From 78e06c8ec01e041e3f78625cb85bcce0cf5be029 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Fri, 26 Aug 2022 11:35:30 -0400 Subject: [PATCH] Only print file output only for 404 and 500 routes (#4497) * fix: print file output only for 404 and 500 routes * chore: changeset --- .changeset/modern-schools-fold.md | 5 +++++ packages/astro/src/core/util.ts | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .changeset/modern-schools-fold.md diff --git a/.changeset/modern-schools-fold.md b/.changeset/modern-schools-fold.md new file mode 100644 index 000000000000..9f2cadb21774 --- /dev/null +++ b/.changeset/modern-schools-fold.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Production build logging - Only log `[code].html` instead of `[code]/index.html` for 404 and 500 routes diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 4087943808c9..3c74b5580b31 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -26,7 +26,7 @@ export function padMultilineString(source: string, n = 2) { return lines.map((l) => ` `.repeat(n) + l).join(`\n`); } -const STATUS_CODE_REGEXP = /^\/?[0-9]{3}$/; +const REGEXP_404_OR_500_ROUTE = /(404)|(500)\/?$/; /** * Get the correct output filename for a route, based on your config. @@ -37,14 +37,13 @@ export function getOutputFilename(astroConfig: AstroConfig, name: string, type: if (type === 'endpoint') { return name; } - if (name === '/' || name === '') { return path.posix.join(name, 'index.html'); } - if (astroConfig.build.format === 'directory' && !STATUS_CODE_REGEXP.test(name)) { - return path.posix.join(name, 'index.html'); + if (astroConfig.build.format === 'file' || REGEXP_404_OR_500_ROUTE.test(name)) { + return `${removeTrailingForwardSlash(name || 'index')}.html`; } - return `${removeTrailingForwardSlash(name || 'index')}.html`; + return path.posix.join(name, 'index.html'); } /** is a specifier an npm package? */