-
Notifications
You must be signed in to change notification settings - Fork 77
Description
Currently, our blog fetches content from an external API (/blog-posts) and renders it on the client using a custom useMarkdown hook with marked. This approach limits our ability to use React components within blog posts and adds unnecessary complexity for content updates.
Goal:
Move all blog content into the frontend repository as .mdx files and use a modern MDX rendering solution (like next-mdx-remote or MDX Components).
Steps to Implement:
-
MDX Setup:
- Install necessary dependencies:
next-mdx-remote,@next/mdx,gray-matter. - Configure
next.config.jsto support MDX if needed.
- Install necessary dependencies:
-
Content Migration:
- Create a directory
content/blog/to store.mdxfiles. - Migrate existing blog posts from the database/API to MDX files with YAML frontmatter (for title, date, author, coverImage, etc.).
- Create a directory
-
Data Fetching:
- Implement utility functions in
lib/mdx.tsto:- Get all blog posts (reading from
content/blog/). - Get a single blog post by slug.
- Parse frontmatter and MDX content.
- Get all blog posts (reading from
- Replace getBlogPosts and getBlogPost in
app/(landing)/blog/with these new utilities.
- Implement utility functions in
-
UI Components Update:
- Update
app/(landing)/blog/page.tsxto be a Server Component (if possible) or usegenerateStaticParamsfor static rendering. - Update
app/(landing)/blog/[slug]/page.tsxto usenext-mdx-remotefor rendering the content. - Integrate existing custom components (like
Mermaid.tsx,Badge, etc.) as MDX components. - Ensure the
useMarkdownhook and its associated manual CSS injections are replaced with Tailwind Typography (prose) and proper MDX components.
- Update
-
Deprecation:
- Remove
lib/api/blog.tsand associated types if no longer used. - Cleanup
app/api/blog/routes if they exist.
- Remove
Tasks:
- Define MDX content structure and frontmatter schema.
- Implement
getMdxContentutility. - Refactor blog listing page to use static file data.
- Refactor blog detail page to use
next-mdx-remote. - Verify SEO and metadata generation using MDX frontmatter.
- Migrate all current posts to
.mdxfiles.
Submit video proof
-
Run
npm run buildto ensure static generation of blog pages works without errors. -
Add a test MDX file and verify it appears in the blog list.
-
Navigate to
/blogand check if all posts are listed correctly. -
Open a blog post and verify styling, images, and any embedded components.
-
Check view-source to ensure content is pre-rendered for SEO.