@plumix/core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/debug-bar/panels/template.d.ts +5 -8
- package/dist/debug-bar/panels/template.d.ts.map +1 -1
- package/dist/debug-bar/panels/template.js +22 -8
- package/dist/debug-bar/panels/template.js.map +1 -1
- package/dist/debug-bar/primitives.d.ts +1 -1
- package/dist/debug-bar/primitives.d.ts.map +1 -1
- package/dist/debug-bar/primitives.js +1 -1
- package/dist/debug-bar/primitives.js.map +1 -1
- package/dist/debug-bar/styles.d.ts.map +1 -1
- package/dist/debug-bar/styles.js +9 -14
- package/dist/debug-bar/styles.js.map +1 -1
- package/dist/debug-bar/template-node-label.d.ts.map +1 -1
- package/dist/debug-bar/template-node-label.js +0 -2
- package/dist/debug-bar/template-node-label.js.map +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/route/render/render-template.d.ts +6 -4
- package/dist/route/render/render-template.d.ts.map +1 -1
- package/dist/route/render/render-template.js +36 -48
- package/dist/route/render/render-template.js.map +1 -1
- package/dist/route/render/resolved-entry.d.ts +10 -5
- package/dist/route/render/resolved-entry.d.ts.map +1 -1
- package/dist/route/render/template-builders.d.ts +72 -0
- package/dist/route/render/template-builders.d.ts.map +1 -0
- package/dist/route/render/template-builders.js +113 -0
- package/dist/route/render/template-builders.js.map +1 -0
- package/dist/route/render/template-hierarchy.d.ts +53 -38
- package/dist/route/render/template-hierarchy.d.ts.map +1 -1
- package/dist/route/render/template-hierarchy.js +127 -74
- package/dist/route/render/template-hierarchy.js.map +1 -1
- package/dist/route/resolve.d.ts +3 -3
- package/dist/route/resolve.d.ts.map +1 -1
- package/dist/route/resolve.js +30 -32
- package/dist/route/resolve.js.map +1 -1
- package/dist/runtime/app.d.ts +0 -8
- package/dist/runtime/app.d.ts.map +1 -1
- package/dist/runtime/app.js +0 -38
- package/dist/runtime/app.js.map +1 -1
- package/dist/runtime/dispatcher.d.ts.map +1 -1
- package/dist/runtime/dispatcher.js +4 -7
- package/dist/runtime/dispatcher.js.map +1 -1
- package/dist/template-deps.js +1 -1
- package/dist/template-registry.d.ts +57 -0
- package/dist/template-registry.d.ts.map +1 -0
- package/dist/template-registry.js +1 -0
- package/dist/template-registry.js.map +1 -0
- package/dist/template.d.ts +2 -2
- package/dist/test/default-theme.d.ts.map +1 -1
- package/dist/test/default-theme.js +7 -6
- package/dist/test/default-theme.js.map +1 -1
- package/dist/theme-errors.d.ts +0 -3
- package/dist/theme-errors.d.ts.map +1 -1
- package/dist/theme-errors.js +7 -18
- package/dist/theme-errors.js.map +1 -1
- package/dist/theme.d.ts +59 -23
- package/dist/theme.d.ts.map +1 -1
- package/dist/theme.js +21 -10
- package/dist/theme.js.map +1 -1
- package/dist/welcome-theme.d.ts +2 -2
- package/dist/welcome-theme.d.ts.map +1 -1
- package/dist/welcome-theme.js +7 -6
- package/dist/welcome-theme.js.map +1 -1
- package/package.json +7 -7
- package/dist/route/render/archive-props.d.ts +0 -39
- package/dist/route/render/archive-props.d.ts.map +0 -1
- package/dist/route/render/archive-props.js +0 -32
- package/dist/route/render/archive-props.js.map +0 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { EntryProjection, EntryTypeName, MetaOf, TermProjection, TermTaxonomyName } from "../../template-registry.js";
|
|
2
|
+
import type { TemplateData, TemplateEntry, TemplateRule, ThemeDescriptor } from "../../theme.js";
|
|
3
|
+
import type { ArchiveData, EntryData, ErrorData, FrontPageData, SearchData, TaxonomyData } from "./resolved-entry.js";
|
|
4
|
+
/** Universal catch-all — matches any resolved node. */
|
|
5
|
+
export declare function fallback(template: TemplateEntry<TemplateData>): TemplateRule;
|
|
6
|
+
/** A single entry (any type). */
|
|
7
|
+
export declare function entry(template: TemplateEntry<EntryData>): TemplateRule;
|
|
8
|
+
/** A content-type archive listing. */
|
|
9
|
+
export declare function archive(template: TemplateEntry<ArchiveData>): TemplateRule;
|
|
10
|
+
/** A term archive (any taxonomy). */
|
|
11
|
+
export declare function taxonomy(template: TemplateEntry<TaxonomyData>): TemplateRule;
|
|
12
|
+
/** The static front page. */
|
|
13
|
+
export declare function frontPage(template: TemplateEntry<FrontPageData>): TemplateRule;
|
|
14
|
+
/** Search results. */
|
|
15
|
+
export declare function search(template: TemplateEntry<SearchData>): TemplateRule;
|
|
16
|
+
/** The 404 handler. */
|
|
17
|
+
export declare function notFound(template: TemplateEntry<ErrorData>): TemplateRule;
|
|
18
|
+
/** The 500 handler. */
|
|
19
|
+
export declare function serverError(template: TemplateEntry<ErrorData>): TemplateRule;
|
|
20
|
+
/**
|
|
21
|
+
* Normalize a theme's `templates` to a rule array — the array form as-is, or a
|
|
22
|
+
* bare component wrapped as the fallback tier.
|
|
23
|
+
*/
|
|
24
|
+
export declare function templateRules(templates: ThemeDescriptor["templates"]): readonly TemplateRule[];
|
|
25
|
+
/**
|
|
26
|
+
* Reserved entry-meta key holding an author's `named`-template choice — the
|
|
27
|
+
* editor writes it, the resolver reads it. Part of the `__plumix_*` namespace.
|
|
28
|
+
*/
|
|
29
|
+
export declare const NAMED_TEMPLATE_META_KEY = "__plumix_template";
|
|
30
|
+
interface EntrySelector<K extends EntryTypeName> {
|
|
31
|
+
/** Bind the template for the selected entry. */
|
|
32
|
+
template(t: TemplateEntry<EntryData<EntryProjection<K>>>): TemplateRule;
|
|
33
|
+
}
|
|
34
|
+
interface EntryTypeBuilder<K extends EntryTypeName> extends EntrySelector<K> {
|
|
35
|
+
/** Narrow to one entry by slug. */
|
|
36
|
+
slug(slug: string): EntrySelector<K>;
|
|
37
|
+
/** Narrow to one entry by numeric id. */
|
|
38
|
+
id(id: number): EntrySelector<K>;
|
|
39
|
+
/** Narrow by an entry-meta value, typed against the type's meta projection. */
|
|
40
|
+
whereMeta<M extends keyof MetaOf<K>>(key: M, value: MetaOf<K>[M]): EntrySelector<K>;
|
|
41
|
+
/** Narrow by an arbitrary predicate over the resolved data. */
|
|
42
|
+
where(predicate: (data: EntryData<EntryProjection<K>>) => boolean): EntrySelector<K>;
|
|
43
|
+
/** Register an author-selectable template, matched from stored entry meta. */
|
|
44
|
+
named(id: string, label: string): EntrySelector<K>;
|
|
45
|
+
/** The content-type archive listing. */
|
|
46
|
+
readonly archive: {
|
|
47
|
+
template(t: TemplateEntry<ArchiveData<EntryProjection<K>>>): TemplateRule;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Target a registered entry type. `name` autocompletes and rejects typos
|
|
52
|
+
* (`keyof EntryTypeRegistry`); the template's `data.entry` is typed from the
|
|
53
|
+
* type's projection.
|
|
54
|
+
*/
|
|
55
|
+
export declare function forEntryType<K extends EntryTypeName>(name: K): EntryTypeBuilder<K>;
|
|
56
|
+
interface TaxonomySelector<K extends TermTaxonomyName> {
|
|
57
|
+
/** Bind the template for the selected term(s). */
|
|
58
|
+
template(t: TemplateEntry<TaxonomyData<TermProjection<K>>>): TemplateRule;
|
|
59
|
+
}
|
|
60
|
+
interface TermTaxonomyBuilder<K extends TermTaxonomyName> extends TaxonomySelector<K> {
|
|
61
|
+
/** Narrow to one term by slug. */
|
|
62
|
+
slug(slug: string): TaxonomySelector<K>;
|
|
63
|
+
/** Narrow to one term by numeric id. */
|
|
64
|
+
id(id: number): TaxonomySelector<K>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Target a registered taxonomy. `name` autocompletes and rejects typos; the
|
|
68
|
+
* template's `data.term` is typed from the taxonomy's term projection.
|
|
69
|
+
*/
|
|
70
|
+
export declare function forTermTaxonomy<K extends TermTaxonomyName>(name: K): TermTaxonomyBuilder<K>;
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=template-builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-builders.d.ts","sourceRoot":"","sources":["../../../src/route/render/template-builders.ts"],"names":[],"mappings":"AA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B;IACnD,kDAAkD;IAClD,QAAQ,CAAC,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;CAC3E;AAED,UAAU,mBAAmB,CAC3B,CAAC,SAAS,gBAAgB,CAC1B,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IAC3B,kCAAkC;IAClC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IACxC,wCAAwC;IACxC,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;CACrC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,gBAAgB,EACxD,IAAI,EAAE,CAAC,GACN,mBAAmB,CAAC,CAAC,CAAC,CAUxB"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// The per-tier data type is erased to the union in the stored rule. Each
|
|
2
|
+
// builder types its input to the tier's data shape (so `data.entry`/`data.term`
|
|
3
|
+
// are typed at the call site), then erases on output — the resolver only ever
|
|
4
|
+
// invokes a rule's template with the matching node's data, so the erasure is
|
|
5
|
+
// sound and it keeps the `templates` array a homogeneous element type.
|
|
6
|
+
function rule(tier, template) {
|
|
7
|
+
return { tier, template: template };
|
|
8
|
+
}
|
|
9
|
+
/** Universal catch-all — matches any resolved node. */
|
|
10
|
+
export function fallback(template) {
|
|
11
|
+
return rule("fallback", template);
|
|
12
|
+
}
|
|
13
|
+
/** A single entry (any type). */
|
|
14
|
+
export function entry(template) {
|
|
15
|
+
return rule("entry", template);
|
|
16
|
+
}
|
|
17
|
+
/** A content-type archive listing. */
|
|
18
|
+
export function archive(template) {
|
|
19
|
+
return rule("archive", template);
|
|
20
|
+
}
|
|
21
|
+
/** A term archive (any taxonomy). */
|
|
22
|
+
export function taxonomy(template) {
|
|
23
|
+
return rule("taxonomy", template);
|
|
24
|
+
}
|
|
25
|
+
/** The static front page. */
|
|
26
|
+
export function frontPage(template) {
|
|
27
|
+
return rule("frontPage", template);
|
|
28
|
+
}
|
|
29
|
+
/** Search results. */
|
|
30
|
+
export function search(template) {
|
|
31
|
+
return rule("search", template);
|
|
32
|
+
}
|
|
33
|
+
/** The 404 handler. */
|
|
34
|
+
export function notFound(template) {
|
|
35
|
+
return rule("notFound", template);
|
|
36
|
+
}
|
|
37
|
+
/** The 500 handler. */
|
|
38
|
+
export function serverError(template) {
|
|
39
|
+
return rule("serverError", template);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Normalize a theme's `templates` to a rule array — the array form as-is, or a
|
|
43
|
+
* bare component wrapped as the fallback tier.
|
|
44
|
+
*/
|
|
45
|
+
export function templateRules(templates) {
|
|
46
|
+
// `Array.isArray` widens a `readonly T[]` to `any[]`, so re-assert the element
|
|
47
|
+
// type on the array branch rather than leaning on the narrowing.
|
|
48
|
+
return Array.isArray(templates)
|
|
49
|
+
? templates
|
|
50
|
+
: [fallback(templates)];
|
|
51
|
+
}
|
|
52
|
+
// ── Targeted builders ───────────────────────────────────────────────────────
|
|
53
|
+
// `forEntryType`/`forTermTaxonomy` produce match rules keyed off the registered
|
|
54
|
+
// names. Each selector types the template to the tier's data shape (with the
|
|
55
|
+
// registry projection) and erases to the union like the generic builders above.
|
|
56
|
+
function matchRule(match, template) {
|
|
57
|
+
return {
|
|
58
|
+
match,
|
|
59
|
+
template: template,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Reserved entry-meta key holding an author's `named`-template choice — the
|
|
64
|
+
* editor writes it, the resolver reads it. Part of the `__plumix_*` namespace.
|
|
65
|
+
*/
|
|
66
|
+
export const NAMED_TEMPLATE_META_KEY = "__plumix_template";
|
|
67
|
+
/** A predicate matching when a content entry's meta value equals `value`. */
|
|
68
|
+
function metaEquals(key, value) {
|
|
69
|
+
return (data) => "entry" in data && data.entry.meta[key] === value;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Target a registered entry type. `name` autocompletes and rejects typos
|
|
73
|
+
* (`keyof EntryTypeRegistry`); the template's `data.entry` is typed from the
|
|
74
|
+
* type's projection.
|
|
75
|
+
*/
|
|
76
|
+
export function forEntryType(name) {
|
|
77
|
+
// Each selector adds its narrowing to the shared content-node prefix.
|
|
78
|
+
const content = (extra) => ({
|
|
79
|
+
template: (t) => matchRule({ nodeKind: "content", type: name, ...extra }, t),
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
template: (t) => matchRule({ nodeKind: "content", type: name }, t),
|
|
83
|
+
slug: (slug) => content({ slug }),
|
|
84
|
+
id: (id) => content({ id }),
|
|
85
|
+
whereMeta: (key, value) => content({ predicate: metaEquals(String(key), value) }),
|
|
86
|
+
where: (predicate) => content({
|
|
87
|
+
predicate: predicate,
|
|
88
|
+
}),
|
|
89
|
+
named: (id, label) => content({
|
|
90
|
+
named: { id, label },
|
|
91
|
+
predicate: metaEquals(NAMED_TEMPLATE_META_KEY, id),
|
|
92
|
+
}),
|
|
93
|
+
archive: {
|
|
94
|
+
template: (t) => matchRule({ nodeKind: "content-type-archive", type: name }, t),
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Target a registered taxonomy. `name` autocompletes and rejects typos; the
|
|
100
|
+
* template's `data.term` is typed from the taxonomy's term projection.
|
|
101
|
+
*/
|
|
102
|
+
export function forTermTaxonomy(name) {
|
|
103
|
+
return {
|
|
104
|
+
template: (t) => matchRule({ nodeKind: "term", type: name }, t),
|
|
105
|
+
slug: (slug) => ({
|
|
106
|
+
template: (t) => matchRule({ nodeKind: "term", type: name, slug }, t),
|
|
107
|
+
}),
|
|
108
|
+
id: (id) => ({
|
|
109
|
+
template: (t) => matchRule({ nodeKind: "term", type: name, id }, t),
|
|
110
|
+
}),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=template-builders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-builders.js","sourceRoot":"","sources":["../../../src/route/render/template-builders.ts"],"names":[],"mappings":"AAwBA,yEAAyE;AACzE,gFAAgF;AAChF,8EAA8E;AAC9E,6EAA6E;AAC7E,uEAAuE;AACvE,SAAS,IAAI,CACX,IAAiB,EACjB,QAA6B;IAE7B,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAkD,EAAE,CAAC;AAChF,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,QAAQ,CAAC,QAAqC;IAC5D,OAAO,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,iCAAiC;AACjC,MAAM,UAAU,KAAK,CAAC,QAAkC;IACtD,OAAO,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACjC,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,OAAO,CAAC,QAAoC;IAC1D,OAAO,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AACnC,CAAC;AAED,qCAAqC;AACrC,MAAM,UAAU,QAAQ,CAAC,QAAqC;IAC5D,OAAO,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,SAAS,CACvB,QAAsC;IAEtC,OAAO,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED,sBAAsB;AACtB,MAAM,UAAU,MAAM,CAAC,QAAmC;IACxD,OAAO,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAClC,CAAC;AAED,uBAAuB;AACvB,MAAM,UAAU,QAAQ,CAAC,QAAkC;IACzD,OAAO,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,uBAAuB;AACvB,MAAM,UAAU,WAAW,CAAC,QAAkC;IAC5D,OAAO,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;AACvC,CAAC;A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AAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;SACpE,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,31 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Template resolution for the array-based `templates`. `resolveTemplate` walks a
|
|
3
|
+
* theme's rules — targeted matchers (`forEntryType`/`forTermTaxonomy`) in
|
|
4
|
+
* declaration order, then the generic tier for the node's kind, then the
|
|
5
|
+
* universal `fallback`. `resolveErrorTemplate` looks up the 404/500 tiers.
|
|
3
6
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
* request. The render pipeline walks this list greedy-first-match
|
|
7
|
-
* against the registered template map.
|
|
8
|
-
*
|
|
9
|
-
* Mirrors WordPress's hierarchy verbatim — including the `category-…` /
|
|
10
|
-
* `tag-…` aliases for the built-in taxonomies (a hard-coded WP rule that
|
|
11
|
-
* predates the generic `taxonomy-{tax}-…` chain) and the fall-through to
|
|
12
|
-
* `archive` / `index`. Faust.js exposes the same shape from
|
|
13
|
-
* `getTemplate.ts`; the two implementations should produce identical
|
|
14
|
-
* candidate lists for the same input.
|
|
15
|
-
*
|
|
16
|
-
* `resolveTemplateCandidates(node, hooks)` is the async orchestrator the
|
|
17
|
-
* renderer calls: it runs the pure walker, then applies the
|
|
18
|
-
* `template:hierarchy` filter chain so plugins can mutate the list.
|
|
7
|
+
* The `ResolvedNode` shapes carry the identity the resolver matches on (kind +
|
|
8
|
+
* type + slug/id).
|
|
19
9
|
*/
|
|
20
|
-
import type {
|
|
21
|
-
|
|
22
|
-
interface FilterRegistry {
|
|
23
|
-
"template:hierarchy": (candidates: readonly string[], ctx: {
|
|
24
|
-
readonly node: ResolvedNode;
|
|
25
|
-
}) => readonly string[] | Promise<readonly string[]>;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export type ResolvedNode = ResolvedTermNode | ResolvedContentNode | ResolvedContentTypeArchive | ResolvedFrontPage | ResolvedPostsPage | ResolvedSearch;
|
|
10
|
+
import type { TemplateData, TemplateRule } from "../../theme.js";
|
|
11
|
+
export type ResolvedNode = ResolvedTermNode | ResolvedContentNode | ResolvedContentTypeArchive | ResolvedFrontPage | ResolvedSearch;
|
|
29
12
|
interface ResolvedTermNode {
|
|
30
13
|
readonly kind: "term";
|
|
31
14
|
readonly taxonomy: string;
|
|
@@ -45,24 +28,56 @@ interface ResolvedContentTypeArchive {
|
|
|
45
28
|
interface ResolvedFrontPage {
|
|
46
29
|
readonly kind: "front-page";
|
|
47
30
|
}
|
|
31
|
+
interface ResolvedSearch {
|
|
32
|
+
readonly kind: "search";
|
|
33
|
+
}
|
|
48
34
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* `
|
|
35
|
+
* Resolve a node to its template rule from a theme's `templates` array:
|
|
36
|
+
* (1) targeted rules (`forEntryType`/`forTermTaxonomy`, incl. `whereMeta`/`where`/
|
|
37
|
+
* `named` predicates) in declaration order, first match wins; (2) the generic
|
|
38
|
+
* tier for the node's kind; (3) the universal `fallback`. Returns `undefined`
|
|
39
|
+
* when nothing matches — the caller then renders the `notFound` (404) template.
|
|
40
|
+
* `data` is required for predicate rules to match.
|
|
52
41
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
export declare function resolveTemplate(rules: readonly TemplateRule[], node: ResolvedNode, data?: TemplateData): TemplateRule | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Look up an error-tier template (`notFound` → 404, `serverError` → 500).
|
|
45
|
+
* Separate from `resolveTemplate` because error pages are triggered by a
|
|
46
|
+
* condition (no match, or a render throw), not by a resolved node.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveErrorTemplate(rules: readonly TemplateRule[], tier: "notFound" | "serverError"): TemplateRule | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* A short human label for a rule — its tier, or (for a targeted rule) the type
|
|
51
|
+
* plus any `:slug` / `#id` narrowing. Used by the debug bar and as the
|
|
52
|
+
* normalize-error slot name.
|
|
53
|
+
*/
|
|
54
|
+
export declare function ruleLabel(rule: TemplateRule): string;
|
|
55
|
+
/** What happened to a rule during resolution. */
|
|
56
|
+
type ResolutionStatus = "matched" | "skipped" | "never-evaluated";
|
|
57
|
+
export interface ResolutionStep {
|
|
58
|
+
readonly label: string;
|
|
59
|
+
readonly status: ResolutionStatus;
|
|
60
|
+
/**
|
|
61
|
+
* Present for a targeted rule carrying a `whereMeta`/`where`/`named`
|
|
62
|
+
* predicate. `fired` is whether the predicate function actually ran (its
|
|
63
|
+
* rule's identity matched and `data` was present); `result` is its return.
|
|
64
|
+
*/
|
|
65
|
+
readonly predicate?: {
|
|
66
|
+
readonly fired: boolean;
|
|
67
|
+
readonly result: boolean;
|
|
68
|
+
};
|
|
55
69
|
}
|
|
56
|
-
interface
|
|
57
|
-
readonly
|
|
70
|
+
export interface ResolutionTrace {
|
|
71
|
+
readonly steps: readonly ResolutionStep[];
|
|
72
|
+
/** The winning rule's label, or `null` when nothing matched (a 404). */
|
|
73
|
+
readonly winner: string | null;
|
|
58
74
|
}
|
|
59
|
-
export declare function getPossibleTemplates(node: ResolvedNode): readonly string[];
|
|
60
75
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
76
|
+
* Replay `resolveTemplate` and classify every rule for the debug bar: which one
|
|
77
|
+
* won, which targeted rules were evaluated-but-skipped (with their predicate
|
|
78
|
+
* result), and which were never reached because an earlier zone already won.
|
|
79
|
+
* Dev-only — `resolveTemplate` stays allocation-free on the render hot path.
|
|
65
80
|
*/
|
|
66
|
-
export declare function
|
|
81
|
+
export declare function explainTemplateResolution(rules: readonly TemplateRule[], node: ResolvedNode, data?: TemplateData): ResolutionTrace;
|
|
67
82
|
export {};
|
|
68
83
|
//# sourceMappingURL=template-hierarchy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-hierarchy.d.ts","sourceRoot":"","sources":["../../../src/route/render/template-hierarchy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"template-hierarchy.d.ts","sourceRoot":"","sources":["../../../src/route/render/template-hierarchy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAGV,YAAY,EACZ,YAAY,EACb,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,YAAY,GACpB,gBAAgB,GAChB,mBAAmB,GACnB,0BAA0B,GAC1B,iBAAiB,GACjB,cAAc,CAAC;AAEnB,UAAU,gBAAgB;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,UAAU,0BAA0B;IAClC,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,UAAU,iBAAiB;IACzB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;CAC7B;AAED,UAAU,cAAc;IACtB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;CACzB;AAsDD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,IAAI,EAAE,YAAY,EAClB,IAAI,CAAC,EAAE,YAAY,GAClB,YAAY,GAAG,SAAS,CAW1B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,IAAI,EAAE,UAAU,GAAG,aAAa,GAC/B,YAAY,GAAG,SAAS,CAE1B;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CASpD;AAED,iDAAiD;AACjD,KAAK,gBAAgB,GAAG,SAAS,GAAG,SAAS,GAAG,iBAAiB,CAAC;AAElE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;CAC5E;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,CAAC;IAC1C,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,IAAI,EAAE,YAAY,EAClB,IAAI,CAAC,EAAE,YAAY,GAClB,eAAe,CAoCjB"}
|
|
@@ -1,88 +1,141 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Template resolution for the array-based `templates`. `resolveTemplate` walks a
|
|
3
|
+
* theme's rules — targeted matchers (`forEntryType`/`forTermTaxonomy`) in
|
|
4
|
+
* declaration order, then the generic tier for the node's kind, then the
|
|
5
|
+
* universal `fallback`. `resolveErrorTemplate` looks up the 404/500 tiers.
|
|
3
6
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
7
|
+
* The `ResolvedNode` shapes carry the identity the resolver matches on (kind +
|
|
8
|
+
* type + slug/id).
|
|
9
|
+
*/
|
|
10
|
+
// Maps each resolved-node kind to the generic tier that renders it. `fallback`
|
|
11
|
+
// (universal) and the `notFound`/`serverError` handlers are not node-matched —
|
|
12
|
+
// the former is the terminal, the latter fire on a condition, not a node.
|
|
13
|
+
const GENERIC_TIER_FOR_NODE = {
|
|
14
|
+
content: "entry",
|
|
15
|
+
"content-type-archive": "archive",
|
|
16
|
+
term: "taxonomy",
|
|
17
|
+
"front-page": "frontPage",
|
|
18
|
+
search: "search",
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The identity part of a match: node kind + type name, then the optional
|
|
22
|
+
* `slug`/`id` narrowing — an unset selector matches any.
|
|
19
23
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
function matchesIdentity(match, node) {
|
|
25
|
+
if (match.nodeKind !== node.kind)
|
|
26
|
+
return false;
|
|
22
27
|
switch (node.kind) {
|
|
23
|
-
case "term":
|
|
24
|
-
appendTermNodeCandidates(node, candidates);
|
|
25
|
-
break;
|
|
26
|
-
case "content":
|
|
27
|
-
appendContentNodeCandidates(node, candidates);
|
|
28
|
-
break;
|
|
29
28
|
case "content-type-archive":
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
case "
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
return match.type === node.entryType;
|
|
30
|
+
case "content":
|
|
31
|
+
return (match.type === node.entryType &&
|
|
32
|
+
(match.slug === undefined || match.slug === node.slug) &&
|
|
33
|
+
(match.id === undefined || match.id === node.databaseId));
|
|
34
|
+
case "term":
|
|
35
|
+
return (match.type === node.taxonomy &&
|
|
36
|
+
(match.slug === undefined || match.slug === node.slug) &&
|
|
37
|
+
(match.id === undefined || match.id === node.databaseId));
|
|
38
|
+
default:
|
|
39
|
+
return false;
|
|
41
40
|
}
|
|
42
|
-
candidates.push("index");
|
|
43
|
-
return candidates;
|
|
44
41
|
}
|
|
45
42
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* branching logic.
|
|
43
|
+
* Does a targeted matcher apply? Identity first, then the optional data
|
|
44
|
+
* predicate (`whereMeta`/`where`/`named`) — which needs the resolved data, so a
|
|
45
|
+
* predicate rule never matches when `data` is absent.
|
|
50
46
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
function matchesNode(match, node, data) {
|
|
48
|
+
if (!matchesIdentity(match, node))
|
|
49
|
+
return false;
|
|
50
|
+
if (match.predicate === undefined)
|
|
51
|
+
return true;
|
|
52
|
+
return data !== undefined && match.predicate(data);
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
out.push("taxonomy");
|
|
54
|
+
/**
|
|
55
|
+
* Resolve a node to its template rule from a theme's `templates` array:
|
|
56
|
+
* (1) targeted rules (`forEntryType`/`forTermTaxonomy`, incl. `whereMeta`/`where`/
|
|
57
|
+
* `named` predicates) in declaration order, first match wins; (2) the generic
|
|
58
|
+
* tier for the node's kind; (3) the universal `fallback`. Returns `undefined`
|
|
59
|
+
* when nothing matches — the caller then renders the `notFound` (404) template.
|
|
60
|
+
* `data` is required for predicate rules to match.
|
|
61
|
+
*/
|
|
62
|
+
export function resolveTemplate(rules, node, data) {
|
|
63
|
+
for (const rule of rules) {
|
|
64
|
+
if (rule.match !== undefined && matchesNode(rule.match, node, data)) {
|
|
65
|
+
return rule;
|
|
66
|
+
}
|
|
69
67
|
}
|
|
70
|
-
|
|
68
|
+
const tier = GENERIC_TIER_FOR_NODE[node.kind];
|
|
69
|
+
return (rules.find((r) => r.tier === tier) ??
|
|
70
|
+
rules.find((r) => r.tier === "fallback"));
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Look up an error-tier template (`notFound` → 404, `serverError` → 500).
|
|
74
|
+
* Separate from `resolveTemplate` because error pages are triggered by a
|
|
75
|
+
* condition (no match, or a render throw), not by a resolved node.
|
|
76
|
+
*/
|
|
77
|
+
export function resolveErrorTemplate(rules, tier) {
|
|
78
|
+
return rules.find((r) => r.tier === tier);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A short human label for a rule — its tier, or (for a targeted rule) the type
|
|
82
|
+
* plus any `:slug` / `#id` narrowing. Used by the debug bar and as the
|
|
83
|
+
* normalize-error slot name.
|
|
84
|
+
*/
|
|
85
|
+
export function ruleLabel(rule) {
|
|
86
|
+
if (rule.tier !== undefined)
|
|
87
|
+
return rule.tier;
|
|
88
|
+
const m = rule.match;
|
|
89
|
+
if (m === undefined)
|
|
90
|
+
return "?";
|
|
91
|
+
let sel = "";
|
|
92
|
+
if (m.slug !== undefined)
|
|
93
|
+
sel = `:${m.slug}`;
|
|
94
|
+
else if (m.id !== undefined)
|
|
95
|
+
sel = `#${m.id}`;
|
|
96
|
+
const prefix = m.nodeKind === "content-type-archive" ? "archive:" : "";
|
|
97
|
+
return `${prefix}${m.type}${sel}`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Replay `resolveTemplate` and classify every rule for the debug bar: which one
|
|
101
|
+
* won, which targeted rules were evaluated-but-skipped (with their predicate
|
|
102
|
+
* result), and which were never reached because an earlier zone already won.
|
|
103
|
+
* Dev-only — `resolveTemplate` stays allocation-free on the render hot path.
|
|
104
|
+
*/
|
|
105
|
+
export function explainTemplateResolution(rules, node, data) {
|
|
106
|
+
const winner = resolveTemplate(rules, node, data);
|
|
107
|
+
// The targeted walk stops at the first matching targeted rule. If the winner
|
|
108
|
+
// is targeted, only rules up to it were evaluated; otherwise every targeted
|
|
109
|
+
// rule was tried and skipped.
|
|
110
|
+
const winnerIsTargeted = winner?.match !== undefined;
|
|
111
|
+
const winnerIndex = winner ? rules.indexOf(winner) : -1;
|
|
112
|
+
const steps = rules.map((rule, index) => {
|
|
113
|
+
const label = ruleLabel(rule);
|
|
114
|
+
let status;
|
|
115
|
+
if (rule === winner) {
|
|
116
|
+
status = "matched";
|
|
117
|
+
}
|
|
118
|
+
else if (rule.match !== undefined) {
|
|
119
|
+
const evaluated = !winnerIsTargeted || index < winnerIndex;
|
|
120
|
+
status = evaluated ? "skipped" : "never-evaluated";
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
status = "never-evaluated";
|
|
124
|
+
}
|
|
125
|
+
const match = rule.match;
|
|
126
|
+
if (match?.predicate !== undefined && status !== "never-evaluated") {
|
|
127
|
+
// A predicate only runs after identity matches and when data is present.
|
|
128
|
+
if (data !== undefined && matchesIdentity(match, node)) {
|
|
129
|
+
return {
|
|
130
|
+
label,
|
|
131
|
+
status,
|
|
132
|
+
predicate: { fired: true, result: match.predicate(data) },
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return { label, status, predicate: { fired: false, result: false } };
|
|
136
|
+
}
|
|
137
|
+
return { label, status };
|
|
138
|
+
});
|
|
139
|
+
return { steps, winner: winner ? ruleLabel(winner) : null };
|
|
87
140
|
}
|
|
88
141
|
//# sourceMappingURL=template-hierarchy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-hierarchy.js","sourceRoot":"","sources":["../../../src/route/render/template-hierarchy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"template-hierarchy.js","sourceRoot":"","sources":["../../../src/route/render/template-hierarchy.ts"],"names":[],"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,CAAC,CAAC,iBAAiB,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,iBAAiB,CAAC;QAC7B,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,KAAK,EAAE,SAAS,KAAK,SAAS,IAAI,MAAM,KAAK,iBAAiB,EAAE,CAAC;YACnE,yEAAyE;YACzE,IAAI,IAAI,KAAK,SAAS,IAAI,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;gBACvD,OAAO;oBACL,KAAK;oBACL,MAAM;oBACN,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;iBAC1D,CAAC;YACJ,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACvE,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC9D,CAAC"}
|
package/dist/route/resolve.d.ts
CHANGED
|
@@ -3,15 +3,15 @@ import type { RegisteredTemplateDep } from "../template-deps.js";
|
|
|
3
3
|
import type { DocumentManifest, ThemeDescriptor } from "../theme.js";
|
|
4
4
|
import type { RouteMatch } from "./match.js";
|
|
5
5
|
import type { AssetManifest } from "./render/asset-manifest.js";
|
|
6
|
-
import type { ArchiveData, FrontPageData, SearchData,
|
|
6
|
+
import type { ArchiveData, EntryData, FrontPageData, SearchData, TaxonomyData } from "./render/resolved-entry.js";
|
|
7
7
|
declare module "../hooks/types.js" {
|
|
8
8
|
interface FilterRegistry {
|
|
9
|
-
"resolve:single:data": (data:
|
|
9
|
+
"resolve:single:data": (data: EntryData) => EntryData | Promise<EntryData>;
|
|
10
10
|
"resolve:archive:data": (data: ArchiveData) => ArchiveData | Promise<ArchiveData>;
|
|
11
11
|
"resolve:term:data": (data: TaxonomyData) => TaxonomyData | Promise<TaxonomyData>;
|
|
12
12
|
"resolve:front-page:data": (data: FrontPageData) => FrontPageData | Promise<FrontPageData>;
|
|
13
13
|
"resolve:search:data": (data: SearchData) => SearchData | Promise<SearchData>;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
export declare function resolvePublicRoute(ctx: AppContext, match: RouteMatch, theme: ThemeDescriptor, document: DocumentManifest,
|
|
16
|
+
export declare function resolvePublicRoute(ctx: AppContext, match: RouteMatch, theme: ThemeDescriptor, document: DocumentManifest, templateDeps: ReadonlyMap<string, RegisteredTemplateDep>, assetManifest: AssetManifest): Promise<Response>;
|
|
17
17
|
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/route/resolve.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,UAAU,EACV,
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/route/resolve.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB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