2022-06-16 14:06:48 -05:00
|
|
|
import { z } from 'zod';
|
2022-06-21 10:29:18 -05:00
|
|
|
import type { SitemapOptions } from './index.js';
|
|
|
|
import { SitemapOptionsSchema } from './schema.js';
|
2022-06-16 14:06:48 -05:00
|
|
|
|
|
|
|
// @internal
|
|
|
|
export const validateOptions = (site: string | undefined, opts: SitemapOptions) => {
|
|
|
|
const result = SitemapOptionsSchema.parse(opts);
|
|
|
|
|
|
|
|
z.object({
|
|
|
|
site: z.string().optional(), // Astro takes care of `site`: how to validate, transform and refine
|
|
|
|
canonicalURL: z.string().optional(), // `canonicalURL` is already validated in prev step
|
|
|
|
})
|
2022-06-22 10:59:49 -05:00
|
|
|
.refine((options) => options.site || options.canonicalURL, {
|
2022-06-16 14:06:48 -05:00
|
|
|
message: 'Required `site` astro.config option or `canonicalURL` integration option',
|
|
|
|
})
|
|
|
|
.parse({
|
|
|
|
site,
|
|
|
|
canonicalURL: result.canonicalURL,
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|