mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-21 21:45:42 -05:00
fix: populate ctx.trie in PageTypeDispatcher before rendering
Components like FolderContent depend on ctx.trie for folder hierarchy. The dispatcher now lazily initializes it via trieFromAllFiles in emit and force-rebuilds it in partialEmit to reflect file changes.
This commit is contained in:
parent
a844133e89
commit
93bd7c5caf
@ -5,7 +5,7 @@ import { FullPageLayout } from "../../cfg"
|
|||||||
import { FullSlug, pathToRoot } from "../../util/path"
|
import { FullSlug, pathToRoot } from "../../util/path"
|
||||||
import { ProcessedContent, defaultProcessedContent } from "../vfile"
|
import { ProcessedContent, defaultProcessedContent } from "../vfile"
|
||||||
import { write } from "../emitters/helpers"
|
import { write } from "../emitters/helpers"
|
||||||
import { BuildCtx } from "../../util/ctx"
|
import { BuildCtx, trieFromAllFiles } from "../../util/ctx"
|
||||||
import { StaticResources } from "../../util/resources"
|
import { StaticResources } from "../../util/resources"
|
||||||
|
|
||||||
function getPageTypes(ctx: BuildCtx): QuartzPageTypePluginInstance[] {
|
function getPageTypes(ctx: BuildCtx): QuartzPageTypePluginInstance[] {
|
||||||
@ -104,6 +104,9 @@ export const PageTypeDispatcher: QuartzEmitterPlugin<Partial<DispatcherOptions>>
|
|||||||
const cfg = ctx.cfg.configuration
|
const cfg = ctx.cfg.configuration
|
||||||
const allFiles = content.map((c) => c[1].data)
|
const allFiles = content.map((c) => c[1].data)
|
||||||
|
|
||||||
|
// Ensure trie is available for components that need folder hierarchy (e.g. FolderContent)
|
||||||
|
ctx.trie ??= trieFromAllFiles(allFiles)
|
||||||
|
|
||||||
for (const [tree, file] of content) {
|
for (const [tree, file] of content) {
|
||||||
const slug = file.data.slug!
|
const slug = file.data.slug!
|
||||||
const fileData = file.data
|
const fileData = file.data
|
||||||
@ -140,6 +143,9 @@ export const PageTypeDispatcher: QuartzEmitterPlugin<Partial<DispatcherOptions>>
|
|||||||
const cfg = ctx.cfg.configuration
|
const cfg = ctx.cfg.configuration
|
||||||
const allFiles = content.map((c) => c[1].data)
|
const allFiles = content.map((c) => c[1].data)
|
||||||
|
|
||||||
|
// Rebuild trie on partial emit to reflect file changes
|
||||||
|
ctx.trie = trieFromAllFiles(allFiles)
|
||||||
|
|
||||||
const changedSlugs = new Set<string>()
|
const changedSlugs = new Set<string>()
|
||||||
for (const changeEvent of changeEvents) {
|
for (const changeEvent of changeEvents) {
|
||||||
if (!changeEvent.file) continue
|
if (!changeEvent.file) continue
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user