📦 plugin-sitemap
This plugin creates sitemaps for your site so that search engine crawlers can crawl your site more accurately.
This plugin is always inactive in development and only active in production because it works on the build output.
インストール
- npm
- Yarn
- pnpm
npm install --save @docusaurus/plugin-sitemap
yarn add @docusaurus/plugin-sitemap
pnpm 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.
設定
Accepted fields:
名前 | Type | Default | 説明 |
---|---|---|---|
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[] | [] | A list of glob patterns; matching route paths will be filtered from the sitemap. Note that you may need to include the base URL in here. |
filename | string | sitemap.xml | The path to the created sitemap file, relative to the output directory. Useful if you have two plugin instances outputting two files. |
createSitemapItems | CreateSitemapItemsFn | undefined | undefined | An optional function which can be used to transform and / or filter the items in the sitemap. |
Types
CreateSitemapItemsFn
type CreateSitemapItemsFn = (params: {
siteConfig: DocusaurusConfig;
routes: RouteConfig[];
defaultCreateSitemapItems: CreateSitemapItemsFn;
}) => Promise<SitemapItem[]>;
This plugin also respects some site config:
noIndex
: results in no sitemap generatedtrailingSlash
: determines if the URLs in the sitemap have trailing slashes
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.
Example configuration
You can configure this plugin through preset options or plugin options.
Most Docusaurus users configure this plugin through the preset options.
- 設定オプション
- プラグイン
プリセットを使用する場合は、 設定オプション を介してこのプラグインを設定してください。
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) => {
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
.