๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ
๋ฒ„์ „: ๋ถˆ์•ˆ์ • ๐Ÿšง

๐Ÿ“ฆ plugin-sitemap

๊ฒ€์ƒ‰ ์—”์ง„ ํฌ๋กค๋Ÿฌ๊ฐ€ ์—ฌ๋Ÿฌ๋ถ„์˜ ์‚ฌ์ดํŠธ๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ์ˆ˜์ง‘ํ•  ์ˆ˜ ์žˆ๋„๋ก ์‚ฌ์ดํŠธ๋งต์„ ๋งŒ๋“ค์–ด์ฃผ๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์ž…๋‹ˆ๋‹ค.

production only

This plugin is always inactive in development and only active in production because it works on the build output.

์„ค์น˜โ€‹

npm install --save @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'date'date is YYYY-MM-DD. datetime is a ISO 8601 datetime. null is disabled. See sitemap docs.
ignorePatternsstring[][]glob ํŒจํ„ด ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค. ์ผ์น˜ํ•˜๋Š” ๋ผ์šฐํŠธ ๊ฒฝ๋กœ๋Š” ์‚ฌ์ดํŠธ๋งต์—์„œ ํ•„ํ„ฐ๋ง๋ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์— base URL์„ ํฌํ•จํ•ด์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
filenamestringsitemap.xml์ถœ๋ ฅ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ƒ์„ฑ๋œ ์‚ฌ์ดํŠธ๋งต ํŒŒ์ผ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค. ๋‘ ๊ฐœ์˜ ํŒŒ์ผ์„ ์ถœ๋ ฅํ•˜๋Š” ๋‘ ๊ฐœ์˜ ํ”Œ๋Ÿฌ๊ทธ์ธ ์ธ์Šคํ„ด์Šค๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
createSitemapItemsCreateSitemapItemsFn | undefinedundefinedAn 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[]>;

SitemapItemโ€‹

type SitemapItem = {
url: string;
lastmod?: string | null;
changefreq?:
| 'always'
| 'hourly'
| 'daily'
| 'weekly'
| 'monthly'
| 'yearly'
| 'never'
| null;
priority?: number | null;
};

See the sitemap protocol docs for the meaning of each field.

์ •๋ณด

์ด ํ”Œ๋Ÿฌ๊ทธ์ธ์€ ์ผ๋ถ€ ์‚ฌ์ดํŠธ ์„ค์ •์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.

  • noIndex: results in no sitemap generated
  • trailingSlash: determines if the URLs in the sitemap have trailing slashes
About lastmod

The 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.

์„ค์ • ์˜ˆ์‹œโ€‹

ํ”„๋ฆฌ์…‹ ์˜ต์…˜์ด๋‚˜ ํ”Œ๋Ÿฌ๊ทธ์ธ ์˜ต์…˜์—์„œ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํŒ

๋Œ€๋ถ€๋ถ„์˜ ๋„ํ์‚ฌ์šฐ๋ฃจ์Šค ์‚ฌ์šฉ์ž๋Š” ํ”„๋ฆฌ์…‹ ์˜ต์…˜์„ ์‚ฌ์šฉํ•ด ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

ํ”„๋ฆฌ์…‹์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ํ”„๋ฆฌ์…‹ ์˜ต์…˜๋ฅผ ํ†ตํ•ด ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.

docusaurus.config.js
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
sitemap: {
lastmod: 'date',
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/'));
},
},
},
],
],
};

You can find your sitemap at /sitemap.xml.

Emitting changefreq and priorityโ€‹

The plugin doesn't emit \<changefreq> and \<priority> tags, which Google ignores. If you need them, use createSitemapItems to emit distinct values per URL:

ํ”„๋ฆฌ์…‹์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ํ”„๋ฆฌ์…‹ ์˜ต์…˜๋ฅผ ํ†ตํ•ด ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.

docusaurus.config.js
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
sitemap: {
createSitemapItems: async (params) => {
const {defaultCreateSitemapItems, ...rest} = params;
const items = await defaultCreateSitemapItems(rest);
return items.map((item) => ({
...item,
changefreq: item.url.includes('/blog/') ? 'weekly' : 'monthly',
priority: item.url.includes('/docs/') ? 0.8 : 0.5,
}));
},
},
},
],
],
};