fix: output 404.astro to 404.html (#1949)

* fix: output 404.astro to 404.html

* chore: revert example change

* fix: update status code to only match 404
This commit is contained in:
Nate Moore 2021-11-22 12:06:15 -06:00 committed by GitHub
parent 69affc5929
commit fc5f416382
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix regression with `astro build` 404.astro output

View file

@ -21,7 +21,7 @@ const ASTRO_PAGE_PREFIX = '@astro-page';
const ASTRO_SCRIPT_PREFIX = '@astro-script';
const ASTRO_EMPTY = '@astro-empty';
const STATUS_CODE_RE = /^404$/;
const tagsWithSrcSet = new Set(['img', 'source']);
const isAstroInjectedLink = (node: parse5.Element) => isStylesheetLink(node) && getAttribute(node, 'data-astro-injected') === '';
@ -424,7 +424,17 @@ export function rollupPluginAstroBuildHTML(options: PluginOptions): VitePlugin {
}
const outHTML = parse5.serialize(document);
const outPath = npath.posix.join(pathname.substr(1), 'index.html');
const name = pathname.substr(1);
let outPath: string;
// Output directly to 404.html rather than 400/index.html
// Supports any other status codes, too
if (name.match(STATUS_CODE_RE)) {
outPath = npath.posix.join(`${name}.html`)
} else {
outPath = npath.posix.join(name, 'index.html')
}
this.emitFile({
fileName: outPath,
source: outHTML,