Fix typescript errors in the build (#124)

* Fix build

* Put sitemap on the buildOptions
This commit is contained in:
Matthew Phillips 2021-04-22 11:45:05 -04:00 committed by GitHub
parent da033e27ea
commit f5384b139d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View file

@ -186,7 +186,7 @@ export async function build(astroConfig: AstroConfig): Promise<0 | 1> {
const filepath = new URL(`file://${pathname}`);
const pageType = getPageType(filepath);
const pageOptions: PageBuildOptions = { astroRoot, dist, filepath, runtime, sitemap: astroConfig.sitemap, statics };
const pageOptions: PageBuildOptions = { astroRoot, dist, filepath, runtime, sitemap: astroConfig.buildOptions.sitemap, statics };
if (pageType === 'collection') {
const { canonicalURLs } = await buildCollectionPage(pageOptions);
builtURLs.push(...canonicalURLs);
@ -239,7 +239,7 @@ export async function build(astroConfig: AstroConfig): Promise<0 | 1> {
}
// build sitemap
if (astroConfig.sitemap && astroConfig.site) {
if (astroConfig.buildOptions.sitemap && astroConfig.site) {
const sitemap = generateSitemap(
builtURLs.map((url) => ({
canonicalURL: new URL(
@ -249,7 +249,7 @@ export async function build(astroConfig: AstroConfig): Promise<0 | 1> {
}))
);
await writeFile(new URL('./sitemap.xml', dist), sitemap, 'utf8');
} else if (astroConfig.sitemap) {
} else if (astroConfig.buildOptions.sitemap) {
info(logging, 'tip', `Set your "site" in astro.config.mjs to generate a sitemap.xml`);
}

View file

@ -25,7 +25,7 @@ function validateConfig(config: any): void {
}
}
if(config.devOptions?.port !== 'number') {
if(typeof config.devOptions?.port !== 'number') {
throw new Error(`[astro config] devOptions.port: Expected number, received ${type(config.devOptions?.port)}`)
}
}
@ -40,7 +40,8 @@ function configDefaults(userConfig?: any): any {
if (!config.public) config.public = './public';
if (!config.devOptions) config.devOptions = {};
if (!config.devOptions.port) config.devOptions.port = 3000;
if (typeof config.sitemap === 'undefined') config.sitemap = true;
if (!config.buildOptions) config.buildOptions = {};
if (typeof config.buildOptions.sitemap === 'undefined') config.buildOptions.sitemap = true;
return config;
}