mirror of
https://github.com/mmahdium/portfolio.git
synced 2025-12-20 09:23:54 +01:00
fix(prerender): Optimize blog route prerendering for multilingual support
- Modify content file parsing hook to handle both English and Persian blog routes - Remove English locale prefix for default language routes - Preserve Persian locale prefix for localized routes - Add type assertions to resolve TypeScript hook typing issues - Improve logging for prerendered blog routes
This commit is contained in:
@@ -5,16 +5,22 @@ export default defineNitroPlugin(async (nitroApp) => {
|
|||||||
|
|
||||||
const routes: string[] = []
|
const routes: string[] = []
|
||||||
|
|
||||||
nitroApp.hooks.hook('content:file:afterParse', (file) => {
|
nitroApp.hooks.hook('content:file:afterParse' as any, (file: any) => {
|
||||||
// Collect blog post routes for prerendering
|
// Collect blog post routes for prerendering
|
||||||
if (file._path && !file.draft) {
|
if (file._path && !file.draft) {
|
||||||
if (file._path.startsWith('/en/blog/') || file._path.startsWith('/fa/blog/')) {
|
// English routes: /en/blog/post -> /blog/post (no prefix for default locale)
|
||||||
|
if (file._path.startsWith('/en/blog/')) {
|
||||||
|
const routeWithoutPrefix = file._path.replace('/en', '')
|
||||||
|
routes.push(routeWithoutPrefix)
|
||||||
|
}
|
||||||
|
// Persian routes: /fa/blog/post -> /fa/blog/post (keep prefix)
|
||||||
|
else if (file._path.startsWith('/fa/blog/')) {
|
||||||
routes.push(file._path)
|
routes.push(file._path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
nitroApp.hooks.hook('prerender:generate', async () => {
|
nitroApp.hooks.hook('prerender:generate' as any, async () => {
|
||||||
for (const route of routes) {
|
for (const route of routes) {
|
||||||
console.log(`Prerendering blog route: ${route}`)
|
console.log(`Prerendering blog route: ${route}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user