Skip to content
Myr

fix(ssg): Fix SSG Extension Map (#4130)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Fix SSG Extension Map Pass the extension map through the generation methods. * Update tests based on feedback * Fix content type

authored by Phips Peter · committed by GitHub · parent ebc7e4b · Browse files · 2 files+16 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−2 removed

  • tests:+13 added−1 removed
  • other:+3 added−1 removed

2 files+16 added−2 removed

modified:src/helper/ssg/ssg.test.tsx+13 added-1 removed
159 unmodified lines
160 expect(result.files).toStrictEqual([])161 })162163 it('Should correctly generate files with the expected paths', async () => {164 app.get('/data', (c) =>165 c.text(JSON.stringify({ title: 'hono' }), 200, {166 'Content-Type': 'text/x-foo',167 })168 )164 await toSSG(app, fsMock, { dir: './static' })169 await toSSG(app, fsMock, {170 dir: './static',171 extensionMap: {172 ...defaultExtensionMap,173 'text/x-foo': 'foo',174 },175 })176177 expect(fsMock.writeFile).toHaveBeenCalledWith('static/index.html', expect.any(String))178 expect(fsMock.writeFile).toHaveBeenCalledWith('static/about.html', expect.any(String))179 expect(fsMock.writeFile).toHaveBeenCalledWith('static/about/some.txt', expect.any(String))
3 unmodified lines
183 )184 expect(fsMock.writeFile).toHaveBeenCalledWith('static/about.html', expect.any(String))185 expect(fsMock.writeFile).toHaveBeenCalledWith('static/bravo.html', expect.any(String))186 expect(fsMock.writeFile).toHaveBeenCalledWith('static/Charlie.html', expect.any(String))187 expect(fsMock.writeFile).toHaveBeenCalledWith('static/data.foo', expect.any(String))188 })189190 it('should modify the request if the hook is provided', async () => {191 const beforeRequestHook: BeforeRequestHook = (req) => {
611 unmodified lines
modified:src/helper/ssg/ssg.ts+3 added-1 removed
358 unmodified lines
359 if (!getContentGen) {360 return361 }362 for (const content of getContentGen) {363 savePromises.push(saveContentToFile(content, fs, outputDir).catch((e) => e))363 savePromises.push(364 saveContentToFile(content, fs, outputDir, options?.extensionMap).catch((e) => e)365 )366 }367 })368 )369 }
21 unmodified lines