mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-21 21:45:42 -05:00
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.
This commit is contained in:
parent
fd36066fdf
commit
17b5c61834
@ -8,6 +8,10 @@ import { write } from "../emitters/helpers"
|
|||||||
import { BuildCtx } from "../../util/ctx"
|
import { BuildCtx } from "../../util/ctx"
|
||||||
import { StaticResources } from "../../util/resources"
|
import { StaticResources } from "../../util/resources"
|
||||||
|
|
||||||
|
function getPageTypes(ctx: BuildCtx): QuartzPageTypePluginInstance[] {
|
||||||
|
return (ctx.cfg.plugins.pageTypes ?? []) as unknown as QuartzPageTypePluginInstance[]
|
||||||
|
}
|
||||||
|
|
||||||
function resolveLayout(
|
function resolveLayout(
|
||||||
pageType: QuartzPageTypePluginInstance,
|
pageType: QuartzPageTypePluginInstance,
|
||||||
sharedDefaults: Partial<FullPageLayout>,
|
sharedDefaults: Partial<FullPageLayout>,
|
||||||
@ -92,13 +96,11 @@ export const PageTypeDispatcher: QuartzEmitterPlugin<Partial<DispatcherOptions>>
|
|||||||
return {
|
return {
|
||||||
name: "PageTypeDispatcher",
|
name: "PageTypeDispatcher",
|
||||||
getQuartzComponents(ctx) {
|
getQuartzComponents(ctx) {
|
||||||
const pageTypes = ctx.cfg.plugins.pageTypes ?? []
|
const pageTypes = getPageTypes(ctx)
|
||||||
return collectComponents(pageTypes, defaults, byPageType)
|
return collectComponents(pageTypes, defaults, byPageType)
|
||||||
},
|
},
|
||||||
async *emit(ctx, content, resources) {
|
async *emit(ctx, content, resources) {
|
||||||
const pageTypes = [...(ctx.cfg.plugins.pageTypes ?? [])].sort(
|
const pageTypes = [...getPageTypes(ctx)].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0))
|
||||||
(a, b) => (b.priority ?? 0) - (a.priority ?? 0),
|
|
||||||
)
|
|
||||||
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)
|
||||||
|
|
||||||
@ -122,20 +124,19 @@ export const PageTypeDispatcher: QuartzEmitterPlugin<Partial<DispatcherOptions>>
|
|||||||
const layout = resolveLayout(pt, defaults, byPageType)
|
const layout = resolveLayout(pt, defaults, byPageType)
|
||||||
|
|
||||||
for (const vp of virtualPages) {
|
for (const vp of virtualPages) {
|
||||||
|
const vpSlug = vp.slug as FullSlug
|
||||||
const [tree, vfile] = defaultProcessedContent({
|
const [tree, vfile] = defaultProcessedContent({
|
||||||
slug: vp.slug,
|
slug: vpSlug,
|
||||||
frontmatter: { title: vp.title, tags: [] },
|
frontmatter: { title: vp.title, tags: [] },
|
||||||
...vp.data,
|
...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) {
|
async *partialEmit(ctx, content, resources, changeEvents) {
|
||||||
const pageTypes = [...(ctx.cfg.plugins.pageTypes ?? [])].sort(
|
const pageTypes = [...getPageTypes(ctx)].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0))
|
||||||
(a, b) => (b.priority ?? 0) - (a.priority ?? 0),
|
|
||||||
)
|
|
||||||
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)
|
||||||
|
|
||||||
@ -168,13 +169,14 @@ export const PageTypeDispatcher: QuartzEmitterPlugin<Partial<DispatcherOptions>>
|
|||||||
const layout = resolveLayout(pt, defaults, byPageType)
|
const layout = resolveLayout(pt, defaults, byPageType)
|
||||||
|
|
||||||
for (const vp of virtualPages) {
|
for (const vp of virtualPages) {
|
||||||
|
const vpSlug = vp.slug as FullSlug
|
||||||
const [tree, vfile] = defaultProcessedContent({
|
const [tree, vfile] = defaultProcessedContent({
|
||||||
slug: vp.slug,
|
slug: vpSlug,
|
||||||
frontmatter: { title: vp.title, tags: [] },
|
frontmatter: { title: vp.title, tags: [] },
|
||||||
...vp.data,
|
...vp.data,
|
||||||
})
|
})
|
||||||
|
|
||||||
yield emitPage(ctx, vp.slug, tree, vfile.data, allFiles, layout, resources)
|
yield emitPage(ctx, vpSlug, tree, vfile.data, allFiles, layout, resources)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user