@dogsbay/format-hugo 0.2.0-beta.182 → 0.2.0-beta.184
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/adapters/conventions.d.ts +15 -0
- package/dist/adapters/conventions.js +213 -0
- package/dist/adapters/datadog.d.ts +23 -0
- package/dist/adapters/datadog.js +376 -0
- package/dist/adapters/docsy.d.ts +9 -0
- package/dist/adapters/docsy.js +57 -0
- package/dist/adapters/index.d.ts +28 -0
- package/dist/adapters/index.js +40 -0
- package/dist/adapters/kubernetes.d.ts +22 -0
- package/dist/adapters/kubernetes.js +738 -0
- package/dist/builtins.d.ts +4 -1
- package/dist/builtins.js +8 -111
- package/dist/choice-html.d.ts +9 -0
- package/dist/choice-html.js +57 -0
- package/dist/cli.d.ts +46 -1
- package/dist/cli.js +466 -11
- package/dist/config.d.ts +16 -0
- package/dist/config.js +121 -2
- package/dist/html-blocks.d.ts +42 -0
- package/dist/html-blocks.js +671 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -2
- package/dist/intent.d.ts +123 -0
- package/dist/intent.js +357 -0
- package/dist/references.d.ts +29 -0
- package/dist/references.js +91 -0
- package/dist/registry.d.ts +116 -2
- package/dist/resolve.d.ts +27 -0
- package/dist/resolve.js +32 -6
- package/dist/shortcodes.d.ts +21 -21
- package/dist/shortcodes.js +60 -27
- package/dist/static.d.ts +25 -0
- package/dist/static.js +195 -0
- package/dist/translate.d.ts +30 -3
- package/dist/translate.js +175 -18
- package/package.json +3 -3
- package/dist/kubernetes.d.ts +0 -13
- package/dist/kubernetes.js +0 -185
package/dist/builtins.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hugo
|
|
2
|
+
* Hugo's own (embedded) shortcodes: the ones every Hugo site has.
|
|
3
|
+
*
|
|
4
|
+
* What a theme or a site defines is an adapter's (`adapters/`): Docsy's `alert`, kubernetes'
|
|
5
|
+
* `feature-state`, the names sites keep reinventing (`note`, `tabs`, `include`).
|
|
3
6
|
*
|
|
4
7
|
* Every mapping here is evidence-backed: the counts in the comments are
|
|
5
8
|
* measured occurrences in `kubernetes/website/content/en`. A shortcode whose
|
package/dist/builtins.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hugo
|
|
2
|
+
* Hugo's own (embedded) shortcodes: the ones every Hugo site has.
|
|
3
|
+
*
|
|
4
|
+
* What a theme or a site defines is an adapter's (`adapters/`): Docsy's `alert`, kubernetes'
|
|
5
|
+
* `feature-state`, the names sites keep reinventing (`note`, `tabs`, `include`).
|
|
3
6
|
*
|
|
4
7
|
* Every mapping here is evidence-backed: the counts in the comments are
|
|
5
8
|
* measured occurrences in `kubernetes/website/content/en`. A shortcode whose
|
|
@@ -9,18 +12,7 @@
|
|
|
9
12
|
*/
|
|
10
13
|
import { arg, attrBlock, directive } from "./registry.js";
|
|
11
14
|
import { lookupParam } from "./config.js";
|
|
12
|
-
import {
|
|
13
|
-
/** Docsy `alert` colours → Dogsbay callout types. */
|
|
14
|
-
const ALERT_COLOURS = {
|
|
15
|
-
primary: "info",
|
|
16
|
-
secondary: "note",
|
|
17
|
-
info: "info",
|
|
18
|
-
success: "success",
|
|
19
|
-
warning: "warning",
|
|
20
|
-
danger: "danger",
|
|
21
|
-
dark: "note",
|
|
22
|
-
light: "note",
|
|
23
|
-
};
|
|
15
|
+
import { attributeRef, isAttributeName } from "./intent.js";
|
|
24
16
|
export const BUILTIN_SHORTCODES = {
|
|
25
17
|
// ── Hugo builtins ───────────────────────────────────────
|
|
26
18
|
//
|
|
@@ -73,6 +65,9 @@ export const BUILTIN_SHORTCODES = {
|
|
|
73
65
|
});
|
|
74
66
|
return "";
|
|
75
67
|
}
|
|
68
|
+
// Keeping intent: the site's attribute, defined once in the config
|
|
69
|
+
if (ctx.intent && isAttributeName(key))
|
|
70
|
+
return attributeRef(ctx.intent, key, value);
|
|
76
71
|
return value;
|
|
77
72
|
},
|
|
78
73
|
// `{{< ref "docs/concepts/_index.md" >}}` — 2570 uses, by far the most
|
|
@@ -108,102 +103,4 @@ export const BUILTIN_SHORTCODES = {
|
|
|
108
103
|
});
|
|
109
104
|
return target.replace(/(?:\/_?index)?\.md$/, "");
|
|
110
105
|
},
|
|
111
|
-
// ── Callouts ────────────────────────────────────────────
|
|
112
|
-
//
|
|
113
|
-
// Hugo/Docsy sites all grow the same three, and Kubernetes uses them 1,071
|
|
114
|
-
// times between them. The body may be markdown (`{{% note %}}`) or raw
|
|
115
|
-
// (`{{< note >}}`); either way it is content and gets translated.
|
|
116
|
-
note: (node, ctx) => directive("note", "", ctx.translate(node.inner)),
|
|
117
|
-
caution: (node, ctx) => directive("caution", "", ctx.translate(node.inner)),
|
|
118
|
-
warning: (node, ctx) => directive("warning", "", ctx.translate(node.inner)),
|
|
119
|
-
// Docsy's own callout. 91 uses. `color=` selects the variant and `title=`
|
|
120
|
-
// is a heading on the box.
|
|
121
|
-
alert: (node, ctx) => {
|
|
122
|
-
const colour = (node.args.named.color ?? "").toLowerCase();
|
|
123
|
-
const type = ALERT_COLOURS[colour] ?? "note";
|
|
124
|
-
if (colour && !ALERT_COLOURS[colour]) {
|
|
125
|
-
ctx.report({
|
|
126
|
-
shortcode: "alert",
|
|
127
|
-
action: "degraded",
|
|
128
|
-
note: `unknown alert colour "${colour}" → :::note`,
|
|
129
|
-
line: node.line,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
return directive(type, attrBlock({ title: node.args.named.title }), ctx.translate(node.inner));
|
|
133
|
-
},
|
|
134
|
-
// Docsy `pageinfo` — a page-level banner. Same shape as an alert.
|
|
135
|
-
pageinfo: (node, ctx) => directive(ALERT_COLOURS[(node.args.named.color ?? "").toLowerCase()] ?? "info", "", ctx.translate(node.inner)),
|
|
136
|
-
// ── Tabs ────────────────────────────────────────────────
|
|
137
|
-
//
|
|
138
|
-
// `{{< tabs name="x" >}}` wrapping `{{% tab name="Linux" %}}`. 117 groups,
|
|
139
|
-
// 287 tabs. Note the delimiter mix: the wrapper is angle, the tabs are
|
|
140
|
-
// percent, which is exactly why the scanner has to handle both.
|
|
141
|
-
tabs: (node, ctx) => directive("tabs", "", ctx.translate(node.inner)),
|
|
142
|
-
tab: (node, ctx) => {
|
|
143
|
-
const title = arg(node.args, "name", "header", "title") ?? "";
|
|
144
|
-
// `{{< tab name="x" include="file.md" />}}` — the kubeadm reference pages
|
|
145
|
-
// use this 118 times to pull in generated content.
|
|
146
|
-
// `include=` is not always a path: `{{< feature-gate-table include="alpha,beta" >}}`
|
|
147
|
-
// uses the same attribute name as a FILTER, and treating that as a file
|
|
148
|
-
// produced a guaranteed-failing read plus a misleading ledger entry.
|
|
149
|
-
const include = node.args.named.include;
|
|
150
|
-
if (looksLikeFile(include)) {
|
|
151
|
-
const content = ctx.readContentFile?.(include, ctx.file);
|
|
152
|
-
if (content !== undefined) {
|
|
153
|
-
return directive("tab", attrBlock({ title }), ctx.translate(content));
|
|
154
|
-
}
|
|
155
|
-
ctx.report({
|
|
156
|
-
shortcode: "tab",
|
|
157
|
-
action: "degraded",
|
|
158
|
-
note: `could not read included file "${include}" — tab is empty`,
|
|
159
|
-
line: node.line,
|
|
160
|
-
});
|
|
161
|
-
return directive("tab", attrBlock({ title }), "");
|
|
162
|
-
}
|
|
163
|
-
return directive("tab", attrBlock({ title }), ctx.translate(node.inner));
|
|
164
|
-
},
|
|
165
|
-
// Docsy's newer tab syntax.
|
|
166
|
-
tabpane: (node, ctx) => directive("tabs", "", ctx.translate(node.inner)),
|
|
167
|
-
"tab-pane": (node, ctx) => directive("tab", attrBlock({ title: arg(node.args, "header", "title", "name") }), ctx.translate(node.inner)),
|
|
168
|
-
// ── Other block constructs ──────────────────────────────
|
|
169
|
-
//
|
|
170
|
-
// 53 uses. A mermaid diagram is a code block with a `mermaid` language
|
|
171
|
-
// everywhere outside Hugo.
|
|
172
|
-
mermaid: (node) => {
|
|
173
|
-
const body = node.inner.replace(/^\n+|\n+$/g, "");
|
|
174
|
-
return `\`\`\`mermaid\n${body}\n\`\`\``;
|
|
175
|
-
},
|
|
176
|
-
// 59 uses. `{{< table caption="…" >}}` wraps a markdown table to caption it.
|
|
177
|
-
table: (node, ctx) => {
|
|
178
|
-
const caption = node.args.named.caption;
|
|
179
|
-
const body = ctx.translate(node.inner).replace(/^\n+|\n+$/g, "");
|
|
180
|
-
// Dogsbay-MD captions a table with a trailing `{caption}` line.
|
|
181
|
-
return caption ? `${body}\n{${caption}}` : body;
|
|
182
|
-
},
|
|
183
|
-
// `{{< include "file.md" >}}` — 171 uses. Pulls in another content file.
|
|
184
|
-
include: (node, ctx) => {
|
|
185
|
-
const target = arg(node.args, "file", "path") ?? "";
|
|
186
|
-
const content = ctx.readContentFile?.(target, ctx.file);
|
|
187
|
-
if (content === undefined) {
|
|
188
|
-
ctx.report({
|
|
189
|
-
shortcode: "include",
|
|
190
|
-
action: "degraded",
|
|
191
|
-
note: `could not read included file "${target}"`,
|
|
192
|
-
line: node.line,
|
|
193
|
-
});
|
|
194
|
-
return "";
|
|
195
|
-
}
|
|
196
|
-
return ctx.translate(content);
|
|
197
|
-
},
|
|
198
|
-
// 12 uses. An author note that never renders — dropping it is correct, and
|
|
199
|
-
// recording the drop is what makes it not-silent.
|
|
200
|
-
comment: (node, ctx) => {
|
|
201
|
-
ctx.report({
|
|
202
|
-
shortcode: "comment",
|
|
203
|
-
action: "stripped",
|
|
204
|
-
note: "author comment — not rendered by Hugo either",
|
|
205
|
-
line: node.line,
|
|
206
|
-
});
|
|
207
|
-
return null;
|
|
208
|
-
},
|
|
209
106
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reader-choice values written inside raw HTML (plans/reader-choices.md, phase 3). Markdown is
|
|
3
|
+
* not read inside an HTML block, so a `:choice-value[…]{…}` the import wrote there (Datadog's
|
|
4
|
+
* `<div class="alert …">` boxes, `<pre>` blocks) would show as that text. Each becomes the
|
|
5
|
+
* default's value, as HTML: the page then shows it to every reader, which the caller reports.
|
|
6
|
+
*/
|
|
7
|
+
import type { TreeNode } from "@dogsbay/types";
|
|
8
|
+
/** Every raw HTML block and inline HTML of a tree with its values written in; how many there were. */
|
|
9
|
+
export declare function bakeChoiceValuesInHtml(tree: TreeNode[], choices: Record<string, unknown>): number;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const VALUE = /:choice-value\[((?:\\.|[^\]\\\n]){0,400})\]\{([^}\n]{0,400})\}/g;
|
|
2
|
+
const ATTR = /([a-z][a-z0-9-]*)(?:="([^"\n]*)")?/g;
|
|
3
|
+
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
4
|
+
const own = (o, k) => o && typeof o === "object" && Object.prototype.hasOwnProperty.call(o, k) ? o[k] : undefined;
|
|
5
|
+
/** The default's value of `key`, from a choice's config as the import wrote it. */
|
|
6
|
+
function defaultValue(config, key) {
|
|
7
|
+
const def = own(config, "default");
|
|
8
|
+
const v = typeof def === "string" ? own(own(own(config, "values"), def), key) : undefined;
|
|
9
|
+
return typeof v === "string" ? v : undefined;
|
|
10
|
+
}
|
|
11
|
+
/** One HTML text with its values written in. */
|
|
12
|
+
function bake(html, choices, count) {
|
|
13
|
+
if (!html.includes(":choice-value["))
|
|
14
|
+
return html;
|
|
15
|
+
return html.replace(VALUE, (all, label, attrText) => {
|
|
16
|
+
const attrs = [...attrText.matchAll(ATTR)];
|
|
17
|
+
const first = attrs[0];
|
|
18
|
+
const value = first && first[2] !== undefined ? defaultValue(own(choices, first[1]), first[2]) : undefined;
|
|
19
|
+
if (value === undefined)
|
|
20
|
+
return all;
|
|
21
|
+
count.n++;
|
|
22
|
+
const forms = new Set(attrs.slice(1).map((a) => a[1]));
|
|
23
|
+
if (forms.has("code"))
|
|
24
|
+
return `<code>${esc(value)}</code>`;
|
|
25
|
+
if (forms.has("link")) {
|
|
26
|
+
const text = label.replace(/\\(.)/g, "$1").replace(/{/g, "{");
|
|
27
|
+
// only an address a link may have (the build refuses the rest for a switched value)
|
|
28
|
+
if (/^\s*(?:javascript|vbscript|data):/i.test(value.replace(/[\u0000- ]+/g, "")))
|
|
29
|
+
return esc(text || value);
|
|
30
|
+
return `<a href="${esc(value)}">${esc(text || value)}</a>`;
|
|
31
|
+
}
|
|
32
|
+
return esc(value);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Every raw HTML block and inline HTML of a tree with its values written in; how many there were. */
|
|
36
|
+
export function bakeChoiceValuesInHtml(tree, choices) {
|
|
37
|
+
const count = { n: 0 };
|
|
38
|
+
const inline = (nodes) => {
|
|
39
|
+
for (const n of nodes ?? []) {
|
|
40
|
+
if (n.type === "html-inline")
|
|
41
|
+
n.html = bake(n.html, choices, count);
|
|
42
|
+
const kids = n.children;
|
|
43
|
+
if (Array.isArray(kids))
|
|
44
|
+
inline(kids);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const blocks = (nodes) => {
|
|
48
|
+
for (const n of nodes ?? []) {
|
|
49
|
+
if (n.type === "html" && typeof n.html === "string")
|
|
50
|
+
n.html = bake(n.html, choices, count);
|
|
51
|
+
inline(n.inline);
|
|
52
|
+
blocks(n.children);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
blocks(tree);
|
|
56
|
+
return count.n;
|
|
57
|
+
}
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { FormatPlugin, ExportPage, NavItem } from "@dogsbay/types";
|
|
2
|
-
import type
|
|
2
|
+
import { type HugoConfig } from "./config.js";
|
|
3
|
+
import { type StaticFile } from "./static.js";
|
|
4
|
+
import type { HugoLedgerEntry, HugoSiteFacts } from "./registry.js";
|
|
3
5
|
export interface HugoImportResult {
|
|
4
6
|
pages: ExportPage[];
|
|
5
7
|
nav: NavItem[];
|
|
@@ -9,6 +11,41 @@ export interface HugoImportResult {
|
|
|
9
11
|
siteTitle?: string;
|
|
10
12
|
/** Languages the site declares — the choices for `--lang`. */
|
|
11
13
|
languages: string[];
|
|
14
|
+
/** The theme and site adapters used, lowest first, each with why it was chosen. */
|
|
15
|
+
adapters: Array<{
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
why: string;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* With `keepIntent`: what the pages refer to and the site must hold.
|
|
22
|
+
* - `attributes`: site attributes (`{{ version }}`), for the config;
|
|
23
|
+
* - `templatePages`: slugs of the pages that compute a value (`template: jinja`);
|
|
24
|
+
* - `fragments`: shared texts pages include, each written once at `path` in the content folder;
|
|
25
|
+
* - `files`: files copied as they are (examples a code block includes);
|
|
26
|
+
* - `data`: data files template pages read (`data.feature_gates`).
|
|
27
|
+
*/
|
|
28
|
+
intent?: {
|
|
29
|
+
attributes: Record<string, string>;
|
|
30
|
+
templatePages: string[];
|
|
31
|
+
fragments: Array<{
|
|
32
|
+
path: string;
|
|
33
|
+
tree: ExportPage["tree"];
|
|
34
|
+
}>;
|
|
35
|
+
files: Array<{
|
|
36
|
+
path: string;
|
|
37
|
+
source: string;
|
|
38
|
+
}>;
|
|
39
|
+
/** Data files the template pages read, by name: for the site's `data/` folder. */
|
|
40
|
+
data: Record<string, unknown>;
|
|
41
|
+
/** Reader choices the pages use, by name: for the config's `choices:` (plans/reader-choices.md). */
|
|
42
|
+
choices: Record<string, unknown>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Files of the Hugo site's `static/` folder the pages show, each to be written at `path` in
|
|
46
|
+
* the content folder (`_assets/…`). The pages already point there.
|
|
47
|
+
*/
|
|
48
|
+
staticFiles: StaticFile[];
|
|
12
49
|
/**
|
|
13
50
|
* Absolute directory the page slugs are relative to: the content dir,
|
|
14
51
|
* narrowed by `--lang` and `--section`. Recomputing it from the config
|
|
@@ -21,6 +58,14 @@ export interface HugoImportResult {
|
|
|
21
58
|
prefix: string;
|
|
22
59
|
}[];
|
|
23
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* What a site says about itself before its pages are read: its themes, and the names of the
|
|
63
|
+
* shortcodes it defines. Names only; the one file opened is `go.mod`, for the modules it
|
|
64
|
+
* requires. All of it is the site's, so: nothing outside the site's folder is listed (a
|
|
65
|
+
* `layouts/shortcodes` that links elsewhere is skipped), links inside are named and not
|
|
66
|
+
* followed, and counts and depth are bounded.
|
|
67
|
+
*/
|
|
68
|
+
export declare function siteFacts(source: string, config: HugoConfig): HugoSiteFacts;
|
|
24
69
|
export declare function importHugo(source: string, opts: Record<string, unknown>): Promise<HugoImportResult>;
|
|
25
70
|
/** Group the ledger for a human-readable report. */
|
|
26
71
|
export declare function summariseHugoLedger(ledger: HugoLedgerEntry[]): Array<{
|