📦 plugin-sitemap
검색 엔진 크롤러가 여러분의 사이트를 정확하게 수집할 수 있도록 사이트맵을 만들어주는 플러그인입니다.
This plugin is always inactive in development and only active in production because it works on the build output.
설치
- npm
- Yarn
- pnpm
- Bun
npm install --save @docusaurus/plugin-sitemap
yarn add @docusaurus/plugin-sitemap
pnpm add @docusaurus/plugin-sitemap
bun add @docusaurus/plugin-sitemap
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.
설정
설정할 수 있는 필드
| 옵션명 | 타입 | 기본값 | 설명 |
|---|---|---|---|
lastmod | 'date' | 'datetime' | null | null | date is YYYY-MM-DD. datetime is a ISO 8601 datetime. null is disabled. See sitemap docs. |
changefreq | string | null | 'weekly' | See sitemap docs |
priority | number | null | 0.5 | See sitemap docs |
ignorePatterns | string[] | [] | glob 패턴 목록입니다. 일치하는 라우트 경로는 사이트맵에서 필터링됩니다. 여기에 base URL을 포함해야 할 수도 있습니다. |
filename | string | sitemap.xml | 출력 디렉토리를 기준으로 생성된 사이트맵 파일 경로입니다. 두 개의 파일을 출력하는 두 개의 플러그인 인스턴스가 있는 경우 유용합니다. |
createSitemapItems | CreateSitemapItemsFn | undefined | undefined | An optional function which can be used to transform and / or filter the items in the sitemap. |
타입
CreateSitemapItemsFn
type CreateSitemapItemsFn = (params: {
siteConfig: DocusaurusConfig;
routes: RouteConfig[];
defaultCreateSitemapItems: CreateSitemapItemsFn;
}) => Promise<SitemapItem[]>;
이 플러그인은 일부 사이트 설정을 유지합니다.
noIndex: results in no sitemap generatedtrailingSlash: determines if the URLs in the sitemap have trailing slashes
lastmodThe lastmod option will only output a sitemap \<lastmod> tag if plugins provide route metadata attributes sourceFilePath and/or lastUpdatedAt.
All the official content plugins provide the metadata for routes backed by a content file (Markdown, MDX or React page components), but it is possible third-party plugin authors do not provide this information, and the plugin will not be able to output a \<lastmod> tag for their routes.
설정 예시
프리셋 옵션이나 플러그인 옵션에서 플러그인을 설정할 수 있습니다.
대부분의 도큐사우루스 사용자는 프리셋 옵션을 사용해 플러그인을 설정합니다.
- 프리셋 옵션
- 플러그인 옵션
프리셋을 사용하는 경우 프리셋 옵션를 통해 플러그인을 구성합니다.
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
sitemap: {
lastmod: 'date',
changefreq: 'weekly',
priority: 0.5,
ignorePatterns: ['/tags/**'],
filename: 'sitemap.xml',
createSitemapItems: async (params) => {
const {defaultCreateSitemapItems, ...rest} = params;
const items = await defaultCreateSitemapItems(rest);
return items.filter((item) => !item.url.includes('/page/'));
},
},
},
],
],
};
독립적으로 실행되는 플러그인을 사용하는 경우에는 플러그인에 대한 옵션을 직접 설정할 수 있습니다.
module.exports = {
plugins: [
[
'@docusaurus/plugin-sitemap',
{
lastmod: 'date',
changefreq: 'weekly',
priority: 0.5,
ignorePatterns: ['/tags/**'],
filename: 'sitemap.xml',
createSitemapItems: async (params)