본문으로 건너뛰기
버전: 3.10.2

📦 plugin-content-docs

Provides the Docs functionality and is the default docs plugin for Docusaurus.

설치​

npm install --save @docusaurus/plugin-content-docs
팁

If you use the preset @docusaurus/preset-classic, you don't need to install this plugin as a dependency.

You can configure this plugin through the preset options.

설정​

설정할 수 있는 필드

옵션명타입기본값설명
pathstring'docs'사이트 디렉토리에 상대적인 파일 시스템의 문서 콘텐츠 디렉토리 경로입니다.
editUrlstring | EditUrlFunctionundefined사이트를 편집하기 위한 Base URL입니다. The final URL is computed by editUrl + relativeDocPath. 옵션 사용 시 각 파일에 대한 세밀한 제어를 할 수 있습니다. 해당 필드를 설정하지 않으면 편집 링크가 비활성화됩니다.
editLocalizedFilesbooleanfalse편집 URL은 현지화되지 않은 원본 파일 대신 현지화된 파일을 대상으로 합니다. Ignored when editUrl is a function.
editCurrentVersionbooleanfalse편집 URL은 항상 이전 버전 대신 현재 버전 문서를 대상으로 합니다. Ignored when editUrl is a function.
routeBasePathstring'docs'사이트 문서 섹션에 대한 URL 라우트 DO NOT include a trailing slash. Use / for shipping docs without base path.
tagsBasePathstring'tags'사이트 태그 목록 페이지에 대한 URL 라우트 It is prepended to the routeBasePath.
includestring[]['**/*.{md,mdx}']콘텐츠 경로를 기준으로 빌드할 마크다운 파일과 일치하는 glob 패턴 배열입니다.
excludestring[]See example configuration제외할 마크다운 파일과 일치하는 glob 패턴 배열입니다. Serves as refinement based on the include option.
sidebarPathfalse | stringundefinedPath to a sidebars configuration file, loaded in a Node.js context. Use false to disable sidebars, or undefined to create a fully autogenerated sidebar.
sidebarCollapsiblebooleantrue기본적으로 사이드바 카테고리를 접을 수 있는지 여부를 설정합니다. See also Collapsible categories
sidebarCollapsedbooleantrue기본적으로 사이드바 카테고리를 접을지 여부를 설정합니다. See also Expanded categories by default
sidebarItemsGeneratorSidebarGeneratorOmittedFunction used to replace the sidebar items of type 'autogenerated' with real sidebar items (docs, categories, links...). See also Customize the sidebar items generator
numberPrefixParserboolean | PrefixParserOmitted파일명에서 숫자 접두사를 추출하는 사용자 지정 구문 분석 방식을 설정합니다. Use false to disable this behavior and leave the docs untouched, and true to use the default parser. See also Using number prefixes
docsRootComponentstring'@theme/DocsRoot'모든 문서 플러그인 페이지(모든 버전 포함)의 상위 컴포넌트입니다. 문서 페이지와 버전 사이를 탐색할 때 마운트된 상태로 유지됩니다.
docVersionRootComponentstring'@theme/DocVersionLayout'개별 버전의 모든 문서 페이지(사이드바가 있는 문서 페이지, 태그 페이지)의 상위 컴포넌트입니다. 특정 버전의 페이지 사이를 탐색할 때 마운트된 상태로 유지됩니다.
docRootComponentstring'@theme/DocRoot'사이드바가 있는 모든 문서 페이지(일반 문서 페이지, 카테고리 생성 색인 페이지)의 상위 컴포넌트입니다. 각 페이지 사이를 탐색할 때 마운트된 상태로 유지됩니다.
docItemComponentstring'@theme/DocItem'목차, 페이지 영역 등 기본 문서 컨테이너
docTagsListComponentstring'@theme/DocTagsListPage'태그 목록 페이지의 루트 컴포넌트
docTagDocListComponentstring'@theme/DocTagDocListPage'"태그 X를 포함한 문서" 페이지의 루트 컴포넌트
docCategoryGeneratedIndexComponentstring'@theme/DocCategoryGeneratedIndexPage'생성된 카테고리 인덱스 페이지의 루트 컴포넌트
remarkPluginsany[][]MDX에 전달된 Remark 플러그인
rehypePluginsany[][]MDX에 전달된 Rehype 플러그인
recmaPluginsany[][]Recma plugins passed to MDX.
beforeDefaultRemarkPluginsany[][]기본 도큐사우루스 Remark 플러그인보다 먼저 MDX에 전달된 사용자 지정 Remark 플러그인
beforeDefaultRehypePluginsany[][]기본 도큐사우루스 Rehype 플러그인보다 먼저 MDX에 전달된 사용자 지정 Rehype 플러그인
showLastUpdateAuthorbooleanfalse문서를 마지막으로 업데이트한 작성자를 표시할지 여부
showLastUpdateTimebooleanfalseOnly for Markdown pages. Whether to display the last date the doc was updated. This requires access to git history during the build, so will not work correctly with shallow clones (a common default for CI systems). With GitHub actions/checkout, use fetch-depth: 0. When deploying to Vercel, set the environment variable VERCEL_DEEP_CLONE=true.
disableVersioningbooleanfalse여러 버전이 있더라도 명시적으로 버전 관리를 비활성화합니다. 이렇게 하면 사이트에 현재 버전만 포함됩니다. Will error if includeCurrentVersion: false and disableVersioning: true.
includeCurrentVersionbooleantrue문서의 현재 버전을 포함
lastVersionstringFirst version in versions.json문서 메뉴바 아이템에 대해 우선적으로 탐색되고 기본적으로 표시되는 버전
onlyIncludeVersionsstring[]사용할 수 있는 모든 버전사용할 수 있는 모든 버전의 하위 집합만 포함
versionsVersionsConfig{}각 버전의 속성을 독립적으로 사용자 지정합니다.
tagsstring | false | null | undefinedtags.ymlPath to a YAML file listing pre-defined tags. Relative to the docs version content directories.
onInlineTags'ignore' | 'log' | 'warn' | 'throw'warnThe plugin behavior when docs contain inline tags (not appearing in the list of pre-defined tags, usually docs/tags.yml).

타입​

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};

설정 예시​

프리셋 옵션이나 플러그인 옵션에서 플러그인을 설정할 수 있습니다.

팁

대부분의 도큐사우루스 사용자는 프리셋 옵션을 사용해 플러그인을 설정합니다.

프리셋을 사용하는 경우 프리셋 옵션를 통해 플러그인을 구성합니다.

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};
},
docsRootComponent: '@theme/DocsRoot',
docVersionRootComponent: '@theme/DocVersionRoot',
docRootComponent: '@theme/DocRoot',
docItemComponent: '@theme/DocItem',
remarkPlugins: [require('./my-remark-plugin')],
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'],
},
},
],
],
};