mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-01 07:49:43 +02:00
chore(v2): fix several lint warnings, add missing types, cleanup (#3844)
* fix several lint warnings, add missing types, cleanup * fix EnumChangefreq issue * better utilization of EnumChangefreq type * update test snapshot
This commit is contained in:
parent
139b668737
commit
ad31facb32
49 changed files with 228 additions and 171 deletions
|
@ -59,7 +59,7 @@ describe('normalizeSitemapPluginOptions', () => {
|
|||
changefreq: 'annually',
|
||||
});
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
`"\\"changefreq\\" must be one of [always, hourly, daily, weekly, monthly, yearly, never]"`,
|
||||
`"\\"changefreq\\" must be one of [daily, monthly, always, hourly, weekly, yearly, never]"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import sitemap, {SitemapItemOptions} from 'sitemap';
|
||||
import sitemap, {Sitemap, SitemapItemOptions} from 'sitemap';
|
||||
import {PluginOptions} from './types';
|
||||
import {DocusaurusConfig} from '@docusaurus/types';
|
||||
|
||||
|
@ -13,28 +13,26 @@ export default function createSitemap(
|
|||
siteConfig: DocusaurusConfig,
|
||||
routesPaths: string[],
|
||||
options: PluginOptions,
|
||||
): sitemap.Sitemap {
|
||||
): Sitemap {
|
||||
const {url: hostname} = siteConfig;
|
||||
if (!hostname) {
|
||||
throw new Error('url in docusaurus.config.js cannot be empty/undefined');
|
||||
}
|
||||
const {cacheTime, changefreq, priority, trailingSlash} = options;
|
||||
|
||||
const urls = routesPaths
|
||||
.filter((route: string) => !route.endsWith('404.html'))
|
||||
.filter((route) => !route.endsWith('404.html'))
|
||||
.map(
|
||||
(routesPath) =>
|
||||
({
|
||||
url: `${routesPath}${
|
||||
options.trailingSlash && routesPath !== '/' ? '/' : ''
|
||||
}`,
|
||||
changefreq: options.changefreq,
|
||||
priority: options.priority,
|
||||
} as SitemapItemOptions),
|
||||
(routesPath): SitemapItemOptions => ({
|
||||
url: `${routesPath}${trailingSlash && routesPath !== '/' ? '/' : ''}`,
|
||||
changefreq,
|
||||
priority,
|
||||
}),
|
||||
);
|
||||
|
||||
return sitemap.createSitemap({
|
||||
hostname,
|
||||
cacheTime: options.cacheTime,
|
||||
cacheTime,
|
||||
urls,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import * as Joi from 'joi';
|
||||
import {EnumChangefreq} from 'sitemap';
|
||||
import {PluginOptions} from './types';
|
||||
|
||||
export const DEFAULT_OPTIONS: Required<PluginOptions> = {
|
||||
cacheTime: 600 * 1000, // 600 sec - cache purge period.
|
||||
changefreq: 'weekly',
|
||||
changefreq: EnumChangefreq.WEEKLY,
|
||||
priority: 0.5,
|
||||
trailingSlash: false,
|
||||
};
|
||||
|
@ -17,7 +18,7 @@ export const DEFAULT_OPTIONS: Required<PluginOptions> = {
|
|||
export const PluginOptionSchema = Joi.object({
|
||||
cacheTime: Joi.number().positive().default(DEFAULT_OPTIONS.cacheTime),
|
||||
changefreq: Joi.string()
|
||||
.valid('always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never')
|
||||
.valid(...Object.values(EnumChangefreq))
|
||||
.default(DEFAULT_OPTIONS.changefreq),
|
||||
priority: Joi.number().min(0).max(1).default(DEFAULT_OPTIONS.priority),
|
||||
trailingSlash: Joi.bool().default(false),
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import {EnumChangefreq} from 'sitemap';
|
||||
|
||||
export interface PluginOptions {
|
||||
cacheTime?: number;
|
||||
changefreq?: string;
|
||||
changefreq?: EnumChangefreq;
|
||||
priority?: number;
|
||||
trailingSlash?: boolean;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue