summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@matthewphillips.info> 2022-01-11 16:52:46 -0500
committerGravatar GitHub <noreply@github.com> 2022-01-11 16:52:46 -0500
commit7e0b32c5696ec9db3cdee3de732de056b380568a (patch)
treec63aff256a8979e52c4665b609c14a1bb40da57a
parenteaa626de88cdd5481d7cae27ca3a3f3db0708a7c (diff)
downloadastro-7e0b32c5696ec9db3cdee3de732de056b380568a.tar.gz
astro-7e0b32c5696ec9db3cdee3de732de056b380568a.tar.zst
astro-7e0b32c5696ec9db3cdee3de732de056b380568a.zip
Fix: static-build with .md pages (#2363)
* Fix: static-build with .md pages This fixes the `--experimental-static-build` flag to work with markdown pages. * Adds a changeset * Account for difference in specifier on windows
-rw-r--r--.changeset/tricky-eagles-enjoy.md5
-rw-r--r--packages/astro/src/core/build/static-build.ts17
-rw-r--r--packages/astro/test/fixtures/static-build/src/layouts/Main.astro6
-rw-r--r--packages/astro/test/fixtures/static-build/src/pages/index.astro6
-rw-r--r--packages/astro/test/fixtures/static-build/src/pages/posts/thoughts.md7
-rw-r--r--packages/astro/test/static-build.test.js28
6 files changed, 66 insertions, 3 deletions
diff --git a/.changeset/tricky-eagles-enjoy.md b/.changeset/tricky-eagles-enjoy.md
new file mode 100644
index 000000000..4285d2c19
--- /dev/null
+++ b/.changeset/tricky-eagles-enjoy.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixes use of --experimental-static-build with markdown pages
diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts
index c424ec92d..1caeebdb1 100644
--- a/packages/astro/src/core/build/static-build.ts
+++ b/packages/astro/src/core/build/static-build.ts
@@ -1,4 +1,4 @@
-import type { OutputChunk, PreRenderedChunk, RollupOutput } from 'rollup';
+import type { OutputChunk, OutputAsset, PreRenderedChunk, RollupOutput } from 'rollup';
import type { Plugin as VitePlugin, UserConfig } from '../vite';
import type { AstroConfig, RouteCache, SSRElement } from '../../@types/astro';
import type { AllPagesData } from './types';
@@ -35,6 +35,17 @@ function addPageName(pathname: string, opts: StaticBuildOptions): void {
opts.pageNames.push(pathname.replace(/\/?$/, pathrepl).replace(/^\//, ''));
}
+// Determines of a Rollup chunk is an entrypoint page.
+function chunkIsPage(output: OutputAsset | OutputChunk, internals: BuildInternals) {
+ if(output.type !== 'chunk') {
+ return false;
+ }
+ const chunk = output as OutputChunk;
+ return chunk.facadeModuleId &&
+ (internals.entrySpecifierToBundleMap.has(chunk.facadeModuleId) ||
+ internals.entrySpecifierToBundleMap.has('/' + chunk.facadeModuleId));
+}
+
export async function staticBuild(opts: StaticBuildOptions) {
const { allPages, astroConfig } = opts;
@@ -158,8 +169,8 @@ async function generatePages(result: RollupOutput, opts: StaticBuildOptions, int
debug(opts.logging, 'generate', 'End build step, now generating');
const generationPromises = [];
for (let output of result.output) {
- if (output.type === 'chunk' && output.facadeModuleId && output.facadeModuleId.endsWith('.astro')) {
- generationPromises.push(generatePage(output, opts, internals, facadeIdToPageDataMap));
+ if (chunkIsPage(output, internals)) {
+ generationPromises.push(generatePage(output as OutputChunk, opts, internals, facadeIdToPageDataMap));
}
}
await Promise.all(generationPromises);
diff --git a/packages/astro/test/fixtures/static-build/src/layouts/Main.astro b/packages/astro/test/fixtures/static-build/src/layouts/Main.astro
new file mode 100644
index 000000000..b6af3a4fe
--- /dev/null
+++ b/packages/astro/test/fixtures/static-build/src/layouts/Main.astro
@@ -0,0 +1,6 @@
+<html>
+<head>
+<title>Testing</title>
+</head>
+<body><slot></slot></body>
+</html>
diff --git a/packages/astro/test/fixtures/static-build/src/pages/index.astro b/packages/astro/test/fixtures/static-build/src/pages/index.astro
new file mode 100644
index 000000000..e22975e58
--- /dev/null
+++ b/packages/astro/test/fixtures/static-build/src/pages/index.astro
@@ -0,0 +1,6 @@
+<html>
+<head>
+<title>Testing</title>
+</head>
+<body><h1>Testing</h1></body>
+</html>
diff --git a/packages/astro/test/fixtures/static-build/src/pages/posts/thoughts.md b/packages/astro/test/fixtures/static-build/src/pages/posts/thoughts.md
new file mode 100644
index 000000000..76e108103
--- /dev/null
+++ b/packages/astro/test/fixtures/static-build/src/pages/posts/thoughts.md
@@ -0,0 +1,7 @@
+---
+layout: ../../layouts/Main.astro
+---
+
+# Post
+
+Testing here
diff --git a/packages/astro/test/static-build.test.js b/packages/astro/test/static-build.test.js
new file mode 100644
index 000000000..2e0896cce
--- /dev/null
+++ b/packages/astro/test/static-build.test.js
@@ -0,0 +1,28 @@
+import { expect } from 'chai';
+import cheerio from 'cheerio';
+import { loadFixture } from './test-utils.js';
+
+describe('Static build', () => {
+ let fixture;
+
+ before(async () => {
+ fixture = await loadFixture({
+ projectRoot: './fixtures/static-build/',
+ renderers: [],
+ buildOptions: {
+ experimentalStaticBuild: true,
+ },
+ });
+ await fixture.build();
+ });
+
+ it('Builds out .astro pags', async () => {
+ const html = await fixture.readFile('/index.html');
+ expect(html).to.be.a('string');
+ });
+
+ it('Builds out .md pages', async () => {
+ const html = await fixture.readFile('/posts/thoughts/index.html');
+ expect(html).to.be.a('string');
+ });
+});