diff --git a/.changeset/gold-kangaroos-notice.md b/.changeset/gold-kangaroos-notice.md new file mode 100644 index 000000000000..4d487285ea91 --- /dev/null +++ b/.changeset/gold-kangaroos-notice.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes pageUrlFormat: 'file' in the static build diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index cbbabfa7b777..22255148d537 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -395,7 +395,7 @@ function getOutFolder(astroConfig: AstroConfig, pathname: string): URL { case 'directory': return new URL('.' + appendForwardSlash(pathname), outRoot); case 'file': - return outRoot; + return new URL('.' + appendForwardSlash(npath.dirname(pathname)), outRoot); } } @@ -404,7 +404,7 @@ function getOutFile(astroConfig: AstroConfig, outFolder: URL, pathname: string): case 'directory': return new URL('./index.html', outFolder); case 'file': - return new URL('.' + pathname + '.html', outFolder); + return new URL('./' + npath.basename(pathname) + '.html', outFolder); } } diff --git a/packages/astro/test/fixtures/static-build-page-url-format/src/pages/one.astro b/packages/astro/test/fixtures/static-build-page-url-format/src/pages/one.astro new file mode 100644 index 000000000000..ad4feb92be3c --- /dev/null +++ b/packages/astro/test/fixtures/static-build-page-url-format/src/pages/one.astro @@ -0,0 +1,4 @@ + +One +

Testing

+ diff --git a/packages/astro/test/fixtures/static-build-page-url-format/src/pages/sub/page.astro b/packages/astro/test/fixtures/static-build-page-url-format/src/pages/sub/page.astro new file mode 100644 index 000000000000..e8914f77e83e --- /dev/null +++ b/packages/astro/test/fixtures/static-build-page-url-format/src/pages/sub/page.astro @@ -0,0 +1,4 @@ + +Subpath +

Testing

+ diff --git a/packages/astro/test/static-build-page-url-format.test.js b/packages/astro/test/static-build-page-url-format.test.js new file mode 100644 index 000000000000..f082d2c0f4f7 --- /dev/null +++ b/packages/astro/test/static-build-page-url-format.test.js @@ -0,0 +1,34 @@ +import { expect } from 'chai'; +import cheerio from 'cheerio'; +import { loadFixture } from './test-utils.js'; + +function addLeadingSlash(path) { + return path.startsWith('/') ? path : '/' + path; +} + +describe('Static build - pageUrlFormat: \'file\'', () => { + let fixture; + + before(async () => { + fixture = await loadFixture({ + projectRoot: './fixtures/static-build-page-url-format/', + renderers: [], + buildOptions: { + experimentalStaticBuild: true, + site: 'http://example.com/subpath/', + pageUrlFormat: 'file' + }, + }); + await fixture.build(); + }); + + it('Builds pages in root', async () => { + const html = await fixture.readFile('/subpath/one.html'); + expect(html).to.be.a('string'); + }); + + it('Builds pages in subfolders', async () => { + const html = await fixture.readFile('/subpath/sub/page.html'); + expect(html).to.be.a('string'); + }); +});