From 17b5c618347839d1b86776ff070ed10f0372241f Mon Sep 17 00:00:00 2001 From: saberzero1 Date: Fri, 13 Feb 2026 19:35:03 +0100 Subject: [PATCH] refactor: update dispatcher to cast PageTypePluginEntry at boundary Add getPageTypes() helper that casts config's PageTypePluginEntry[] to QuartzPageTypePluginInstance[] in one place. Cast VirtualPage.slug to FullSlug at emitPage/defaultProcessedContent call sites. --- quartz/plugins/pageTypes/dispatcher.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/quartz/plugins/pageTypes/dispatcher.ts b/quartz/plugins/pageTypes/dispatcher.ts index 5a89cf00f..5c5fa75bc 100644 --- a/quartz/plugins/pageTypes/dispatcher.ts +++ b/quartz/plugins/pageTypes/dispatcher.ts @@ -8,6 +8,10 @@ import { write } from "../emitters/helpers" import { BuildCtx } from "../../util/ctx" import { StaticResources } from "../../util/resources" +function getPageTypes(ctx: BuildCtx): QuartzPageTypePluginInstance[] { + return (ctx.cfg.plugins.pageTypes ?? []) as unknown as QuartzPageTypePluginInstance[] +} + function resolveLayout( pageType: QuartzPageTypePluginInstance, sharedDefaults: Partial, @@ -92,13 +96,11 @@ export const PageTypeDispatcher: QuartzEmitterPlugin> return { name: "PageTypeDispatcher", getQuartzComponents(ctx) { - const pageTypes = ctx.cfg.plugins.pageTypes ?? [] + const pageTypes = getPageTypes(ctx) return collectComponents(pageTypes, defaults, byPageType) }, async *emit(ctx, content, resources) { - const pageTypes = [...(ctx.cfg.plugins.pageTypes ?? [])].sort( - (a, b) => (b.priority ?? 0) - (a.priority ?? 0), - ) + const pageTypes = [...getPageTypes(ctx)].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0)) const cfg = ctx.cfg.configuration const allFiles = content.map((c) => c[1].data) @@ -122,20 +124,19 @@ export const PageTypeDispatcher: QuartzEmitterPlugin> const layout = resolveLayout(pt, defaults, byPageType) for (const vp of virtualPages) { + const vpSlug = vp.slug as FullSlug const [tree, vfile] = defaultProcessedContent({ - slug: vp.slug, + slug: vpSlug, frontmatter: { title: vp.title, tags: [] }, ...vp.data, }) - yield emitPage(ctx, vp.slug, tree, vfile.data, allFiles, layout, resources) + yield emitPage(ctx, vpSlug, tree, vfile.data, allFiles, layout, resources) } } }, async *partialEmit(ctx, content, resources, changeEvents) { - const pageTypes = [...(ctx.cfg.plugins.pageTypes ?? [])].sort( - (a, b) => (b.priority ?? 0) - (a.priority ?? 0), - ) + const pageTypes = [...getPageTypes(ctx)].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0)) const cfg = ctx.cfg.configuration const allFiles = content.map((c) => c[1].data) @@ -168,13 +169,14 @@ export const PageTypeDispatcher: QuartzEmitterPlugin> const layout = resolveLayout(pt, defaults, byPageType) for (const vp of virtualPages) { + const vpSlug = vp.slug as FullSlug const [tree, vfile] = defaultProcessedContent({ - slug: vp.slug, + slug: vpSlug, frontmatter: { title: vp.title, tags: [] }, ...vp.data, }) - yield emitPage(ctx, vp.slug, tree, vfile.data, allFiles, layout, resources) + yield emitPage(ctx, vpSlug, tree, vfile.data, allFiles, layout, resources) } } },