What features would you want on your blog? Here are the ones I chose:
Features
- Static site that can be published to GitHub Pages
- MDX support: I work on frontend code, so I need to embed React components in my posts
- Search
- Table of contents (Clerk style)
- A Blog Post
- List of Posts with Pagination
- Categories
- Series
- Tags (WIP)
- Metadata with Social Images
- Static (yes, repeating for emphasis)
Setup
The official FumaDocs documentation has an article on setting up a blog: Setup a Blog. Using that as a foundation, I built my blog with the features above.
You can proceed in two ways:
- Clone the current repo
- Follow the steps below to add these features to your existing Next.js site
Install and Configure Fuma Docs
Install Fuma Docs
You need a working Fuma Docs setup. If you don't have one, create it using the following command:
Or you can configure FumaDocs manually.
At this point, you should have a basic setup ready with the files: source.config.ts
and lib/source.ts
.
Setup ShadCN Components
If you already have shadcn set up, you don't need to run the following command.
We need the following components:
- button
- popover
- badge
- card
You can add all of the above with:
We also need a book icon component, which is used when displaying series:
Define a Collection for Blog
Install zod
as we will use it to add a frontmatter schema.
Now define a collection for the blog. Add the following:
Add the following to lib/source.ts
:
Add fumadocs-blog components
There are multiple features, so instead of adding files one by one, we'll copy entire folders using the giget command.
Add all the required components
Add /blog route page
Add /blog-og route page
Correct the imports
The original components are built to work with a monorepo, so we need to correct the imports.
Run the following commands:
Add styles to global.css
Configure the blog
If fumadocs-blog was an npm package, all the above steps would be handled by that. Now, we need to configure the blog. Blog configuration drives following:
- Metadata
- Components
- Categories
- Series
- Others
I will document a detailed guide, but as of now the following should give majority of the idea
Add the following file in your repo at root path, we import this using @/blog-configuration
.
Add following sample post
Add the sample .mdx
file below to test if everything is working. Place it at content/blog/idea/zero-trust-security.mdx
.
A few things to note: "idea" is the category of the blog, and "zero-trust-security" will be the URL of the blog post.
Test the blog
If you open http://localhost:3000/blog
, you'll see a list of posts—at this point, only one. You can add more, edit the content, and try it out. The pagination size is 5, so after 5 posts you'll see a paginator.
You can open a blog detail page and see details like tags, series, categories, etc.
If you want a post to be part of a series, add the following frontmatter to the .mdx
file:
Future
This development is driven by my needs and the products I'm working on. Here are a few things in the pipeline:
- Newsletter subscription (But how do you do it for a static site?)
- Tags
- Make other components overridable so you can style them better
- Make this a clonable template
- The biggest problem I have with templates is that once you clone and start changing them, updating is not easy. You're off-track from the first second. So, I'm leaning towards a monorepo where I can balance open code and updates like a package.
Anything else? Hit me up on Twitter and follow for more updates.
Last updated on