fix(ssg): path of already extention (#2236)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* fix(ssg): path of already extention * adding test
authored by watany · committed by GitHub · parent 1dd07d0 · Browse files · 3 files·+23 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+23 added−0 removed
- tests:+13 added−0 removed
- other:+10 added−0 removed
Provenance
- Commit
d67babf- Tree
6507c36- Author
watany <76135106+watany-dev@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
1dd07d0
3 files changed+23 added−0 removed
modified:deno_dist/helper/ssg/index.ts+5 added
29 unmodified lines30 error?: Error31 }32 33 const generateFilePath = (routePath: string, outDir: string, mimeType: string) => {34+ const hasExtension = /\.[^\/]+$/.test(routePath)35+ if (hasExtension) {36+ return joinPaths(outDir, routePath)37+ }38+39 const extension = determineExtension(mimeType)40 if (routePath === '/') {41 return joinPaths(outDir, `index.${extension}`)42 }256 unmodified linesmodified:src/helper/ssg/index.test.tsx+13 added
293 unmodified lines294 htmlMap = new Map([295 ['/', { content: 'Home Page', mimeType: 'text/html' }],296 ['/about', { content: 'About Page', mimeType: 'text/html' }],297 ['/about/', { content: 'About Page', mimeType: 'text/html' }],298+ ['/bravo/index.html', { content: 'About Page', mimeType: 'text/html' }],299+ ['/bravo/index.tar.gz', { content: 'About Page', mimeType: 'application/gzip' }],300+ ['/bravo.text/index.html', { content: 'About Page', mimeType: 'text/html' }],301+ ['/bravo.text/', { content: 'Bravo Page', mimeType: 'text/html' }],302 ])303 })304 305 it('should correctly create files with the right content and paths', async () => {1 unmodified line307 308 expect(fsMock.writeFile).toHaveBeenCalledWith('static/index.html', 'Home Page')309 expect(fsMock.writeFile).toHaveBeenCalledWith('static/about.html', 'About Page')310 expect(fsMock.writeFile).toHaveBeenCalledWith('static/about/index.html', 'About Page')311+ expect(fsMock.writeFile).toHaveBeenCalledWith('static/bravo/index.html', 'About Page')312+ expect(fsMock.writeFile).toHaveBeenCalledWith('static/bravo/index.tar.gz', 'About Page')313+ expect(fsMock.writeFile).toHaveBeenCalledWith('static/bravo.text/index.html', 'About Page')314+ expect(fsMock.writeFile).toHaveBeenCalledWith('static/bravo.text/index.html', 'Bravo Page')315 })316 317 it('should correctly create directories if they do not exist', async () => {318 await saveContentToFiles(htmlMap, fsMock, './static')10 unmodified lines329 await expect(saveContentToFiles(htmlMap, fsMock, './static')).rejects.toThrow(330 'File write error'331 )332 })333+ it('check extensions', async () => {334+ await saveContentToFiles(htmlMap, fsMock, './static')335+336+ expect(fsMock.mkdir).toHaveBeenCalledWith('static', { recursive: true })337+ })338 })339 340 describe('Dynamic route handling', () => {341 let app: Hono67 unmodified linesmodified:src/helper/ssg/index.ts+5 added
29 unmodified lines30 error?: Error31 }32 33 const generateFilePath = (routePath: string, outDir: string, mimeType: string) => {34+ const hasExtension = /\.[^\/]+$/.test(routePath)35+ if (hasExtension) {36+ return joinPaths(outDir, routePath)37+ }38+39 const extension = determineExtension(mimeType)40 if (routePath === '/') {41 return joinPaths(outDir, `index.${extension}`)42 }256 unmodified lines