diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 2f70b9bf5f..406186a21d 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -240,14 +240,21 @@ interface GeneratePathOptions { renderers: SSRLoadedRenderer[]; } -function shouldAppendForwardSlash(trailingSlash: AstroConfig['trailingSlash'], buildFormat: AstroConfig['build']['format']): boolean { - switch(trailingSlash) { - case 'always': return true; - case 'never': return false; +function shouldAppendForwardSlash( + trailingSlash: AstroConfig['trailingSlash'], + buildFormat: AstroConfig['build']['format'] +): boolean { + switch (trailingSlash) { + case 'always': + return true; + case 'never': + return false; case 'ignore': { - switch(buildFormat) { - case 'directory': return true; - case 'file': return false; + switch (buildFormat) { + case 'directory': + return true; + case 'file': + return false; } } } @@ -256,9 +263,9 @@ function shouldAppendForwardSlash(trailingSlash: AstroConfig['trailingSlash'], b function addPageName(pathname: string, opts: StaticBuildOptions): void { const trailingSlash = opts.astroConfig.trailingSlash; const buildFormat = opts.astroConfig.build.format; - const pageName = shouldAppendForwardSlash(trailingSlash, buildFormat) ? - pathname.replace(/\/?$/, '/').replace(/^\//, '') : - pathname.replace(/^\//, '') + const pageName = shouldAppendForwardSlash(trailingSlash, buildFormat) + ? pathname.replace(/\/?$/, '/').replace(/^\//, '') + : pathname.replace(/^\//, ''); opts.pageNames.push(pageName); } diff --git a/packages/integrations/sitemap/test/test-utils.js b/packages/integrations/sitemap/test/test-utils.js index 22c1d19197..31d40de9ef 100644 --- a/packages/integrations/sitemap/test/test-utils.js +++ b/packages/integrations/sitemap/test/test-utils.js @@ -19,12 +19,12 @@ export function loadFixture(inlineConfig) { export function readXML(fileOrPromise) { const parseString = xml2js.parseString; - return Promise.resolve(fileOrPromise).then(xml => { + return Promise.resolve(fileOrPromise).then((xml) => { return new Promise((resolve, reject) => { parseString(xml, function (err, result) { - if(err) return reject(err); + if (err) return reject(err); resolve(result); + }); }); - }) }); } diff --git a/packages/integrations/sitemap/test/trailing-slash.test.js b/packages/integrations/sitemap/test/trailing-slash.test.js index 6b6aa3a352..b5b7dd6c15 100644 --- a/packages/integrations/sitemap/test/trailing-slash.test.js +++ b/packages/integrations/sitemap/test/trailing-slash.test.js @@ -12,12 +12,12 @@ describe('Trailing slash', () => { root: './fixtures/trailing-slash/', trailingSlash: 'ignore', build: { - format: 'directory' - } + format: 'directory', + }, }); await fixture.build(); }); - + it('URLs end with trailing slash', async () => { const data = await readXML(fixture.readFile('/sitemap-0.xml')); const urls = data.urlset.url; @@ -31,15 +31,15 @@ describe('Trailing slash', () => { root: './fixtures/trailing-slash/', trailingSlash: 'ignore', build: { - format: 'file' - } + format: 'file', + }, }); await fixture.build(); }); - + it('URLs do not end with trailing slash', async () => { const data = await readXML(fixture.readFile('/sitemap-0.xml')); - const urls = data.urlset.url; + const urls = data.urlset.url; expect(urls[0].loc[0]).to.equal('http://example.com/one'); }); }); @@ -53,7 +53,7 @@ describe('Trailing slash', () => { }); await fixture.build(); }); - + it('URLs do no end with trailing slash', async () => { const data = await readXML(fixture.readFile('/sitemap-0.xml')); const urls = data.urlset.url; @@ -69,7 +69,7 @@ describe('Trailing slash', () => { }); await fixture.build(); }); - + it('URLs end with trailing slash', async () => { const data = await readXML(fixture.readFile('/sitemap-0.xml')); const urls = data.urlset.url;