Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getFileInfo does not add .html extension in url when build.format is file #4849

Merged
merged 3 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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