mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
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
This commit is contained in:
parent
eaa626de88
commit
7e0b32c569
6 changed files with 66 additions and 3 deletions
5
.changeset/tricky-eagles-enjoy.md
Normal file
5
.changeset/tricky-eagles-enjoy.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes use of --experimental-static-build with markdown pages
|
|
@ -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 { Plugin as VitePlugin, UserConfig } from '../vite';
|
||||||
import type { AstroConfig, RouteCache, SSRElement } from '../../@types/astro';
|
import type { AstroConfig, RouteCache, SSRElement } from '../../@types/astro';
|
||||||
import type { AllPagesData } from './types';
|
import type { AllPagesData } from './types';
|
||||||
|
@ -35,6 +35,17 @@ function addPageName(pathname: string, opts: StaticBuildOptions): void {
|
||||||
opts.pageNames.push(pathname.replace(/\/?$/, pathrepl).replace(/^\//, ''));
|
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) {
|
export async function staticBuild(opts: StaticBuildOptions) {
|
||||||
const { allPages, astroConfig } = opts;
|
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');
|
debug(opts.logging, 'generate', 'End build step, now generating');
|
||||||
const generationPromises = [];
|
const generationPromises = [];
|
||||||
for (let output of result.output) {
|
for (let output of result.output) {
|
||||||
if (output.type === 'chunk' && output.facadeModuleId && output.facadeModuleId.endsWith('.astro')) {
|
if (chunkIsPage(output, internals)) {
|
||||||
generationPromises.push(generatePage(output, opts, internals, facadeIdToPageDataMap));
|
generationPromises.push(generatePage(output as OutputChunk, opts, internals, facadeIdToPageDataMap));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Promise.all(generationPromises);
|
await Promise.all(generationPromises);
|
||||||
|
|
6
packages/astro/test/fixtures/static-build/src/layouts/Main.astro
vendored
Normal file
6
packages/astro/test/fixtures/static-build/src/layouts/Main.astro
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Testing</title>
|
||||||
|
</head>
|
||||||
|
<body><slot></slot></body>
|
||||||
|
</html>
|
6
packages/astro/test/fixtures/static-build/src/pages/index.astro
vendored
Normal file
6
packages/astro/test/fixtures/static-build/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Testing</title>
|
||||||
|
</head>
|
||||||
|
<body><h1>Testing</h1></body>
|
||||||
|
</html>
|
7
packages/astro/test/fixtures/static-build/src/pages/posts/thoughts.md
vendored
Normal file
7
packages/astro/test/fixtures/static-build/src/pages/posts/thoughts.md
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
layout: ../../layouts/Main.astro
|
||||||
|
---
|
||||||
|
|
||||||
|
# Post
|
||||||
|
|
||||||
|
Testing here
|
28
packages/astro/test/static-build.test.js
Normal file
28
packages/astro/test/static-build.test.js
Normal file
|
@ -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');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue