📦 plugin-content-blog
Docusaurus 的默认博客插件,提供了博客功能。
some features production only
订阅源功能通过提取构建输出实现,仅在生产环境中可用。
安装流程
- npm
- Yarn
- pnpm
npm install --save @docusaurus/plugin-content-blog
yarn add @docusaurus/plugin-content-blog
pnpm add @docusaurus/plugin-content-blog
提示
如果你已经安装了 @docusaurus/preset-classic,就不需要安装这个包了。
你可以通过预设选项配置这个插件。
配置
接受的字段:
| 参数 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| path | string | 'blog' | 博客内容目录的文件系统路径,相对于站点目录。 | 
| editUrl | string | EditUrlFn | undefined | 编辑文档的基础 URL。 最终的 URL 会按照 editUrl + relativePostPath计算。 使用函数可以允许你更精细地控制每一个文件。 完全忽略这个变量就会禁用编辑链接。 | 
| editLocalizedFiles | boolean | false | 编辑 URL 会指向本地化的文件,而不是原始的未翻译文件。 如果 editUrl是一个函数,会完全忽略此选项。 | 
| blogTitle | string | 'Blog' | 用于增进 SEO 的博客页面标题。 | 
| blogDescription | string | 'Blog' | 用于增进 SEO 的博客页面元描述。 | 
| blogSidebarCount | number | 'ALL' | 5 | 在博客侧边栏中展示的博文项目数量。 'ALL'会显示所有博文;0会禁用侧边栏。 | 
| blogSidebarTitle | string | 'Recent posts' | 博客侧边栏的标题。 | 
| routeBasePath | string | 'blog' | 站点博客部分的 URL 前缀。 不要包含末尾斜杠。 /会把博客放在根路径。 | 
| tagsBasePath | string | 'tags' | 博客标签部分的 URL 前缀。 会被添加到 routeBasePath后面。 不要包含末尾斜杠。 | 
| archiveBasePath | string | null | 'archive' | 博客归档部分的 URL 前缀。 会被添加到 routeBasePath后面。 不要包含末尾斜杠。null会禁止生成博客归档。 | 
| include | string[] | ['**/*.{md,mdx}'] | 相对于内容路径的 glob 模式列表,匹配到的 Markdown 文件会被构建。 | 
| exclude | string[] | 见示例配置 | Glob 模式列表,匹配到的 Markdown 文件会被排除。 在 include选项的基础上进一步细调。 | 
| postsPerPage | number | 'ALL' | 10 | 每个博文列表页面显示的博文数量。 'ALL'会让所有博文都展示在一个列表页上。 | 
| blogListComponent | string | '@theme/BlogListPage' | 博客列表页的根组件。 | 
| blogPostComponent | string | '@theme/BlogPostPage' | 每个博文页面的根组件。 | 
| blogTagsListComponent | string | '@theme/BlogTagsListPage' | 标签列表页的根组件。 | 
| blogTagsPostsComponent | string | '@theme/BlogTagsPostsPage' | 「包含某标签的所有博文」页面的根组件。 | 
| blogArchiveComponent | string | '@theme/BlogArchivePage' | 博客归档页的根组件。 | 
| remarkPlugins | any[] | [] | 传递给 MDX 的 Remark 插件。 | 
| rehypePlugins | any[] | [] | 传递给 MDX 的 Rehype 插件。 | 
| beforeDefaultRemarkPlugins | any[] | [] | 在 Docusaurus 默认 Remark 插件之前传递给 MDX 的自定义 Remark 插件。 | 
| beforeDefaultRehypePlugins | any[] | [] | 在 Docusaurus 默认 Rehype 插件之前传递给 MDX 的自定义 Rehype 插件。 | 
| truncateMarker | RegExp | /<!--\s*(truncate)\s*-->/ | 标明摘要结束处的标记。 | 
| showReadingTime | boolean | true | 在博文上显示估计阅读时间。 | 
| readingTime | ReadingTimeFn | 默认阅读时间 | 用于自定义显示的阅读时间数字的回调。 | 
| authorsMapPath | string | 'authors.yml' | 作者记录表的文件路径, 相对于博客内容目录。 | 
| feedOptions | 见下文 | {type: ['rss', 'atom']} | 博客订阅源。 | 
| feedOptions.type | FeedType | FeedType[] | 'all' | null | 必填 | 要生成的订阅源类型。 null会禁用订阅源生成。 | 
| feedOptions.createFeedItems | CreateFeedItemsFn | undefined | undefined | An optional function which can be used to transform and / or filter the items in the feed. | 
| feedOptions.title | string | siteConfig.title | 订阅源的标题。 | 
| feedOptions.description | string | `${siteConfig.title} Blog` | 订阅源的描述。 | 
| feedOptions.copyright | string | undefined | 版权信息。 | 
| feedOptions.language | string(所有可选值请见文档) | undefined | 订阅源的语言元数据。 | 
| sortPosts | 'descending' | 'ascending'  | 'descending' | 决定博文排序的方向。 | 
类型
EditUrlFn
type EditUrlFunction = (params: {
  blogDirPath: string;
  blogPath: string;
  permalink: string;
  locale: string;
}) => string | undefined;