feat: enhance post retrieval with authorization token

- Updated `getPostById` function to accept an optional authorization token.
- Modified `PostPage` to retrieve the token from cookies and pass it to the API call.
- Added smooth transition effects for background and text colors in `globals.css`.
- Cleaned up imports and formatting in `blog-home.tsx`.
- Refactored `blog-post.tsx` to use `MDXRemote` for rendering markdown content.
- Introduced `blog-comment.tsx` and `blog-post-header.client.tsx` components for better structure.
- Added a switch component for dark/light mode toggle in the navbar.
- Updated `Post` model to include a description field.
This commit is contained in:
2025-07-28 08:30:37 +08:00
parent d73ed493be
commit 89e2fbe0b9
17 changed files with 1040 additions and 108 deletions

View File

@ -10,9 +10,13 @@ interface ListPostsParams {
keywords?: string
}
export async function getPostById(id: string): Promise<Post | null> {
export async function getPostById(id: string, token: string=""): Promise<Post | null> {
try {
const res = await axiosClient.get<BaseResponse<Post>>(`/post/p/${id}`)
const res = await axiosClient.get<BaseResponse<Post>>(`/post/p/${id}`, {
headers: {
Authorization: `Bearer ${token}`
}
})
return res.data.data
}
catch (error) {