Blog
Initial setup
To setup your site's blog, start by creating a blog
directory.
Then, add a item link to your blog within docusaurus.config.js
:
Adding posts
To publish in the blog, create a file within the blog directory with a formatted name of YYYY-MM-DD-my-blog-post-title.md
. The post date is extracted from the file name.
For example, at my-website/blog/2019-09-05-hello-docusaurus-v2.md
:
Header options
The only required field is title
; however, we provide options to add author information to your blog post as well along with other options.
author
- The author name to be displayed.author_url
- The URL that the author's name will be linked to. This could be a GitHub, Twitter, Facebook profile URL, etc.author_image_url
- The URL to the author's thumbnail image.author_title
- A description of the author.title
- The blog post title.tags
- A list of strings to tag to your post.draft
- A boolean flag to indicate that the blog post is work in process and therefore should not be published yet. However, draft blog posts will be displayed during development.description
: The description of your post, which will become the<meta name="description" content="..."/>
and<meta property="og:description" content="..."/>
in<head>
, used by search engines. If this field is not present, it will default to the first line of the contents.image
: Cover or thumbnail image that will be used when displaying the link to your post.
Summary truncation
Use the <!--truncate-->
marker in your blog post to represent what will be shown as the summary when viewing all published blog posts. Anything above <!--truncate-->
will be part of the summary. For example:
Feed
You can generate RSS/ Atom feed by passing feedOptions.
Example usage:
Accessing the feed:
The feed for RSS can be found at:
and for Atom:
Advanced topics
Blog-only mode
You can run your Docusaurus 2 site without a landing page and instead have your blog's post list page as the index page. Set the routeBasePath
to be '/'
to indicate it's the root path.
caution
Don't forget to delete the existing homepage at ./src/pages/index.js
or else there will be two files mapping to the same route!
Multiple blogs
By default, the classic theme assumes only one blog per website and hence includes only one instance of the blog plugin. If you would like to have multiple blogs on a single website, it's possible too! You can add another blog by specifying another blog plugin in the plugins
option for docusaurus.config.js
.
Set the routeBasePath
to the URL route that you want your second blog to be accessed on. Note that the routeBasePath
here has to be different from the first blog or else there could be a collision of paths! Also, set path
to the path to the directory containing your second blog's entries.