mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
feat: expose route dist URL on SSG (#3438)
* feat: expose route dist URL on SSG * chore: add changeset * chore: add test for `distURL` * cleanup: remove console.log from test
This commit is contained in:
parent
c4658ba857
commit
79b9ebc83a
5 changed files with 45 additions and 0 deletions
5
.changeset/ten-hounds-fry.md
Normal file
5
.changeset/ten-hounds-fry.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Expose route dist URL on SSG
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -18,3 +18,6 @@ package-lock.json
|
||||||
|
|
||||||
!packages/astro/vendor/vite/dist
|
!packages/astro/vendor/vite/dist
|
||||||
packages/integrations/**/.netlify/
|
packages/integrations/**/.netlify/
|
||||||
|
|
||||||
|
# exclude IntelliJ/WebStorm stuff
|
||||||
|
.idea
|
||||||
|
|
|
@ -963,6 +963,8 @@ export interface RouteData {
|
||||||
generate: (data?: any) => string;
|
generate: (data?: any) => string;
|
||||||
params: string[];
|
params: string[];
|
||||||
pathname?: string;
|
pathname?: string;
|
||||||
|
// expose the real path name on SSG
|
||||||
|
distURL?: URL;
|
||||||
pattern: RegExp;
|
pattern: RegExp;
|
||||||
segments: RoutePart[][];
|
segments: RoutePart[][];
|
||||||
type: RouteType;
|
type: RouteType;
|
||||||
|
|
|
@ -250,6 +250,7 @@ async function generatePath(
|
||||||
|
|
||||||
const outFolder = getOutFolder(astroConfig, pathname, pageData.route.type);
|
const outFolder = getOutFolder(astroConfig, pathname, pageData.route.type);
|
||||||
const outFile = getOutFile(astroConfig, outFolder, pathname, pageData.route.type);
|
const outFile = getOutFile(astroConfig, outFolder, pathname, pageData.route.type);
|
||||||
|
pageData.route.distURL = outFile;
|
||||||
await fs.promises.mkdir(outFolder, { recursive: true });
|
await fs.promises.mkdir(outFolder, { recursive: true });
|
||||||
await fs.promises.writeFile(outFile, body, 'utf-8');
|
await fs.promises.writeFile(outFile, body, 'utf-8');
|
||||||
}
|
}
|
||||||
|
|
34
packages/astro/test/static-build-page-dist-url.test.js
Normal file
34
packages/astro/test/static-build-page-dist-url.test.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import { loadFixture } from './test-utils.js';
|
||||||
|
|
||||||
|
describe('Static build: pages routes have distURL', () => {
|
||||||
|
/** @type {import('./test-utils').Fixture} */
|
||||||
|
let fixture;
|
||||||
|
/** @type {RouteData[]} */
|
||||||
|
let checkRoutes
|
||||||
|
before(async () => {
|
||||||
|
const fixture = await loadFixture({
|
||||||
|
root: './fixtures/astro pages/',
|
||||||
|
integrations: [{
|
||||||
|
name: '@astrojs/distURL',
|
||||||
|
hooks: {
|
||||||
|
'astro:build:done': ({ routes }) => {
|
||||||
|
checkRoutes = routes.filter(p => p.type === 'page')
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
await fixture.build();
|
||||||
|
})
|
||||||
|
it('Pages routes have distURL', async () => {
|
||||||
|
expect(checkRoutes).to.have.lengthOf.above(0, 'Pages not found: build end hook not being called')
|
||||||
|
checkRoutes.forEach(p => expect(p).to.have.property(
|
||||||
|
'distURL'
|
||||||
|
).that.is.a(
|
||||||
|
'URL', `${p.pathname} doesn't include distURL`
|
||||||
|
));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue