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:
parent
944d24e9ee
commit
ee5fdeffdd
3 changed files with 13 additions and 1 deletions
5
.changeset/light-shrimps-draw.md
Normal file
5
.changeset/light-shrimps-draw.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
append .html to the file URL in case build.format says file
|
|
@ -1,3 +1,7 @@
|
||||||
|
export function appendExtension(path: string, extension: string) {
|
||||||
|
return path + '.' + extension;
|
||||||
|
}
|
||||||
|
|
||||||
export function appendForwardSlash(path: string) {
|
export function appendForwardSlash(path: string) {
|
||||||
return path.endsWith('/') ? path : path + '/';
|
return path.endsWith('/') ? path : path + '/';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Data } from 'vfile';
|
import { Data } from 'vfile';
|
||||||
import type { AstroConfig, MarkdownAstroData } from '../@types/astro';
|
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) {
|
export function getFileInfo(id: string, config: AstroConfig) {
|
||||||
const sitePathname = appendForwardSlash(
|
const sitePathname = appendForwardSlash(
|
||||||
|
@ -14,6 +14,9 @@ export function getFileInfo(id: string, config: AstroConfig) {
|
||||||
if (fileUrl && config.trailingSlash === 'always') {
|
if (fileUrl && config.trailingSlash === 'always') {
|
||||||
fileUrl = appendForwardSlash(fileUrl);
|
fileUrl = appendForwardSlash(fileUrl);
|
||||||
}
|
}
|
||||||
|
if (fileUrl && config.build.format === 'file') {
|
||||||
|
fileUrl = appendExtension(fileUrl, 'html');
|
||||||
|
}
|
||||||
return { fileId, fileUrl };
|
return { fileId, fileUrl };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue