Using the MkDocs Blog Plugin
Walkthtough
This guide will walk you through setting up the MkDocs Blog Plugin and publishing your first blog post.
Step 1: Install the MkDocs Blog Plugin¶
-
Install the plugin using
pip
:pip install mkdocs-blog-plugin
-
Add the plugin to your
mkdocs.yml
configuration file:- blog
Step 2: Configure the Blog Plugin¶
Update your mkdocs.yml
to configure the blog plugin. Here’s an example configuration:
- blog:
# Optional: Specify the directory for blog posts (default is "blog")
blog_dir: blog
# Optional: Enable pagination
pagination: true
# Optional: Number of posts per page
posts_per_page: 5
# Optional: Enable tags
tags: true
# Optional: Enable categories
categories: true
Step 3: Create a Blog Post¶
-
Create a directory for your blog posts (e.g.,
docs/blog
). -
Add your first blog post as a Markdown file in the blog directory. For example, create
docs/blog/my-first-post.md
--- title: My First Blog Post date: 2023-10-01 author: Your Name tags: - MkDocs - Blog categories: - Tutorials --- # My First Blog Post Welcome to my first blog post using the MkDocs Blog Plugin! ## Introduction This is an example of how to create and publish a blog post with MkDocs. ## Features - Easy to set up - Markdown-based - Supports tags and categories ## Conclusion I hope you found this guide helpful. Stay tuned for more posts!
- The
title
,date
,author
,tags
, andcategories
fields are metadata for the blog post. - The content below the --- is the body of the blog post.
- The
Step 4: Update Navigation¶
Add a link to your blog in the navigation section of mkdocs.yml
:
nav:
- Home: index.md
- Blog: blog/
Step 5: Serve and Verify¶
-
Serve your MkDocs site:
mkdocs serve
-
Open your browser and navigate to
http://127.0.0.1:8000/blog/
. -
Verify that your blog post appears on the blog page.
Step 6:Customize the Blog Layout (Optional)¶
You can customize the blog layout by adding custom CSS or overriding the plugin's templates.
-
Create a
custom.css
file (e.g.,docs/styles/custom.css
) and add your styles. -
Link the CSS file in mkdocs.yml:
extra_css: - styles/custom.css
Step 7:Deploy Your Blog¶
Once you're satisfied with your blog, deploy it to a hosting platform like GitHub Pages, Netlify, or Read the Docs.
Deploy to GitHub Pages¶
-
Install
mkdocs
andmkdocs-material
(if not already installed):pip install mkdocs mkdocs-material
-
Build the site:
mkdocs build
-
Deploy to GitHub Pages:
mkdocs gh-deploy