fix(order): before/after naming crawl-links, remove-draft or content-index mean the built-in

This commit is contained in:
saberzero1 committed 2026-11-26 22:39:04 +01:00
1 parent 9de19e3027
commit bc0e3937c3
5 files changed
+52 -7

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
Plugin order: `before:` / `after:` naming a plugin that is built into Quartz now (`crawl-links`, `remove-draft`, `content-index`) passed validation but was ignored. They now mean the built-in that replaced them (`links`, `drafts`, `contentIndex`), so `before: crawl-links` orders the plugin before link processing, and is checked against its `order` like `before: links`.
+1 -1
View File
@@ -171,7 +171,7 @@ plugins:
Plugins are categorized by their type (transformer, filter, emitter, pageType) based on their manifest. The `order` field controls execution order within each category.
`before` and `after` name plugins that this one must run before or after (one name or a list; `obsidian-flavored-markdown`, `ObsidianFlavoredMarkdown` and `@quartz-community/obsidian-flavored-markdown` all work, as do the built-ins `frontmatter`, `links`, `drafts` and `contentIndex`). They never override `order`; they are checked against it:
`before` and `after` name plugins that this one must run before or after (one name or a list; `obsidian-flavored-markdown`, `ObsidianFlavoredMarkdown` and `@quartz-community/obsidian-flavored-markdown` all work, as do the built-ins `frontmatter`, `links`, `drafts` and `contentIndex`; the names of the plugins they replaced, `crawl-links`, `remove-draft` and `content-index`, mean those built-ins). They never override `order`; they are checked against it:
```yaml title="quartz.config.yaml"
plugins:
+34
View File
@@ -7,6 +7,7 @@ import { VFile } from "vfile"
import { Element, Root, Text } from "hast"
import { visit } from "unist-util-visit"
import { BUILTINS, instantiateBuiltins, officialPluginName, planBuiltins, PlanInput } from "."
import { normalizePluginName, orderPlugins } from "../loader/plugin-order"
import {
Frontmatter,
normalizeFrontmatter,
@@ -181,6 +182,39 @@ describe("planBuiltins", () => {
})
})
describe("plugin order constraints naming a replaced plugin", () => {
test("after: crawl-links / before: remove-draft order against the built-in", () => {
const transformers = instantiateBuiltins(plan([]), "transformer")
const links = transformers.find((b) => b.instance.name === "Links")!
assert.ok(links.names.includes("crawl-links"))
const known = new Set(
[...transformers.flatMap((b) => b.names), "my-plugin"].map(normalizePluginName),
)
// same order as Links (60): without the mapping the constraint was ignored and the list
// order (built-ins first) put Links first anyway, so run it before
const mine = {
order: 60,
instance: { name: "Mine" },
label: "my-plugin",
names: ["my-plugin"],
before: ["crawl-links"],
}
const ordered = orderPlugins(
[
...transformers.map((b) => ({
order: b.order,
instance: b.instance as { name: string },
label: b.instance.name,
names: b.names,
})),
mine,
],
known,
).map((i) => i.name)
assert.ok(ordered.indexOf("Mine") < ordered.indexOf("Links"), ordered.join(", "))
})
})
describe("frontmatter built-in", () => {
const ctx = () => ({ allSlugs: [] as FullSlug[] }) as unknown as BuildCtx
+8 -2
View File
@@ -303,7 +303,7 @@ export function planBuiltins(input: PlanInput): BuiltinPlan {
export function instantiateBuiltins<C extends BuiltinCategory>(
plan: BuiltinPlan,
category: C,
): { order: number; instance: BuiltinInstance }[] {
): { order: number; instance: BuiltinInstance; names: string[] }[] {
return (
plan.builtins
.filter((b) => b.enabled && b.spec.category === category)
@@ -318,7 +318,13 @@ export function instantiateBuiltins<C extends BuiltinCategory>(
category: b.spec.category,
builtin: true,
})
return { order: b.order, instance }
// `before`/`after` may name the built-in by its config key or by the plugin it
// replaced (`after: crawl-links` is `after: links`)
return {
order: b.order,
instance,
names: [instance.name, b.spec.configKey, ...b.spec.absorbs],
}
})
)
}
+4 -4
View File
@@ -758,7 +758,7 @@ export async function loadQuartzConfig(
const knownPluginNames = new Set(
[
...json.plugins.map((e) => extractPluginName(e.source)),
...builtinPlan.builtins.map((b) => b.spec.configKey),
...builtinPlan.builtins.flatMap((b) => [b.spec.configKey, ...b.spec.absorbs]),
"Frontmatter",
"Links",
"Drafts",
@@ -767,14 +767,14 @@ export async function loadQuartzConfig(
].map(normalizePluginName),
)
const withBuiltins = <T>(
builtins: { order: number; instance: unknown }[],
builtins: { order: number; instance: unknown; names?: string[] }[],
instances: OrderItem<T>[],
): T[] =>
orderPlugins(
[
...builtins.map(({ order, instance }) => {
...builtins.map(({ order, instance, names }) => {
const name = (instance as { name: string }).name
return { order, instance: instance as T, label: name, names: [name] }
return { order, instance: instance as T, label: name, names: names ?? [name] }
}),
...instances,
],