Repository: honojs/hono
File: deno_dist/helper/ssg/index.ts (TypeScript)

Code before:
}

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

const parseResponseContent = async (response: Response): Promise<string | ArrayBuffer> => {
  const contentType = response.headers.get('Content-Type')

  try {
    if (contentType?.includes('text')) {
      return await response.text()
    } else if (contentType?.includes('json')) {
      return JSON.stringify(await response.json())
    } else {
      return await response.arrayBuffer()
    }
  } catch (error) {
    throw new Error(
      `Error processing response: ${error instanceof Error ? error.message : 'Unknown error'}`
    )
  }
}

const determineExtension = (mimeType: string): string => {
  switch (mimeType) {
    case 'text/html':
      return '.html'
    case 'text/xml':
    case 'application/xml':
      return '.xml'
    default:
      return '.html'
  }
}

/**
 * @experimental
 * `fetchRoutesContent` is an experimental feature.
 * The API might be changed.
 */
export const fetchRoutesContent = async <
  E extends Env = Env,
  S extends Schema = {},
  BasePath extends string = '/'
>(
  app: Hono<E, S, BasePath>
): Promise<Map<string, { content: string | ArrayBuffer; mimeType: string }>> => {
  const htmlMap = new Map<string, { content: string | ArrayBuffer; mimeType: string }>()

Review comment (refactor):
How about using the `utils/mime.ts`?

```diff
diff --git a/src/helper/ssg/index.ts b/src/helper/ssg/index.ts
index 125f2cd..c7f4dc2 100644
--- a/src/helper/ssg/index.ts
+++ b/src/helper/ssg/index.ts
@@ -1,6 +1,7 @@
 import { inspectRoutes } from '../../helper/dev'
 import type { Hono } from '../../hono'
 import type { Env, Schema } from '../../types'
+import { getExtension } from '../../utils/mime'
 import { joinPaths, dirname } from './utils'

 /**
@@ -49,6 +50,8 @@ const parseResponseContent = async (response: Response): Promise<string | ArrayB
 }

 const determineExtension = (mimeType: string): string => {
+  const extension = getExtension(mimeType)
+  if (extension) return extension
   switch (mimeType) {
     case 'text/html':
       return '.html'
diff --git a/src/utils/mime.ts b/src/utils/mime.ts
index 5b55663..807cec9 100644
--- a/src/utils/mime.ts
+++ b/src/utils/mime.ts
@@ -9,6 +9,12 @@ export const getMimeType = (filename: string): string | undefined => {
   return mimeType
 }

+export const getExtension = (mimeType: string): string | undefined => {
+  const extensions = Object.keys(mimes)
+  const extension = extensions.find((ext) => mimes[ext] === mimeType)
+  return extension
+}
+
 const mimes: Record<string, string> = {
   aac: 'audio/aac',
   abw: 'application/x-abiword',
```

Code after:
  error?: Error
}

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

const parseResponseContent = async (response: Response): Promise<string | ArrayBuffer> => {
  const contentType = response.headers.get('Content-Type')

  try {
    if (contentType?.includes('text') || contentType?.includes('json')) {
      return await response.text()
    } else {
      return await response.arrayBuffer()
    }
  } catch (error) {
    throw new Error(
      `Error processing response: ${error instanceof Error ? error.message : 'Unknown error'}`
    )
  }
}

const determineExtension = (mimeType: string): string => {
  switch (mimeType) {
    case 'text/html':
      return '.html'
    case 'text/xml':
    case 'application/xml':
      return '.xml'
    default: {
      const extension = getExtension(mimeType)
      return extension || '.html'
    }
  }
}

/**
 * @experimental
 * `fetchRoutesContent` is an experimental feature.
 * The API might be changed.
 */
export const fetchRoutesContent = async <
  E extends Env = Env,
  S extends Schema = {},
  BasePath extends string = '/'
>(
  app: Hono<E, S, BasePath>
): Promise<Map<string, { content: string | ArrayBuffer; mimeType: string }>> => {