Skip to content

Commit

Permalink
Fixes pageUrlFormat: 'file' in static build (withastro#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 committed Feb 11, 2022
1 parent 1f288bf commit 2cceb7e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 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 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:https://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 2cceb7e

Please sign in to comment.