博客
配置 docusaurus.config.js
在 docusaurus.config.js 中,添加博客插件配置:
js
export default {
themeConfig: {
navbar: {
items: [
{ to: 'blog', label: '博客', position: 'left' },
],
},
},
};
这将把博客链接添加到导航栏左侧。
创建博客文章
在项目根目录下创建 blog 文件夹,然后在其中添加 Markdown 文件,例如:
text
website/blog/2019-09-05-hello-docusaurus.md
在 Markdown 文件中,使用 Front Matter 来定义文章的元数据:
md
---
title: 欢迎使用 Docusaurus
description: 这是我在 Docusaurus 上的第一篇文章。
slug: welcome-docusaurus-v2
authors:
- name: Joel Marcey
title: Docusaurus 1 的共同创建者
url: https://github.com/JoelMarcey
image_url: https://github.com/JoelMarcey.png
socials:
x: joelmarcey
github: JoelMarcey
tags: [hello, docusaurus-v2]
image: https://i.imgur.com/mErPwqL.png
hide_table_of_contents: false
---
欢迎来到这个博客。这个博客是使用 [**Docusaurus**](https://docusaurus.io/) 创建的。
<!-- truncate -->
这是我在 Docusaurus 上的第一篇文章。
接下来将有更多的探索内容。
在文章中,使用 <!-- truncate --> 标记来指定在博客列表页显示的摘要内容。
博客列表页
博客的索引页默认位于 /blog ,展示所有博客文章。
你可以在 docusaurus.config.js 中配置每页显示的文章数量:
js
export default {
presets: [
[
'@docusaurus/preset-classic',
{
blog: {
blogTitle: 'Docusaurus 博客',
blogDescription: '一个由 Docusaurus 支持的博客',
postsPerPage: 'ALL',
},
},
],
],
};
这将禁用分页,所有文章将在一页中显示。
博客侧边栏
博客侧边栏默认显示最近的博客文章。
你可以在 docusaurus.config.js 中配置侧边栏显示的文章数量:
js
export default {
presets: [
[
'@docusaurus/preset-classic',
{
blog: {
blogSidebarCount: 5,
},
},
],
],
};
这将使侧边栏显示最近的 5 篇文章。
参考: Docusaurus