Fixes pageUrlFormat: 'file' in static build (#2569)
* Fixes pageUrlFormat: 'file' in static build * Adds a changeset
This commit is contained in:
parent
176b77329e
commit
82544e4134
5 changed files with 49 additions and 2 deletions
5
.changeset/gold-kangaroos-notice.md
Normal file
5
.changeset/gold-kangaroos-notice.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes pageUrlFormat: 'file' in the static build
|
|
@ -395,7 +395,7 @@ function getOutFolder(astroConfig: AstroConfig, pathname: string): URL {
|
||||||
case 'directory':
|
case 'directory':
|
||||||
return new URL('.' + appendForwardSlash(pathname), outRoot);
|
return new URL('.' + appendForwardSlash(pathname), outRoot);
|
||||||
case 'file':
|
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':
|
case 'directory':
|
||||||
return new URL('./index.html', outFolder);
|
return new URL('./index.html', outFolder);
|
||||||
case 'file':
|
case 'file':
|
||||||
return new URL('.' + pathname + '.html', outFolder);
|
return new URL('./' + npath.basename(pathname) + '.html', outFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
packages/astro/test/fixtures/static-build-page-url-format/src/pages/one.astro
vendored
Normal file
4
packages/astro/test/fixtures/static-build-page-url-format/src/pages/one.astro
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<html>
|
||||||
|
<head><title>One</title></head>
|
||||||
|
<body><h1>Testing</h1></body>
|
||||||
|
</html>
|
4
packages/astro/test/fixtures/static-build-page-url-format/src/pages/sub/page.astro
vendored
Normal file
4
packages/astro/test/fixtures/static-build-page-url-format/src/pages/sub/page.astro
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<html>
|
||||||
|
<head><title>Subpath</title></head>
|
||||||
|
<body><h1>Testing</h1></body>
|
||||||
|
</html>
|
34
packages/astro/test/static-build-page-url-format.test.js
Normal file
34
packages/astro/test/static-build-page-url-format.test.js
Normal 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');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue