Skip to content

Commit

Permalink
Fixes pageUrlFormat: 'file' in static build (#2569)
Browse files Browse the repository at this point in the history
* Fixes pageUrlFormat: 'file' in static build

* Adds a changeset
  • Loading branch information
matthewp authored Feb 11, 2022
1 parent 176b773 commit 82544e4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-kangaroos-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes pageUrlFormat: 'file' in the static build
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<html>
<head><title>One</title></head>
<body><h1>Testing</h1></body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<html>
<head><title>Subpath</title></head>
<body><h1>Testing</h1></body>
</html>
34 changes: 34 additions & 0 deletions packages/astro/test/static-build-page-url-format.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit 82544e4

Please sign in to comment.