summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joaquín Sánchez <joaquin.sanchez@fi2net.es> 2022-05-26 16:19:19 +0200
committerGravatar GitHub <noreply@github.com> 2022-05-26 10:19:19 -0400
commit79b9ebc83ab7e190bd2894338e51e7f3f41e04d2 (patch)
tree79edc4a2ac91099e9fbb73f93d95f84ae1af5e4a
parentc4658ba857d1982406bc362210d3ccac8d6afbde (diff)
downloadastro-79b9ebc83ab7e190bd2894338e51e7f3f41e04d2.tar.gz
astro-79b9ebc83ab7e190bd2894338e51e7f3f41e04d2.tar.zst
astro-79b9ebc83ab7e190bd2894338e51e7f3f41e04d2.zip
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
-rw-r--r--.changeset/ten-hounds-fry.md5
-rw-r--r--.gitignore3
-rw-r--r--packages/astro/src/@types/astro.ts2
-rw-r--r--packages/astro/src/core/build/generate.ts1
-rw-r--r--packages/astro/test/static-build-page-dist-url.test.js34
5 files changed, 45 insertions, 0 deletions
diff --git a/.changeset/ten-hounds-fry.md b/.changeset/ten-hounds-fry.md
new file mode 100644
index 000000000..9db3680d2
--- /dev/null
+++ b/.changeset/ten-hounds-fry.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Expose route dist URL on SSG
diff --git a/.gitignore b/.gitignore
index fa9abb6d0..8967dc4b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,6 @@ package-lock.json
!packages/astro/vendor/vite/dist
packages/integrations/**/.netlify/
+
+# exclude IntelliJ/WebStorm stuff
+.idea
diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts
index ada2427ad..31f9e98f3 100644
--- a/packages/astro/src/@types/astro.ts
+++ b/packages/astro/src/@types/astro.ts
@@ -963,6 +963,8 @@ export interface RouteData {
generate: (data?: any) => string;
params: string[];
pathname?: string;
+ // expose the real path name on SSG
+ distURL?: URL;
pattern: RegExp;
segments: RoutePart[][];
type: RouteType;
diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts
index d0dec38be..5a9965eee 100644
--- a/packages/astro/src/core/build/generate.ts
+++ b/packages/astro/src/core/build/generate.ts
@@ -250,6 +250,7 @@ async function generatePath(
const outFolder = getOutFolder(astroConfig, 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.writeFile(outFile, body, 'utf-8');
}
diff --git a/packages/astro/test/static-build-page-dist-url.test.js b/packages/astro/test/static-build-page-dist-url.test.js
new file mode 100644
index 000000000..0d5bd09aa
--- /dev/null
+++ b/packages/astro/test/static-build-page-dist-url.test.js
@@ -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`
+ ));
+ });
+});
+
+
+