refactor(routes): load route templates with fs/promises

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
pull/5342/head
Divyansh Singh 1 month ago
parent cef5a7fc8e
commit a35c9c900a

@ -1,4 +1,5 @@
import fs from 'node:fs' import fs from 'node:fs'
import { readFile } from 'node:fs/promises'
import path from 'node:path' import path from 'node:path'
import c from 'picocolors' import c from 'picocolors'
import pm from 'picomatch' import pm from 'picomatch'
@ -148,7 +149,7 @@ export const dynamicRoutesPlugin = async (
load: { load: {
filter: { id: /\.md$/ }, filter: { id: /\.md$/ },
handler(id) { async handler(id) {
const matched = config.dynamicRoutes.find((r) => r.fullPath === id) const matched = config.dynamicRoutes.find((r) => r.fullPath === id)
if (matched) { if (matched) {
const { route, params, content } = matched const { route, params, content } = matched
@ -157,7 +158,7 @@ export const dynamicRoutesPlugin = async (
moduleGraph.add(id, [routeFile]) moduleGraph.add(id, [routeFile])
moduleGraph.add(routeFile, [matched.loaderPath]) moduleGraph.add(routeFile, [matched.loaderPath])
let baseContent = fs.readFileSync(routeFile, 'utf8') let baseContent = await readFile(routeFile, 'utf8')
// inject raw content // inject raw content
// this is intended for integration with CMS // this is intended for integration with CMS

Loading…
Cancel
Save