๐ฆ plugin-content-docs
Provides the Docs functionality and is the default docs plugin for Docusaurus.
Installationโ
- npm
- Yarn
- pnpm
npm install --save @docusaurus/plugin-content-docs
yarn add @docusaurus/plugin-content-docs
pnpm add @docusaurus/plugin-content-docs
ํ
If you use the preset @docusaurus/preset-classic
, you don't need to install this plugin as a dependency.
์ฌ๋ฌ๋ถ์ ํ๋ฆฌ์ ์ต์ ์ ์ฌ์ฉํด ํ๋ฌ๊ทธ์ธ์ ์ค์ ํ ์ ์์ต๋๋ค.
Configurationโ
์ค์ ํ ์ ์๋ ํ๋
์ต์ ๋ช | ํ์ | ๊ธฐ๋ณธ๊ฐ | ์ค๋ช |
---|---|---|---|
path | string | 'docs' | ์ฌ์ดํธ ๋๋ ํ ๋ฆฌ์ ์๋์ ์ธ ํ์ผ ์์คํ ์ ๋ฌธ์ ์ฝํ ์ธ ๋๋ ํ ๋ฆฌ ๊ฒฝ๋ก์ ๋๋ค. |
editUrl | string | EditUrlFunction | undefined | ์ฌ์ดํธ๋ฅผ ํธ์งํ๊ธฐ ์ํ Base URL์
๋๋ค. The final URL is computed by editUrl + relativeDocPath . ์ต์
์ฌ์ฉ ์ ๊ฐ ํ์ผ์ ๋ํ ์ธ๋ฐํ ์ ์ด๋ฅผ ํ ์ ์์ต๋๋ค. ํด๋น ํ๋๋ฅผ ์ค์ ํ์ง ์์ผ๋ฉด ํธ์ง ๋งํฌ๊ฐ ๋นํ์ฑํ๋ฉ๋๋ค. |
editLocalizedFiles | boolean | false | ํธ์ง URL์ ํ์งํ๋์ง ์์ ์๋ณธ ํ์ผ ๋์ ํ์งํ๋ ํ์ผ์ ๋์์ผ๋ก ํฉ๋๋ค. Ignored when editUrl is a function. |
editCurrentVersion | boolean | false | ํธ์ง URL์ ํญ์ ์ด์ ๋ฒ์ ๋์ ํ์ฌ ๋ฒ์ ๋ฌธ์๋ฅผ ๋์์ผ๋ก ํฉ๋๋ค. Ignored when editUrl is a function. |
routeBasePath | string | 'docs' | ์ฌ์ดํธ ๋ฌธ์ ์น์
์ ๋ํ URL ๋ผ์ฐํธ DO NOT include a trailing slash. Use / for shipping docs without base path. |
tagsBasePath | string | 'tags' | ์ฌ์ดํธ ํ๊ทธ ๋ชฉ๋ก ํ์ด์ง์ ๋ํ URL ๋ผ์ฐํธ It is prepended to the routeBasePath . |
include | string[] | ['**/*.{md,mdx}'] | ์ฝํ ์ธ ๊ฒฝ๋ก๋ฅผ ๊ธฐ์ค์ผ๋ก ๋น๋ํ ๋งํฌ๋ค์ด ํ์ผ๊ณผ ์ผ์นํ๋ glob ํจํด ๋ฐฐ์ด์ ๋๋ค. |
exclude | string[] | See example configuration | ์ ์ธํ ๋งํฌ๋ค์ด ํ์ผ๊ณผ ์ผ์นํ๋ glob ํจํด ๋ฐฐ์ด์
๋๋ค. Serves as refinement based on the include option. |
sidebarPath | false | string | undefined | ์ฌ์ด๋๋ฐ ๊ตฌ์ฑ ๊ฒฝ๋ก์
๋๋ค. Use false to disable sidebars, or undefined to create a fully autogenerated sidebar. |
sidebarCollapsible | boolean | true | ๊ธฐ๋ณธ์ ์ผ๋ก ์ฌ์ด๋๋ฐ ์นดํ ๊ณ ๋ฆฌ๋ฅผ ์ ์ ์ ์๋์ง ์ฌ๋ถ๋ฅผ ์ค์ ํฉ๋๋ค. See also Collapsible categories |
sidebarCollapsed | boolean | true | ๊ธฐ๋ณธ์ ์ผ๋ก ์ฌ์ด๋๋ฐ ์นดํ ๊ณ ๋ฆฌ๋ฅผ ์ ์์ง ์ฌ๋ถ๋ฅผ ์ค์ ํฉ๋๋ค. See also Expanded categories by default |
sidebarItemsGenerator | SidebarGenerator | Omitted | Function used to replace the sidebar items of type 'autogenerated' with real sidebar items (docs, categories, links...). See also Customize the sidebar items generator |
numberPrefixParser | boolean | PrefixParser | Omitted | ํ์ผ๋ช
์์ ์ซ์ ์ ๋์ฌ๋ฅผ ์ถ์ถํ๋ ์ฌ์ฉ์ ์ง์ ๊ตฌ๋ฌธ ๋ถ์ ๋ฐฉ์์ ์ค์ ํฉ๋๋ค. Use false to disable this behavior and leave the docs untouched, and true to use the default parser. See also Using number prefixes |
docLayoutComponent | string | '@theme/DocPage' | ๊ฐ ๋ฌธ์ ํ์ด์ง์ ๋ฃจํธ ๋ ์ด์์ ์ปดํฌ๋ํธ์ ๋๋ค. ๋ฒ์ ๋ฐ์ดํฐ ์ปจํ ์คํธ๋ฅผ ์ ๊ณตํ๋ฉฐ ๋ฌธ์ ์ ํ ์ ๋ง์ดํธ ํด์ ๋์ง ์์ต๋๋ค. |
docItemComponent | string | '@theme/DocItem' | ๋ชฉ์ฐจ, ํ์ด์ง ์์ญ ๋ฑ ๊ธฐ๋ณธ ๋ฌธ์ ์ปจํ ์ด๋ |
docTagsListComponent | string | '@theme/DocTagsListPage' | ํ๊ทธ ๋ชฉ๋ก ํ์ด์ง์ ๋ฃจํธ ์ปดํฌ๋ํธ |
docTagDocListComponent | string | '@theme/DocTagDocListPage' | "ํ๊ทธ X๋ฅผ ํฌํจํ ๋ฌธ์" ํ์ด์ง์ ๋ฃจํธ ์ปดํฌ๋ํธ |
docCategoryGeneratedIndexComponent | string | '@theme/DocCategoryGeneratedIndexPage' | ์์ฑ๋ ์นดํ ๊ณ ๋ฆฌ ์ธ๋ฑ์ค ํ์ด์ง์ ๋ฃจํธ ์ปดํฌ๋ํธ |
remarkPlugins | any[] | [] | MDX์ ์ ๋ฌ๋ Remark ํ๋ฌ๊ทธ์ธ |
rehypePlugins | any[] | [] | MDX์ ์ ๋ฌ๋ Rehype ํ๋ฌ๊ทธ์ธ |
beforeDefaultRemarkPlugins | any[] | [] | ๊ธฐ๋ณธ ๋ํ์ฌ์ฐ๋ฃจ์ค Remark ํ๋ฌ๊ทธ์ธ๋ณด๋ค ๋จผ์ MDX์ ์ ๋ฌ๋ ์ฌ์ฉ์ ์ง์ Remark ํ๋ฌ๊ทธ์ธ |
beforeDefaultRehypePlugins | any[] | [] | ๊ธฐ๋ณธ ๋ํ์ฌ์ฐ๋ฃจ์ค Rehype ํ๋ฌ๊ทธ์ธ๋ณด๋ค ๋จผ์ MDX์ ์ ๋ฌ๋ ์ฌ์ฉ์ ์ง์ Rehype ํ๋ฌ๊ทธ์ธ |
showLastUpdateAuthor | boolean | false | ๋ฌธ์๋ฅผ ๋ง์ง๋ง์ผ๋ก ์ ๋ฐ์ดํธํ ์์ฑ์๋ฅผ ํ์ํ ์ง ์ฌ๋ถ |
showLastUpdateTime | boolean | false | ๋ฌธ์๋ฅผ ๋ง์ง๋ง์ผ๋ก ์ ๋ฐ์ดํธํ ๋ ์ง๋ฅผ ํ์ํ ์ง ์ฌ๋ถ |
breadcrumbs | boolean | true | ๋ฌธ์ ํ์ด์ง์์ ์ด๋ ๊ฒฝ๋ก๋ฅผ ํ์ฑํ ๋๋ ๋นํ์ฑํ |
disableVersioning | boolean | false | ์ฌ๋ฌ ๋ฒ์ ์ด ์๋๋ผ๋ ๋ช
์์ ์ผ๋ก ๋ฒ์ ๊ด๋ฆฌ๋ฅผ ๋นํ์ฑํํฉ๋๋ค. ์ด ๋ ๊ฒ ํ๋ฉด ์ฌ์ดํธ์ ํ์ฌ ๋ฒ์ ๋ง ํฌํจ๋ฉ๋๋ค. Will error if includeCurrentVersion: false and disableVersioning: true . |
includeCurrentVersion | boolean | true | ๋ฌธ์์ ํ์ฌ ๋ฒ์ ์ ํฌํจ |
lastVersion | string | First version in versions.json | ๋ฌธ์ ๋ฉ๋ด๋ฐ ์์ดํ ์ ๋ํด ์ฐ์ ์ ์ผ๋ก ํ์๋๊ณ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์๋๋ ๋ฒ์ |
onlyIncludeVersions | string[] | ์ฌ์ฉํ ์ ์๋ ๋ชจ๋ ๋ฒ์ | ์ฌ์ฉํ ์ ์๋ ๋ชจ๋ ๋ฒ์ ์ ํ์ ์งํฉ๋ง ํฌํจ |
versions | VersionsConfig | {} | ๊ฐ ๋ฒ์ ์ ์์ฑ์ ๋ ๋ฆฝ์ ์ผ๋ก ์ฌ์ฉ์ ์ง์ ํฉ๋๋ค. |
Typesโ
EditUrlFunction
โ
type EditUrlFunction = (params: {
version: string;
versionDocsDirPath: string;
docPath: string;
permalink: string;
locale: string;
}) => string | undefined;
PrefixParser
โ
type PrefixParser = (filename: string) => {
filename: string;
numberPrefix?: number;
};
SidebarGenerator
โ
type SidebarGenerator = (generatorArgs: {
/** The sidebar item with type "autogenerated" to be transformed. */
item: {type: 'autogenerated'; dirName: string};
/** Useful metadata for the version this sidebar belongs to. */
version: {contentPath: string; versionName: string};
/** All the docs of that version (unfiltered). */
docs: {
id: string;
title: string;
frontMatter: DocFrontMatter & Record<string, unknown>;
source: string;
sourceDirName: string;
sidebarPosition?: number | undefined;
}[];
/** Number prefix parser configured for this plugin. */
numberPrefixParser: PrefixParser;
/** The default category index matcher which you can override. */
isCategoryIndex: CategoryIndexMatcher;
/**
* key is the path relative to the doc content directory, value is the
* category metadata file's content.
*/
categoriesMetadata: {[filePath: string]: CategoryMetadata};
/**
* Useful to re-use/enhance the default sidebar generation logic from
* Docusaurus.
*/
defaultSidebarItemsGenerator: SidebarGenerator;
// Returns an array of sidebar items โ same as what you can declare in
// sidebars.js, except for shorthands. See https://docusaurus.io/docs/sidebar/items
}) => Promise<SidebarItem[]>;
type CategoryIndexMatcher = (param: {
/** The file name, without extension */
fileName: string;
/**
* The list of directories, from lowest level to highest.
* If there's no dir name, directories is ['.']
*/
directories: string[];
/** The extension, with a leading dot */
extension: string;
}) => boolean;
VersionsConfig
โ
type VersionConfig = {
/**
* The base path of the version, will be appended to `baseUrl` +
* `routeBasePath`.
*/
path?: string;
/** The label of the version to be used in badges, dropdowns, etc. */
label?: string;
/** The banner to show at the top of a doc of that version. */
banner?: 'none' | 'unreleased' | 'unmaintained';
/** Show a badge with the version label at the top of each doc. */
badge?: boolean;
/** Prevents search engines from indexing this version */
noIndex?: boolean;
/** Add a custom class name to the <html> element of each doc */
className?: string;
};
type VersionsConfig = {[versionName: string]: VersionConfig};
Example configurationโ
ํ๋ฆฌ์ ์ต์ ์ด๋ ํ๋ฌ๊ทธ์ธ ์ต์ ์์ ํ๋ฌ๊ทธ์ธ์ ์ค์ ํ ์ ์์ต๋๋ค.
ํ
๋๋ถ๋ถ์ ๋ํ์ฌ์ฐ๋ฃจ์ค ์ฌ์ฉ์๋ ํ๋ฆฌ์ ์ต์ ์ ์ฌ์ฉํด ํ๋ฌ๊ทธ์ธ์ ์ค์ ํฉ๋๋ค.
- ํ๋ฆฌ์ ์ต์
- ํ๋ฌ๊ทธ์ธ ์ต์
ํ๋ฆฌ์ ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ํ๋ฆฌ์ ์ต์ ๋ฅผ ํตํด ํ๋ฌ๊ทธ์ธ์ ๊ตฌ์ฑํฉ๋๋ค.
docusaurus.config.js
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
path: 'docs',
breadcrumbs: true,
// Simple use-case: string editUrl
// editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/',
// Advanced use-case: functional editUrl
editUrl: ({versionDocsDirPath, docPath}) =>
`https://github.com/facebook/docusaurus/edit/main/website/${versionDocsDirPath}/${docPath}`,
editLocalizedFiles: false,
editCurrentVersion: false,
routeBasePath: 'docs',
include: ['**/*.md', '**/*.mdx'],
exclude: [
'**/_*.{js,jsx,ts,tsx,md,mdx}',
'**/_*/**',
'**/*.test.{js,jsx,ts,tsx}',
'**/__tests__/**',
],
sidebarPath: 'sidebars.js',
async sidebarItemsGenerator({
defaultSidebarItemsGenerator,
numberPrefixParser,
item,
version,
docs,
isCategoryIndex,
}) {
// Use the provided data to generate a custom sidebar slice
return [
{type: 'doc', id: 'intro'},
{
type: 'category',
label: 'Tutorials',
items: [
{type: 'doc', id: 'tutorial1'},
{type: 'doc', id: 'tutorial2'},
],
},
];
},
numberPrefixParser(filename) {
// Implement your own logic to extract a potential number prefix
const numberPrefix = findNumberPrefix(filename);
// Prefix found: return it with the cleaned filename
if (numberPrefix) {
return {
numberPrefix,
filename: filename.replace(prefix, ''),
};
}
// No number prefix found
return {numberPrefix: undefined, filename};
},
docLayoutComponent: '@theme/DocPage',
docItemComponent: '@theme/DocItem',
remarkPlugins: [require('remark-math')],
rehypePlugins: [],
beforeDefaultRemarkPlugins: [],
beforeDefaultRehypePlugins: [],
showLastUpdateAuthor: false,
showLastUpdateTime: false,
disableVersioning: false,
includeCurrentVersion: true,
lastVersion: undefined,
versions: {
current: {
label: 'Android SDK v2.0.0 (WIP)',
path: 'android-2.0.0',
banner: 'none',
},
'1.0.0': {
label: 'Android SDK v1.0.0',
path: 'android-1.0.0',
banner: 'unmaintained',
},
},
onlyIncludeVersions: ['current', '1.0.0', '2.0.0'],
},
},
],
],
};
๋ ๋ฆฝ์ ์ผ๋ก ์คํ๋๋ ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ์๋ ํ๋ฌ๊ทธ์ธ์ ๋ํ ์ต์ ์ ์ง์ ์ค์ ํ ์ ์์ต๋๋ค.
docusaurus.config.js
module.exports = {
plugins: [
[
'@docusaurus/plugin-content-docs',
{
path: 'docs',
breadcrumbs: true,
// Simple use-case: string editUrl
// editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/',
// Advanced use-case: functional editUrl
editUrl: ({versionDocsDirPath, docPath}) =>
`https://github.com/facebook/docusaurus/edit/main/website/${versionDocsDirPath}/${docPath}`,
editLocalizedFiles: false,
editCurrentVersion: false,
routeBasePath: 'docs',
include: ['**/*.md', '**/*.mdx'],
exclude: [
'**/_*.{js,jsx,ts,tsx,md,mdx}',
'**/_*/**',
'**/*.test.{js,jsx,ts,tsx}',
'**/__tests__/**',
],
sidebarPath: 'sidebars.js',
async sidebarItemsGenerator({
defaultSidebarItemsGenerator,
numberPrefixParser,
item,
version,
docs,
isCategoryIndex,
}) {
// Use the provided data to generate a custom sidebar slice
return [
{type: 'doc', id: 'intro'},
{
type: 'category',
label: 'Tutorials',
items: [
{type: 'doc', id: 'tutorial1'},
{type: 'doc', id: 'tutorial2'},
],
},
];
},
numberPrefixParser(filename) {
// Implement your own logic to extract a potential number prefix
const numberPrefix = findNumberPrefix(filename);
// Prefix found: return it with the cleaned filename
if (numberPrefix) {
return {
numberPrefix,
filename: filename.replace(prefix, ''),
};
}
// No number prefix found
return {numberPrefix: undefined, filename};
},
docLayoutComponent: '@theme/DocPage',
docItemComponent: '@theme/DocItem',
remarkPlugins: [require('remark-math')],
rehypePlugins: [],
beforeDefaultRemarkPlugins: [],
beforeDefaultRehypePlugins: [],
showLastUpdateAuthor: false,
showLastUpdateTime: false,
disableVersioning: false,
includeCurrentVersion: true,
lastVersion: undefined,
versions: {
current: {
label: 'Android SDK v2.0.0 (WIP)',
path: 'android-2.0.0',
banner: 'none',
},
'1.0.0': {
label: 'Android SDK v1.0.0',
path: 'android-1.0.0',
banner: 'unmaintained',
},
},
onlyIncludeVersions: ['current', '1.0.0', '2.0.0'],
},
],
],
};