summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2022-02-11 09:43:42 -0500
committerGravatar GitHub <noreply@github.com> 2022-02-11 14:43:42 +0000
commit82544e413406a62ecf3e408ca1aac5c8c15b7453 (patch)
tree1aa26218b03a73a286278664747492504e46c31f
parent176b77329e573f7229fbaa3dd92b71f664a48139 (diff)
downloadastro-82544e413406a62ecf3e408ca1aac5c8c15b7453.tar.gz
astro-82544e413406a62ecf3e408ca1aac5c8c15b7453.tar.zst
astro-82544e413406a62ecf3e408ca1aac5c8c15b7453.zip
Fixes pageUrlFormat: 'file' in static build (#2569)
* Fixes pageUrlFormat: 'file' in static build * Adds a changeset
-rw-r--r--.changeset/gold-kangaroos-notice.md5
-rw-r--r--packages/astro/src/core/build/static-build.ts4
-rw-r--r--packages/astro/test/fixtures/static-build-page-url-format/src/pages/one.astro4
-rw-r--r--packages/astro/test/fixtures/static-build-page-url-format/src/pages/sub/page.astro4
-rw-r--r--packages/astro/test/static-build-page-url-format.test.js34
5 files changed, 49 insertions, 2 deletions
diff --git a/.changeset/gold-kangaroos-notice.md b/.changeset/gold-kangaroos-notice.md
new file mode 100644
index 000000000..4d487285e
--- /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 cbbabfa7b..22255148d 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 000000000..ad4feb92b
--- /dev/null
+++ b/packages/astro/test/fixtures/static-build-page-url-format/src/pages/one.astro
@@ -0,0 +1,4 @@
+<html>
+<head><title>One</title></head>
+<body><h1>Testing</h1></body>
+</html>
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 000000000..e8914f77e
--- /dev/null
+++ b/packages/astro/test/fixtures/static-build-page-url-format/src/pages/sub/page.astro
@@ -0,0 +1,4 @@
+<html>
+<head><title>Subpath</title></head>
+<body><h1>Testing</h1></body>
+</html>
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 000000000..f082d2c0f
--- /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');
+ });
+});