Skip to content

Commit

Permalink
fix: getFileInfo does not add .html extension in url when build.forma…
Browse files Browse the repository at this point in the history
…t is file (#4849)

* Create appendExtension

* Add html to file URLs if build.format is file

* Add changeset
  • Loading branch information
Rishi Raj Jain authored Sep 23, 2022
1 parent 944d24e commit ee5fdef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/light-shrimps-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

append .html to the file URL in case build.format says file
4 changes: 4 additions & 0 deletions packages/astro/src/core/path.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function appendExtension(path: string, extension: string) {
return path + '.' + extension;
}

export function appendForwardSlash(path: string) {
return path.endsWith('/') ? path : path + '/';
}
Expand Down
5 changes: 4 additions & 1 deletion packages/astro/src/vite-plugin-utils/index.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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 };
}

Expand Down

0 comments on commit ee5fdef

Please sign in to comment.