Blog
O recurso de blog permite que você importe rapidamente um blog com todas as funcionalidades.
Check the Blog Plugin API Reference documentation for an exhaustive list of options.
Initial setup
To set up your site's blog, start by creating a blog
directory.
Then, add an item link to your blog within docusaurus.config.js
:
export default {
themeConfig: {
// ...
navbar: {
items: [
// ...
{to: 'blog', label: 'Blog', position: 'left'}, // or position: 'right'
],
},
},
};
Adding posts
Para publicar no blog, crie um arquivo Markdown dentro do diretório do blog.
For example, create a file at website/blog/2019-09-05-hello-docusaurus.md
:
---
title: Welcome Docusaurus
description: This is my first post on Docusaurus.
slug: welcome-docusaurus-v2
authors:
- name: Joel Marcey
title: Co-creator of Docusaurus 1
url: https://github.com/JoelMarcey
image_url: https://github.com/JoelMarcey.png
- name: Sébastien Lorber
title: Docusaurus maintainer
url: https://sebastienlorber.com
image_url: https://github.com/slorber.png
tags: [hello, docusaurus-v2]
image: https://i.imgur.com/mErPwqL.png
hide_table_of_contents: false
---
Welcome to this blog. This blog is created with [**Docusaurus 2**](https://docusaurus.io/).
<!-- truncate -->
This is my first post on Docusaurus 2.
A whole bunch of exploration to follow.
The front matter is useful to add more metadata to your blog post, for example, author information, but Docusaurus will be able to infer all necessary metadata without the front matter. For all possible fields, see the API documentation.
Blog list
The blog's index page (by default, it is at /blog
) is the blog list page, where all blog posts are collectively displayed.
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. Note that the portion above the truncate marker must be standalone renderable Markdown. Por exemplo:
---
title: Markdown blog truncation example
---
All these will be part of the blog post summary.
<!-- truncate -->
But anything from here on down will not be.
For files using the .mdx
extension, use a MDX comment {/* truncate */}
instead:
---
title: MDX blog truncation Example
---
All these will be part of the blog post summary.
{/* truncate */}
But anything from here on down will not be.
By default, 10 posts are shown on each blog list page, but you can control pagination with the postsPerPage
option in the plugin configuration. If you set postsPerPage: 'ALL'
, pagination will be disabled and all posts will be displayed on the first page. You can also add a meta description to the blog list page for better SEO:
export default {
// ...
presets: [
[
'@docusaurus/preset-classic',
{
blog: {
blogTitle: 'Docusaurus blog!',
blogDescription: 'A Docusaurus powered blog!',
postsPerPage: 'ALL',
},
},
],
],
};
Blog sidebar
The blog sidebar displays recent blog posts. The default number of items shown is 5, but you can customize with the blogSidebarCount
option in the plugin configuration. By setting blogSidebarCount: 0
, the sidebar will be completely disabled, with the container removed as well. This will increase the width of the main container. Specially, if you have set blogSidebarCount: 'ALL'
, all posts will be displayed.
You can also alter the sidebar heading text with the blogSidebarTitle
option. For example, if you have set blogSidebarCount: 'ALL'
, instead of the default "Recent posts", you may rather make it say "All posts":
export default {
presets: [
[
'@docusaurus/preset-classic',
{
blog: {
blogSidebarTitle: 'All posts',
blogSidebarCount: 'ALL',
},
},
],
],
};
Blog post date
Docusaurus will extract a YYYY-MM-DD
date from many patterns such as YYYY-MM-DD-my-blog-post-title.md
or YYYY/MM/DD/my-blog-post-title.md
. This enables you to easily group blog posts by year, by month, or to use a flat structure.
Supported date extraction patterns
Pattern | Exemplo |
---|---|
Single file | 2021-05-28-my-blog-post-title.md |
MDX file | 2021-05-28-my-blog-post-title.mdx |
Single folder + index.md | 2021-05-28-my-blog-post-title/index.md |
Folder named by date | 2021-05-28/my-blog-post-title.md |
Nested folders by date | 2021/05/28/my-blog-post-title.md |
Partially nested folders by date | 2021/05-28-my-blog-post-title.md |
Nested folders + index.md | 2021/05/28/my-blog-post-title/index.md |
Date in the middle of path | category/2021/05-28-my-blog-post-title.md |
Docusaurus can extract the date from the posts using any of the naming patterns above. It is advisable to choose one pattern and apply it to all posts to avoid confusion.
Using a folder can be convenient to co-locate blog post images alongside the Markdown file.
This naming convention is optional, and you can also provide the date as front matter. Since the front matter follows YAML syntax where the datetime notation is supported, you can use front matter if you need more fine-grained publish dates. For example, if you have multiple posts published on the same day, you can order them according to the time of the day:
---
data: 2021-09-13T10:00
---
---
data: 2021-09-13T10:00
---
Blog post authors
Use the authors
front matter field to declare blog post authors. An author should have at least a name
or an image_url
. Docusaurus uses information like url
, email
, and title
, but any other information is allowed.
Inline authors
Blog post authors can be declared directly inside the front matter:
- Single author
- Multiple authors
---
authors:
name: Joel Marcey
title: Co-creator of Docusaurus 1
url: https://github.com/JoelMarcey
image_url: https://github.com/JoelMarcey.png
email: [email protected]
---
---
authors:
- name: Joel Marcey
title: Co-creator of Docusaurus 1
url: https://github.com/JoelMarcey
image_url: https://github.com/JoelMarcey.png
email: [email protected]
- name: Sébastien Lorber
title: Docusaurus maintainer
url: https://sebastienlorber.com
image_url: https://github.com/slorber.png
---
This option works best to get started, or for casual, irregular authors.
Prefer using the authors
front matter, but the legacy author_*
front matter remains supported:
---
author: Joel Marcey
author_title: Co-creator of Docusaurus 1
author_url: https://github.com/JoelMarcey
author_image_url: https://github.com/JoelMarcey.png
---
Global authors
For regular blog post authors, it can be tedious to maintain authors' information inlined in each blog post.
It is possible to declare those authors globally in a configuration file:
jmarcey:
name: Joel Marcey
title: Co-creator of Docusaurus 1
url: https://github.com/JoelMarcey
image_url: https://github.com/JoelMarcey.png
email: [email protected]
slorber:
name: Sébastien Lorber
title: Docusaurus maintainer
url: https://sebastienlorber.com
image_url: https://github.com/slorber.png
Use the authorsMapPath
plugin option to configure the path. JSON is also supported.
In blog posts front matter, you can reference the authors declared in the global configuration file:
- Single author
- Multiple authors
---
authors: jmarcey
---
---
authors: [jmarcey, slorber]
---
The authors
system is very flexible and can suit more advanced use-case:
Mix inline authors and global authors
You can use global authors most of the time, and still use inline authors:
---
authors:
- jmarcey
- slorber
- name: Inline Author name
title: Inline Author Title
url: https://github.com/inlineAuthor
image_url: https://github.com/inlineAuthor
---
Local override of global authors
You can customize the global author's data on per-blog-post basis:
---
authors:
- key: jmarcey
title: Joel Marcey's new title
- key: slorber
name: Sébastien Lorber's new name
---
Localize the author's configuration file
The configuration file can be localized, just create a localized copy of it at:
website/i18n/[locale]/docusaurus-plugin-content-blog/authors.yml