From ee5fdeffddfee32a0d7708bbf6b64cee50e82aa7 Mon Sep 17 00:00:00 2001 From: Rishi Raj Jain Date: Fri, 23 Sep 2022 17:37:27 +0530 Subject: [PATCH] fix: getFileInfo does not add .html extension in url when build.format is file (#4849) * Create appendExtension * Add html to file URLs if build.format is file * Add changeset --- .changeset/light-shrimps-draw.md | 5 +++++ packages/astro/src/core/path.ts | 4 ++++ packages/astro/src/vite-plugin-utils/index.ts | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/light-shrimps-draw.md diff --git a/.changeset/light-shrimps-draw.md b/.changeset/light-shrimps-draw.md new file mode 100644 index 000000000..756d9b0a3 --- /dev/null +++ b/.changeset/light-shrimps-draw.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +append .html to the file URL in case build.format says file diff --git a/packages/astro/src/core/path.ts b/packages/astro/src/core/path.ts index 307283c72..17648ece5 100644 --- a/packages/astro/src/core/path.ts +++ b/packages/astro/src/core/path.ts @@ -1,3 +1,7 @@ +export function appendExtension(path: string, extension: string) { + return path + '.' + extension; +} + export function appendForwardSlash(path: string) { return path.endsWith('/') ? path : path + '/'; } diff --git a/packages/astro/src/vite-plugin-utils/index.ts b/packages/astro/src/vite-plugin-utils/index.ts index 9beadcbfd..59725ad3b 100644 --- a/packages/astro/src/vite-plugin-utils/index.ts +++ b/packages/astro/src/vite-plugin-utils/index.ts @@ -1,6 +1,6 @@ import { Data } from 'vfile'; import type { AstroConfig, MarkdownAstroData } from '../@types/astro'; -import { appendForwardSlash } from '../core/path.js'; +import { appendForwardSlash, appendExtension } from '../core/path.js'; export function getFileInfo(id: string, config: AstroConfig) { const sitePathname = appendForwardSlash( @@ -14,6 +14,9 @@ export function getFileInfo(id: string, config: AstroConfig) { if (fileUrl && config.trailingSlash === 'always') { fileUrl = appendForwardSlash(fileUrl); } + if (fileUrl && config.build.format === 'file') { + fileUrl = appendExtension(fileUrl, 'html'); + } return { fileId, fileUrl }; }