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
This commit is contained in:
Rishi Raj Jain 2022-09-23 17:37:27 +05:30 committed by GitHub
parent 944d24e9ee
commit ee5fdeffdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
append .html to the file URL in case build.format says file

View file

@ -1,3 +1,7 @@
export function appendExtension(path: string, extension: string) {
return path + '.' + extension;
}
export function appendForwardSlash(path: string) {
return path.endsWith('/') ? path : path + '/';
}

View file

@ -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 };
}