Skip to content

Commit

Permalink
fix(nuxt): allow scanning metadata from multiple files with same route
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Nov 19, 2024
1 parent 02b57d4 commit 87ed7d6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/nuxt/src/pages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export async function resolvePagesRoutes (): Promise<NuxtPage[]> {
} else {
const augmentedPages = await augmentPages(pages, nuxt.vfs)
await nuxt.callHook('pages:extend', pages)
await augmentPages(pages, nuxt.vfs, augmentedPages)
augmentedPages.clear()
await augmentPages(pages, nuxt.vfs, { pagesToSkip: augmentedPages })
augmentedPages?.clear()
}

await nuxt.callHook('pages:resolved', pages)
Expand Down Expand Up @@ -155,24 +155,28 @@ export function generateRoutesFromFiles (files: ScannedFile[], options: Generate
return prepareRoutes(routes)
}

export async function augmentPages (routes: NuxtPage[], vfs: Record<string, string>, augmentedPages = new Set<string>()) {
interface AugmentPagesContext {
pagesToSkip?: Set<string>
augmentedPages?: Set<string>
}
export async function augmentPages (routes: NuxtPage[], vfs: Record<string, string>, ctx: AugmentPagesContext = {}) {
for (const route of routes) {
if (route.file && !augmentedPages.has(route.file)) {
if (route.file && !ctx.pagesToSkip?.has(route.file)) {
const fileContent = route.file in vfs ? vfs[route.file]! : fs.readFileSync(await resolvePath(route.file), 'utf-8')
const routeMeta = await getRouteMeta(fileContent, route.file)
if (route.meta) {
routeMeta.meta = { ...routeMeta.meta, ...route.meta }
}

Object.assign(route, routeMeta)
augmentedPages.add(route.file)
ctx.augmentedPages?.add(route.file)
}

if (route.children && route.children.length > 0) {
await augmentPages(route.children, vfs, augmentedPages)
await augmentPages(route.children, vfs, ctx)
}
}
return augmentedPages
return ctx.augmentedPages
}

const SFC_SCRIPT_RE = /<script(?<attrs>[^>]*)>(?<content>[\s\S]*?)<\/script[^>]*>/gi
Expand Down

0 comments on commit 87ed7d6

Please sign in to comment.