3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Docusaurus の scaffold で作成した Project で Docs 機能を廃止し Blog 機能のみ使用するように変更する

Last updated at Posted at 2025-01-28

はじめに

Docusaurus の Project を簡単に始める方法として scaffold を使用する方法が推奨されています。
Scaffold で作成した Project には Docs, Blog 機能やトップページ等多くの機能が組み込まれています。

Docusaurus を単にブログ管理のために使用したい場合は blog 以外の機能を廃止したほうがスッキリするのでドキュメント管理のためだけに使用する方法を記載しておきます。

scaffold 直後の構成

npx create-docusaurus@latest my-website classic 等で作成した直後の Project 構成は以下のようになっています。

> tree -L 2 -I node_modules/
.
├── README.md
├── blog
│   ├── 2019-05-28-first-blog-post.md
│   ├── 2019-05-29-long-blog-post.md
│   ├── 2021-08-01-mdx-blog-post.mdx
│   ├── 2021-08-26-welcome
│   ├── authors.yml
│   └── tags.yml
├── docs
│   ├── intro.md
│   ├── tutorial-basics
│   └── tutorial-extras
├── docusaurus.config.ts
├── package-lock.json
├── package.json
├── sidebars.ts
├── src
│   ├── components
│   ├── css
│   └── pages
├── static
│   └── img
└── tsconfig.json

docs ディレクトリの削除 及び 設定の変更

不要となる docs ディレクトリを削除'します。

rm -rf docs

及び src/pages/index.tsx を削除します。

rm src/pages/index.tsx

docusaurus.config.ts 内の docs に関する設定を削除するとともに、 blogrouteBasePath: "/", を追加します。

docusaurus.config.ts
const config: Config = {
  // 他設定 ...
  presets: [
    [
      'classic',
      {
+       docs: false,
-       docs: {
-         routeBasePath: "/",
-         sidebarPath: './sidebars.ts',
-         // Please change this to your repo.
-         // Remove this to remove the "edit this page" links.
-         editUrl:
-           'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
-       },
        blog: {
+         routeBasePath: '/',
          showReadingTime: true,
          feedOptions: {
            type: ['rss', 'atom'],
            xslt: true,
          },
          // Please change this to your repo.
          // Remove this to remove the "edit this page" links.
          editUrl:
            'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
          // Useful options to enforce blogging best practices
          onInlineTags: 'warn',
          onInlineAuthors: 'warn',
          onUntruncatedBlogPosts: 'warn',
        },
        theme: {
          customCss: './src/css/custom.css',
        },
      } satisfies Preset.Options,
    ],

ここまで対応すれば / へアクセスした際に blog 以下のコンテンツが表示されるようになります。

Ref

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?