跳转至主内容
Version: 2.0.0-beta.3

📦 plugin-content-blog

Docusaurus 默认的博客插件,其提供博客功能。

安装#

npm install --save @docusaurus/plugin-content-blog
tip

若您已安装 @docusaurus/preset-classic,则无需安装此依赖。 您也可以通过经典预设选项来配置,从而无需进行下列操作。

配置#

docusaurus.config.js
module.exports = {  plugins: [    [      '@docusaurus/plugin-content-blog',      {        /**         * 文件系统中,数据对站点的相对路径。         */        path: 'blog',        /**         * 编辑您站点的 URL。         * Docusaurus will compute the final editUrl with "editUrl + relativeDocPath"         */        editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/',        /**         * For advanced cases, compute the edit url for each Markdown file yourself.         */        editUrl: ({locale, blogDirPath, blogPath}) => {          return `https://github.com/facebook/docusaurus/edit/master/website/${blogDirPath}/${blogPath}`;        },        /**         * 在提交本地文件至 Git 时有用。         * When Markdown files are localized, the edit url will target the localized file,         * instead of the original unlocalized file.         * 注:此选项将在 editUrl 为函数时被自动忽略         */        editLocalizedFiles: false,        /**         * 用以优化 SEO 的博客页面标题         */        blogTitle: 'Blog title',        /**         * 用以优化 SEO 的博客页面源描述         */        blogDescription: 'Blog',        /**         * 显示于博客侧边栏的博文数量,设置为         * 'ALL' 以显示所有博文,0 则禁用此功能         */        blogSidebarCount: 5,        /**         * 博客侧边栏标题         */        blogSidebarTitle: 'All our posts',        /**         * 通往您博客的 URL 路由。         * *请务必不要*添加斜杠。         */        routeBasePath: 'blog',        include: ['*.md', '*.mdx'],        postsPerPage: 10,        /**         * 博客页面所使用的主题组件。         */        blogListComponent: '@theme/BlogListPage',        blogPostComponent: '@theme/BlogPostPage',        blogTagsListComponent: '@theme/BlogTagsListPage',        blogTagsPostsComponent: '@theme/BlogTagsPostsPage',        /**         * 传递至 MDX 的 Remark 及 Rehype 插件。         */        remarkPlugins: [          /* require('remark-math') */        ],        rehypePlugins: [],        /**         * 于 Docusaurus 自带的默认 Remark 及 Rehype 插件前         * 传递至 MDX 的自定义 Remark 及 Rehype 插件。         */        beforeDefaultRemarkPlugins: [],        beforeDefaultRehypePlugins: [],        /**         * 截断标记,可为正则表达式或字符串。         */        truncateMarker: /<!--\s*(truncate)\s*-->/,        /**         * 显示博文的估计阅读时间。         */        showReadingTime: true,        /**         * 博客订阅;若 feedOptions 为 undefined,则不会生成订阅源。                   */        feedOptions: {          type: '', // 必填,可为 'rss' | 'feed' | 'all'           title: '', // 默认为 siteConfig.title          description: '', // 默认为 `${siteConfig.title} Blog`          copyright: '',          language: undefined, // 参见:http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes        },      },    ],  ],};

i18n#

请先阅读 i18n 简介

翻译文件位置#

  • 基础路径website/i18n/<语言>/docusaurus-plugin-content-blog
  • 多实例路径website/i18n/<语言>/docusaurus-plugin-content-blog-<pluginId>
  • JSON 文件:N/A
  • Markdown 文件website/i18n/<语言>/docusaurus-plugin-content-blog

文件系统结构示例#

website/i18n/<语言>/docusaurus-plugin-content-blog# 网站/博客译文├── first-blog-post.md└── second-blog-post.md