-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
schema.ts
39 lines (34 loc) · 1.14 KB
/
schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { EnumChangefreq as ChangeFreq } from 'sitemap';
import { z } from 'zod';
import { SITEMAP_CONFIG_DEFAULTS } from './config-defaults.js';
const localeKeySchema = z.string().min(1);
export const SitemapOptionsSchema = z
.object({
filter: z.function().args(z.string()).returns(z.boolean()).optional(),
customPages: z.string().url().array().optional(),
canonicalURL: z.string().url().optional(),
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(),
entryLimit: z.number().nonnegative().optional().default(SITEMAP_CONFIG_DEFAULTS.entryLimit),
serialize: z.function().args(z.any()).returns(z.any()).optional(),
changefreq: z.nativeEnum(ChangeFreq).optional(),
lastmod: z.date().optional(),
priority: z.number().min(0).max(1).optional(),
})
.strict()
.default(SITEMAP_CONFIG_DEFAULTS);