블로그
블로그 기능을 사용하면 모든 기능을 갖춘 블로그를 즉시 배포할 수 있습니다.
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
블로그를 게시하기 위해서는 블로그 디렉터리에 마크다운 파일을 만드세요.
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. 예를 들면 아래와 같은 형식입니다.
---
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
패턴 | 예 |
---|---|
단일 파일 | 2021-05-28-my-blog-post-title.md |
MDX 파일 | 2021-05-28-my-blog-post-title.mdx |
Single folder + index.md | 2021-05-28-my-blog-post-title/index.md |
날짜 폴더명 | 2021-05-28/my-blog-post-title.md |
중첩된 날짜 기준 폴더 | 2021/05/28/my-blog-post-title.md |
부분적으로 중첩된 날짜 기준 폴더 | 2021/05-28-my-blog-post-title.md |
Nested folders + index.md | 2021/05/28/my-blog-post-title/index.md |
경로 중간에 부분적으로 중첩된 날짜 기준 폴더 | 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:
---
date: 2021-09-13T10:00
---
---
date: 2021-09-13T18:00
---