2022-06-20 19:29:53 +00:00
|
|
|
import { EnumChangefreq as ChangeFreq } from 'sitemap';
|
2022-06-20 19:31:39 +00:00
|
|
|
import { z } from 'zod';
|
2022-06-21 15:29:18 +00:00
|
|
|
import { SITEMAP_CONFIG_DEFAULTS } from './config-defaults.js';
|
2022-06-16 19:06:48 +00:00
|
|
|
|
2022-06-20 19:29:53 +00:00
|
|
|
const localeKeySchema = z.string().min(1);
|
2022-06-16 19:06:48 +00:00
|
|
|
|
|
|
|
export const SitemapOptionsSchema = z
|
2022-06-20 19:31:39 +00:00
|
|
|
.object({
|
|
|
|
filter: z.function().args(z.string()).returns(z.boolean()).optional(),
|
|
|
|
customPages: z.string().url().array().optional(),
|
|
|
|
canonicalURL: z.string().url().optional(),
|
2022-06-16 19:06:48 +00:00
|
|
|
|
2022-06-20 19:31:39 +00:00
|
|
|
i18n: z
|
|
|
|
.object({
|
|
|
|
defaultLocale: localeKeySchema,
|
|
|
|
locales: z.record(
|
|
|
|
localeKeySchema,
|
|
|
|
z
|
|
|
|
.string()
|
|
|
|
.min(2)
|
|
|
|
.regex(/^[a-zA-Z\-]+$/gm, {
|
|
|
|
message: 'Only English alphabet symbols and hyphen allowed',
|
|
|
|
})
|
|
|
|
),
|
|
|
|
})
|
|
|
|
.refine((val) => !val || val.locales[val.defaultLocale], {
|
|
|
|
message: '`defaultLocale` must exist in `locales` keys',
|
|
|
|
})
|
|
|
|
.optional(),
|
2022-06-16 19:06:48 +00:00
|
|
|
|
2022-06-20 19:31:39 +00:00
|
|
|
entryLimit: z.number().nonnegative().optional().default(SITEMAP_CONFIG_DEFAULTS.entryLimit),
|
|
|
|
serialize: z.function().args(z.any()).returns(z.any()).optional(),
|
2022-06-16 19:06:48 +00:00
|
|
|
|
2022-06-20 19:31:39 +00:00
|
|
|
changefreq: z.nativeEnum(ChangeFreq).optional(),
|
|
|
|
lastmod: z.date().optional(),
|
|
|
|
priority: z.number().min(0).max(1).optional(),
|
|
|
|
})
|
|
|
|
.strict()
|
|
|
|
.default(SITEMAP_CONFIG_DEFAULTS);
|