+ + {blog.title} + +
+{blog.description}
+ +diff --git a/apps/frontend/app/(with-header-footer)/blog/page.tsx b/apps/frontend/app/(with-header-footer)/blog/page.tsx index 979f739..72de2ec 100644 --- a/apps/frontend/app/(with-header-footer)/blog/page.tsx +++ b/apps/frontend/app/(with-header-footer)/blog/page.tsx @@ -7,22 +7,33 @@ import { import { AlertCircle } from "lucide-react"; import { base62 } from "@/lib/utils"; import { BlogAPI } from "@/lib/api/server"; +import { handleAPIError } from "@/lib/api/common"; + +const formatNumber = (num: number): string => { + if (num >= 1_000_000) { + return (num / 1_000_000).toFixed(1) + 'M'; + } + if (num >= 1_000) { + return (num / 1_000).toFixed(1) + 'K'; + } + return num.toString(); +}; + +const getBlogDetailUrl = (id: string): string => { + const cleanId = id.replace(/-/g, ''); + const encoded = base62.encode(Buffer.from(cleanId, 'hex')); + return `/blog/${encoded}`; +}; export default async function Blog() { - const formatNumber = useCallback((num: number) => { - if (num >= 1000) { - return (num / 1000).toFixed(1) + 'K'; - } else if (num >= 1000000) { - return (num / 1000000).toFixed(1) + 'M'; - } - return num.toString(); - }, []); - let errorMsg = ''; - const blogs = await BlogAPI.list().catch(e => { errorMsg = `${e}`; return null }); + const blogs = await BlogAPI.list().catch(e => { + handleAPIError(e, ({ message }) => { errorMsg = message }); + return null; + }); return ( -
{blog.description}
-{new Date(blog.createdAt).toLocaleString()} · {formatNumber(blog.viewCount)} 次访问
-{blog.description}
+ +