Skip to content
Myr

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

3 files+23 added−0 removed

modified:deno_dist/helper/ssg/index.ts+5 added
29 unmodified lines
30 error?: Error31}3233const generateFilePath = (routePath: string, outDir: string, mimeType: string) => {34 const hasExtension = /\.[^\/]+$/.test(routePath)35 if (hasExtension) {36 return joinPaths(outDir, routePath)37 }3839 const extension = determineExtension(mimeType)40 if (routePath === '/') {41 return joinPaths(outDir, `index.${extension}`)42 }
256 unmodified lines
modified:src/helper/ssg/index.test.tsx+13 added
293 unmodified lines
294 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 })304305 it('should correctly create files with the right content and paths', async () => {
1 unmodified line
307308 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 })316317 it('should correctly create directories if they do not exist', async () => {318 await saveContentToFiles(htmlMap, fsMock, './static')
10 unmodified lines
329 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')335336 expect(fsMock.mkdir).toHaveBeenCalledWith('static', { recursive: true })337 })338})339340describe('Dynamic route handling', () => {341 let app: Hono
67 unmodified lines
modified:src/helper/ssg/index.ts+5 added
29 unmodified lines
30 error?: Error31}3233const generateFilePath = (routePath: string, outDir: string, mimeType: string) => {34 const hasExtension = /\.[^\/]+$/.test(routePath)35 if (hasExtension) {36 return joinPaths(outDir, routePath)37 }3839 const extension = determineExtension(mimeType)40 if (routePath === '/') {41 return joinPaths(outDir, `index.${extension}`)42 }
256 unmodified lines