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(ssg): Uniformly Convert Paths Ending with Slash to 'index.ext' Format #2056

Merged
merged 2 commits into from
Jan 23, 2024
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
9 changes: 7 additions & 2 deletions deno_dist/helper/ssg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ export interface ToSSGResult {

const generateFilePath = (routePath: string, outDir: string, mimeType: string) => {
const extension = determineExtension(mimeType)
const fileName = routePath === '/' ? `index.${extension}` : `${routePath}.${extension}`
return joinPaths(outDir, fileName)
if (routePath === '/') {
return joinPaths(outDir, `index.${extension}`)
}
if (routePath.endsWith('/')) {
return joinPaths(outDir, routePath, `index.${extension}`)
}
return joinPaths(outDir, `${routePath}.${extension}`)
}

const parseResponseContent = async (response: Response): Promise<string | ArrayBuffer> => {
Expand Down
2 changes: 2 additions & 0 deletions src/helper/ssg/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ describe('saveContentToFiles function', () => {
htmlMap = new Map([
['/', { content: 'Home Page', mimeType: 'text/html' }],
['/about', { content: 'About Page', mimeType: 'text/html' }],
['/about/', { content: 'About Page', mimeType: 'text/html' }],
])
})

Expand All @@ -205,6 +206,7 @@ describe('saveContentToFiles function', () => {

expect(fsMock.writeFile).toHaveBeenCalledWith('static/index.html', 'Home Page')
expect(fsMock.writeFile).toHaveBeenCalledWith('static/about.html', 'About Page')
expect(fsMock.writeFile).toHaveBeenCalledWith('static/about/index.html', 'About Page')
})

it('should correctly create directories if they do not exist', async () => {
Expand Down
9 changes: 7 additions & 2 deletions src/helper/ssg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ export interface ToSSGResult {

const generateFilePath = (routePath: string, outDir: string, mimeType: string) => {
const extension = determineExtension(mimeType)
const fileName = routePath === '/' ? `index.${extension}` : `${routePath}.${extension}`
return joinPaths(outDir, fileName)
if (routePath === '/') {
return joinPaths(outDir, `index.${extension}`)
}
if (routePath.endsWith('/')) {
return joinPaths(outDir, routePath, `index.${extension}`)
}
return joinPaths(outDir, `${routePath}.${extension}`)
}

const parseResponseContent = async (response: Response): Promise<string | ArrayBuffer> => {
Expand Down