Fixes pageUrlFormat: 'file' in static build (#2569)

* Fixes pageUrlFormat: 'file' in static build

* Adds a changeset
This commit is contained in:
Matthew Phillips 2022-02-11 09:43:42 -05:00 committed by GitHub
parent 176b77329e
commit 82544e4134
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes pageUrlFormat: 'file' in the static build

View file

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

View file

@ -0,0 +1,4 @@
<html>
<head><title>One</title></head>
<body><h1>Testing</h1></body>
</html>

View file

@ -0,0 +1,4 @@
<html>
<head><title>Subpath</title></head>
<body><h1>Testing</h1></body>
</html>

View file

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