|
| 1 | +--- |
| 2 | +title: Docusaurus の scaffold で作成した Project で Docs 機能を廃止し Blog 機能のみ使用するように変更する |
| 3 | +tags: |
| 4 | + - TypeScript |
| 5 | + - React |
| 6 | + - Docusaurus |
| 7 | +private: false |
| 8 | +updated_at: '2025-01-28T23:48:07+09:00' |
| 9 | +id: 4e86d9da210728a3e89b |
| 10 | +organization_url_name: foundingbase |
| 11 | +slide: false |
| 12 | +ignorePublish: false |
| 13 | +--- |
| 14 | + |
| 15 | +## はじめに |
| 16 | + |
| 17 | +Docusaurus の Project を簡単に始める方法として scaffold を使用する方法が推奨されています。 |
| 18 | +Scaffold で作成した Project には Docs, Blog 機能やトップページ等多くの機能が組み込まれています。 |
| 19 | + |
| 20 | +Docusaurus を単にブログ管理のために使用したい場合は `blog` 以外の機能を廃止したほうがスッキリするのでドキュメント管理のためだけに使用する方法を記載しておきます。 |
| 21 | + |
| 22 | +## scaffold 直後の構成 |
| 23 | + |
| 24 | +`npx create-docusaurus@latest my-website classic` 等で作成した直後の Project 構成は以下のようになっています。 |
| 25 | + |
| 26 | +```sh |
| 27 | +> tree -L 2 -I node_modules/ |
| 28 | +. |
| 29 | +├── README.md |
| 30 | +├── blog |
| 31 | +│ ├── 2019-05-28-first-blog-post.md |
| 32 | +│ ├── 2019-05-29-long-blog-post.md |
| 33 | +│ ├── 2021-08-01-mdx-blog-post.mdx |
| 34 | +│ ├── 2021-08-26-welcome |
| 35 | +│ ├── authors.yml |
| 36 | +│ └── tags.yml |
| 37 | +├── docs |
| 38 | +│ ├── intro.md |
| 39 | +│ ├── tutorial-basics |
| 40 | +│ └── tutorial-extras |
| 41 | +├── docusaurus.config.ts |
| 42 | +├── package-lock.json |
| 43 | +├── package.json |
| 44 | +├── sidebars.ts |
| 45 | +├── src |
| 46 | +│ ├── components |
| 47 | +│ ├── css |
| 48 | +│ └── pages |
| 49 | +├── static |
| 50 | +│ └── img |
| 51 | +└── tsconfig.json |
| 52 | +``` |
| 53 | + |
| 54 | +## `docs` ディレクトリの削除 及び 設定の変更 |
| 55 | + |
| 56 | +不要となる `docs` ディレクトリを削除'します。 |
| 57 | + |
| 58 | +```sh |
| 59 | +rm -rf docs |
| 60 | +``` |
| 61 | + |
| 62 | +及び `src/pages/index.tsx` を削除します。 |
| 63 | + |
| 64 | +```sh |
| 65 | +rm src/pages/index.tsx |
| 66 | +``` |
| 67 | + |
| 68 | +`docusaurus.config.ts` 内の `docs` に関する設定を削除するとともに、 `blog` に `routeBasePath: "/",` を追加します。 |
| 69 | + |
| 70 | +```diff_typescript:docusaurus.config.ts |
| 71 | +const config: Config = { |
| 72 | + // 他設定 ... |
| 73 | + presets: [ |
| 74 | + [ |
| 75 | + 'classic', |
| 76 | + { |
| 77 | ++ docs: false, |
| 78 | +- docs: { |
| 79 | +- routeBasePath: "/", |
| 80 | +- sidebarPath: './sidebars.ts', |
| 81 | +- // Please change this to your repo. |
| 82 | +- // Remove this to remove the "edit this page" links. |
| 83 | +- editUrl: |
| 84 | +- 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/', |
| 85 | +- }, |
| 86 | + blog: { |
| 87 | ++ routeBasePath: '/', |
| 88 | + showReadingTime: true, |
| 89 | + feedOptions: { |
| 90 | + type: ['rss', 'atom'], |
| 91 | + xslt: true, |
| 92 | + }, |
| 93 | + // Please change this to your repo. |
| 94 | + // Remove this to remove the "edit this page" links. |
| 95 | + editUrl: |
| 96 | + 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/', |
| 97 | + // Useful options to enforce blogging best practices |
| 98 | + onInlineTags: 'warn', |
| 99 | + onInlineAuthors: 'warn', |
| 100 | + onUntruncatedBlogPosts: 'warn', |
| 101 | + }, |
| 102 | + theme: { |
| 103 | + customCss: './src/css/custom.css', |
| 104 | + }, |
| 105 | + } satisfies Preset.Options, |
| 106 | + ], |
| 107 | +``` |
| 108 | +
|
| 109 | +ここまで対応すれば `/` へアクセスした際に blog 以下のコンテンツが表示されるようになります。 |
| 110 | +
|
| 111 | +## Ref |
| 112 | +
|
| 113 | +https://docusaurus.io/docs/blog#blog-only-mode |
0 commit comments