@dogsbay/format-hugo 0.2.0-beta.101
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/builtins.d.ts +12 -0
- package/dist/builtins.d.ts.map +1 -0
- package/dist/builtins.js +207 -0
- package/dist/builtins.js.map +1 -0
- package/dist/cli.d.ts +33 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +190 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +72 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +191 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/kubernetes.d.ts +14 -0
- package/dist/kubernetes.d.ts.map +1 -0
- package/dist/kubernetes.js +186 -0
- package/dist/kubernetes.js.map +1 -0
- package/dist/nav.d.ts +88 -0
- package/dist/nav.d.ts.map +1 -0
- package/dist/nav.js +381 -0
- package/dist/nav.js.map +1 -0
- package/dist/registry.d.ts +79 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +41 -0
- package/dist/registry.js.map +1 -0
- package/dist/resolve.d.ts +26 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +81 -0
- package/dist/resolve.js.map +1 -0
- package/dist/shortcodes.d.ts +66 -0
- package/dist/shortcodes.d.ts.map +1 -0
- package/dist/shortcodes.js +216 -0
- package/dist/shortcodes.js.map +1 -0
- package/dist/translate.d.ts +19 -0
- package/dist/translate.d.ts.map +1 -0
- package/dist/translate.js +99 -0
- package/dist/translate.js.map +1 -0
- package/package.json +39 -0
package/dist/config.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hugo site configuration.
|
|
3
|
+
*
|
|
4
|
+
* Hugo accepts `hugo.toml|yaml|json`, the legacy `config.*` names, and a
|
|
5
|
+
* `config/_default/**` directory that is merged key-by-key. Kubernetes uses
|
|
6
|
+
* `hugo.toml` with `contentDir = "content/en"`.
|
|
7
|
+
*
|
|
8
|
+
* This is not just metadata. `{{< param "x" >}}` and `{{< skew >}}` read
|
|
9
|
+
* `[params]`, so the config is required for CONTENT fidelity: without it those
|
|
10
|
+
* shortcodes have nothing to substitute and 418 calls across the kubernetes
|
|
11
|
+
* corpus resolve to nothing.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
14
|
+
import { join, extname } from "node:path";
|
|
15
|
+
import { parse as parseToml } from "smol-toml";
|
|
16
|
+
import { parse as parseYaml } from "yaml";
|
|
17
|
+
const CONFIG_BASENAMES = ["hugo", "config"];
|
|
18
|
+
const CONFIG_EXTS = [".toml", ".yaml", ".yml", ".json"];
|
|
19
|
+
function parseFile(path, errors, label) {
|
|
20
|
+
try {
|
|
21
|
+
const text = readFileSync(path, "utf-8");
|
|
22
|
+
const ext = extname(path).toLowerCase();
|
|
23
|
+
if (ext === ".toml")
|
|
24
|
+
return parseToml(text);
|
|
25
|
+
if (ext === ".json")
|
|
26
|
+
return JSON.parse(text);
|
|
27
|
+
return (parseYaml(text) ?? {});
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
// A config we cannot read degrades to defaults rather than killing the
|
|
31
|
+
// import — the content is still worth having — but the caller is told.
|
|
32
|
+
errors.push({ file: label, message: err instanceof Error ? err.message : String(err) });
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Deep merge, later wins. Hugo merges `config/_default/**` this way. */
|
|
37
|
+
function merge(base, next) {
|
|
38
|
+
const out = { ...base };
|
|
39
|
+
for (const [k, v] of Object.entries(next)) {
|
|
40
|
+
const prev = out[k];
|
|
41
|
+
out[k] =
|
|
42
|
+
prev && typeof prev === "object" && !Array.isArray(prev) &&
|
|
43
|
+
v && typeof v === "object" && !Array.isArray(v)
|
|
44
|
+
? merge(prev, v)
|
|
45
|
+
: v;
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
/** Detect whether a directory looks like a Hugo site. */
|
|
50
|
+
export function detectHugo(dir) {
|
|
51
|
+
if (!existsSync(dir))
|
|
52
|
+
return false;
|
|
53
|
+
for (const base of CONFIG_BASENAMES) {
|
|
54
|
+
for (const ext of CONFIG_EXTS) {
|
|
55
|
+
if (existsSync(join(dir, base + ext)))
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return existsSync(join(dir, "config", "_default"));
|
|
60
|
+
}
|
|
61
|
+
export function loadHugoConfig(dir) {
|
|
62
|
+
const sources = [];
|
|
63
|
+
const parseErrors = [];
|
|
64
|
+
let raw = {};
|
|
65
|
+
// `config/_default/**` first, then a root config file overrides it — which
|
|
66
|
+
// is Hugo's precedence.
|
|
67
|
+
const defaults = join(dir, "config", "_default");
|
|
68
|
+
if (existsSync(defaults) && statSync(defaults).isDirectory()) {
|
|
69
|
+
for (const name of readdirSync(defaults).sort()) {
|
|
70
|
+
if (!CONFIG_EXTS.includes(extname(name).toLowerCase()))
|
|
71
|
+
continue;
|
|
72
|
+
const parsed = parseFile(join(defaults, name), parseErrors, join("config/_default", name));
|
|
73
|
+
if (!parsed)
|
|
74
|
+
continue;
|
|
75
|
+
sources.push(join("config/_default", name));
|
|
76
|
+
// `params.yaml` in that directory populates `params`, `menus.yaml`
|
|
77
|
+
// populates `menus`, and so on — the FILENAME is the key.
|
|
78
|
+
const key = name.slice(0, -extname(name).length);
|
|
79
|
+
raw = key === "hugo" || key === "config" ? merge(raw, parsed) : merge(raw, { [key]: parsed });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
for (const base of CONFIG_BASENAMES) {
|
|
83
|
+
for (const ext of CONFIG_EXTS) {
|
|
84
|
+
const path = join(dir, base + ext);
|
|
85
|
+
if (!existsSync(path))
|
|
86
|
+
continue;
|
|
87
|
+
const parsed = parseFile(path, parseErrors, base + ext);
|
|
88
|
+
if (!parsed)
|
|
89
|
+
continue;
|
|
90
|
+
sources.push(base + ext);
|
|
91
|
+
raw = merge(raw, parsed);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const params = (raw.params ?? {});
|
|
95
|
+
const contentDir = typeof raw.contentDir === "string" ? raw.contentDir : "content";
|
|
96
|
+
const languages = [];
|
|
97
|
+
const langBlock = raw.languages;
|
|
98
|
+
if (langBlock && typeof langBlock === "object") {
|
|
99
|
+
for (const [code, cfg] of Object.entries(langBlock)) {
|
|
100
|
+
languages.push({
|
|
101
|
+
code,
|
|
102
|
+
contentDir: typeof cfg?.contentDir === "string" ? cfg.contentDir : contentDir,
|
|
103
|
+
title: typeof cfg?.title === "string" ? cfg.title : undefined,
|
|
104
|
+
weight: typeof cfg?.weight === "number" ? cfg.weight : undefined,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
languages.sort((a, b) => (a.weight ?? 0) - (b.weight ?? 0));
|
|
108
|
+
}
|
|
109
|
+
// Hugo accepts both `[permalinks] blog = "…"` and the newer
|
|
110
|
+
// `[permalinks.page] blog = "…"`.
|
|
111
|
+
const permalinks = {};
|
|
112
|
+
const sectionPermalinks = {};
|
|
113
|
+
const permaRaw = (raw.permalinks ?? {});
|
|
114
|
+
for (const [key, value] of Object.entries(permaRaw)) {
|
|
115
|
+
// The legacy flat form applies to regular pages.
|
|
116
|
+
if (typeof value === "string")
|
|
117
|
+
permalinks[key] = value;
|
|
118
|
+
else if (value && typeof value === "object" && (key === "page" || key === "section")) {
|
|
119
|
+
const target = key === "section" ? sectionPermalinks : permalinks;
|
|
120
|
+
for (const [k, v] of Object.entries(value)) {
|
|
121
|
+
if (typeof v === "string")
|
|
122
|
+
target[k] = v;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const themeRaw = raw.theme;
|
|
127
|
+
const themes = Array.isArray(themeRaw)
|
|
128
|
+
? themeRaw.filter((t) => typeof t === "string")
|
|
129
|
+
: typeof themeRaw === "string"
|
|
130
|
+
? [themeRaw]
|
|
131
|
+
: [];
|
|
132
|
+
return {
|
|
133
|
+
title: typeof raw.title === "string" ? raw.title : undefined,
|
|
134
|
+
baseURL: typeof raw.baseURL === "string" ? raw.baseURL : undefined,
|
|
135
|
+
contentDir,
|
|
136
|
+
params,
|
|
137
|
+
languages,
|
|
138
|
+
themes,
|
|
139
|
+
permalinks,
|
|
140
|
+
sectionPermalinks,
|
|
141
|
+
sources,
|
|
142
|
+
parseErrors,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Resolve a dotted param path against the site params, the way
|
|
147
|
+
* `{{< param "version.next" >}}` does. Returns undefined when absent, so the
|
|
148
|
+
* caller can record the unresolved reference rather than emitting "undefined".
|
|
149
|
+
*/
|
|
150
|
+
export function lookupParam(params, path) {
|
|
151
|
+
let cursor = params;
|
|
152
|
+
for (const key of path.split(".")) {
|
|
153
|
+
if (!cursor || typeof cursor !== "object")
|
|
154
|
+
return undefined;
|
|
155
|
+
// Hugo param lookup is case-insensitive.
|
|
156
|
+
const record = cursor;
|
|
157
|
+
const match = key in record
|
|
158
|
+
? key
|
|
159
|
+
: Object.keys(record).find((k) => k.toLowerCase() === key.toLowerCase());
|
|
160
|
+
if (match === undefined)
|
|
161
|
+
return undefined;
|
|
162
|
+
cursor = record[match];
|
|
163
|
+
}
|
|
164
|
+
if (cursor === null || cursor === undefined)
|
|
165
|
+
return undefined;
|
|
166
|
+
if (typeof cursor === "object")
|
|
167
|
+
return undefined;
|
|
168
|
+
return String(cursor);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The content directory to import for a given language.
|
|
172
|
+
*
|
|
173
|
+
* A multilingual Hugo site keeps one directory per language
|
|
174
|
+
* (`content/en`, `content/ja`, …). Kubernetes declares 18. One language per
|
|
175
|
+
* import run: mixing them produces a page set with colliding slugs.
|
|
176
|
+
*/
|
|
177
|
+
export function contentDirFor(config, lang) {
|
|
178
|
+
if (!lang)
|
|
179
|
+
return config.contentDir;
|
|
180
|
+
const declared = config.languages.find((l) => l.code === lang);
|
|
181
|
+
if (declared)
|
|
182
|
+
return declared.contentDir;
|
|
183
|
+
// Not declared but conventional: `content/<lang>` beside the default.
|
|
184
|
+
const parts = config.contentDir.split("/");
|
|
185
|
+
if (parts.length > 1) {
|
|
186
|
+
parts[parts.length - 1] = lang;
|
|
187
|
+
return parts.join("/");
|
|
188
|
+
}
|
|
189
|
+
return `${config.contentDir}/${lang}`;
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAuD1C,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC5C,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExD,SAAS,SAAS,CAChB,IAAY,EACZ,MAAgD,EAChD,KAAa;IAEb,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACzC,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QACxC,IAAI,GAAG,KAAK,OAAO;YAAE,OAAO,SAAS,CAAC,IAAI,CAA4B,CAAC;QACvE,IAAI,GAAG,KAAK,OAAO;YAAE,OAAO,IAA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ScanNode, type ShortcodeNode, type TextNode, type ShortcodeArgs, type ShortcodeDelimiter, } from "./shortcodes.js";
|
|
2
|
+
export { detectHugo, loadHugoConfig, lookupParam, contentDirFor, type HugoConfig, type HugoLanguage, } from "./config.js";
|
|
3
|
+
export { arg, attrBlock, directive, composeRegistry, type ShortcodeMapping, type ShortcodeRegistry, type ShortcodeContext, type HugoLedgerEntry, } from "./registry.js";
|
|
4
|
+
export { BUILTIN_SHORTCODES } from "./builtins.js";
|
|
5
|
+
export { KUBERNETES_SHORTCODES } from "./kubernetes.js";
|
|
6
|
+
export { makeContentResolver, looksLikeFile } from "./resolve.js";
|
|
7
|
+
export { translateHugo, type TranslateOptions, type TranslateResult } from "./translate.js";
|
|
8
|
+
export { collectHugoPages, buildHugoNav, makeRefResolver, splitFrontmatter, type HugoPage, } from "./nav.js";
|
|
9
|
+
export { importHugo, summariseHugoLedger, plugin, type HugoImportResult, } from "./cli.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,uBAAuB,EACvB,oBAAoB,EACpB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,kBAAkB,GACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,UAAU,EACV,cAAc,EACd,WAAW,EACX,aAAa,EACb,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,GAAG,EACH,SAAS,EACT,SAAS,EACT,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,KAAK,QAAQ,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,MAAM,EACN,KAAK,gBAAgB,GACtB,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { scanShortcodes, parseArgs, stripContentTypeMarkers, CONTENT_TYPE_MARKERS, } from "./shortcodes.js";
|
|
2
|
+
export { detectHugo, loadHugoConfig, lookupParam, contentDirFor, } from "./config.js";
|
|
3
|
+
export { arg, attrBlock, directive, composeRegistry, } from "./registry.js";
|
|
4
|
+
export { BUILTIN_SHORTCODES } from "./builtins.js";
|
|
5
|
+
export { KUBERNETES_SHORTCODES } from "./kubernetes.js";
|
|
6
|
+
export { makeContentResolver, looksLikeFile } from "./resolve.js";
|
|
7
|
+
export { translateHugo } from "./translate.js";
|
|
8
|
+
export { collectHugoPages, buildHugoNav, makeRefResolver, splitFrontmatter, } from "./nav.js";
|
|
9
|
+
export { importHugo, summariseHugoLedger, plugin, } from "./cli.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,uBAAuB,EACvB,oBAAoB,GAMrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,UAAU,EACV,cAAc,EACd,WAAW,EACX,aAAa,GAGd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,GAAG,EACH,SAAS,EACT,SAAS,EACT,eAAe,GAKhB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,aAAa,EAA+C,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,gBAAgB,GAEjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,MAAM,GAEP,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kubernetes site shortcodes.
|
|
3
|
+
*
|
|
4
|
+
* These are defined in `kubernetes/website/layouts/shortcodes/`, not in Hugo
|
|
5
|
+
* or Docsy, so they belong in a SITE layer rather than the core — the same
|
|
6
|
+
* separation the MDX adapters use. They are here because kubernetes/website is
|
|
7
|
+
* the testbed and because several are extremely common (`glossary_tooltip`
|
|
8
|
+
* alone is 1,266 uses), so leaving them unmapped would dominate the ledger.
|
|
9
|
+
*
|
|
10
|
+
* Counts are measured in `content/en`.
|
|
11
|
+
*/
|
|
12
|
+
import { type ShortcodeRegistry } from "./registry.js";
|
|
13
|
+
export declare const KUBERNETES_SHORTCODES: ShortcodeRegistry;
|
|
14
|
+
//# sourceMappingURL=kubernetes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kubernetes.d.ts","sourceRoot":"","sources":["../src/kubernetes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAA6B,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAWlF,eAAO,MAAM,qBAAqB,EAAE,iBAkKnC,CAAC"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kubernetes site shortcodes.
|
|
3
|
+
*
|
|
4
|
+
* These are defined in `kubernetes/website/layouts/shortcodes/`, not in Hugo
|
|
5
|
+
* or Docsy, so they belong in a SITE layer rather than the core — the same
|
|
6
|
+
* separation the MDX adapters use. They are here because kubernetes/website is
|
|
7
|
+
* the testbed and because several are extremely common (`glossary_tooltip`
|
|
8
|
+
* alone is 1,266 uses), so leaving them unmapped would dominate the ledger.
|
|
9
|
+
*
|
|
10
|
+
* Counts are measured in `content/en`.
|
|
11
|
+
*/
|
|
12
|
+
import { arg, directive } from "./registry.js";
|
|
13
|
+
import { lookupParam } from "./config.js";
|
|
14
|
+
/** `stable` | `beta` | `alpha` | `deprecated` → a callout type. */
|
|
15
|
+
const STATE_TYPES = {
|
|
16
|
+
stable: "success",
|
|
17
|
+
beta: "info",
|
|
18
|
+
alpha: "warning",
|
|
19
|
+
deprecated: "caution",
|
|
20
|
+
};
|
|
21
|
+
export const KUBERNETES_SHORTCODES = {
|
|
22
|
+
// 1,162 uses — the single most structurally important one.
|
|
23
|
+
//
|
|
24
|
+
// It returns the TEXT ONLY. The source already supplies the hashes:
|
|
25
|
+
// `## {{% heading "whatsnext" %}}` — measured, 1,161 of 1,162 calls sit
|
|
26
|
+
// after a `#` run on the same line. Emitting `## Text` here produced
|
|
27
|
+
// `## ## Whatsnext` on every one of them, which markdown then rendered as a
|
|
28
|
+
// heading whose visible text began with two hashes. Caught only by looking
|
|
29
|
+
// at a real exported page; no fixture would have suggested it.
|
|
30
|
+
heading: (node, ctx) => {
|
|
31
|
+
const name = arg(node.args, "name") ?? "";
|
|
32
|
+
if (!name) {
|
|
33
|
+
ctx.report({
|
|
34
|
+
shortcode: "heading",
|
|
35
|
+
action: "degraded",
|
|
36
|
+
note: "heading had no name argument",
|
|
37
|
+
line: node.line,
|
|
38
|
+
});
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
// The argument is a translation KEY (`whatsnext`, `prerequisites`); the
|
|
42
|
+
// rendered text comes from the site's i18n files. Title-casing the key is
|
|
43
|
+
// a readable, honest approximation and is recorded as one.
|
|
44
|
+
const text = name
|
|
45
|
+
.replace(/[_-]+/g, " ")
|
|
46
|
+
.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
47
|
+
ctx.report({
|
|
48
|
+
shortcode: "heading",
|
|
49
|
+
action: "degraded",
|
|
50
|
+
note: `i18n heading key "${name}" rendered as "${text}" — the translated string lives in the site's i18n files`,
|
|
51
|
+
line: node.line,
|
|
52
|
+
});
|
|
53
|
+
return text;
|
|
54
|
+
},
|
|
55
|
+
// 1,266 uses. A glossary term with a hover definition. The tooltip is a
|
|
56
|
+
// theme affordance; the LINK and the text are the content.
|
|
57
|
+
glossary_tooltip: (node) => {
|
|
58
|
+
const text = arg(node.args, "text") ?? node.args.named.term_id ?? "";
|
|
59
|
+
const term = node.args.named.term_id;
|
|
60
|
+
return term ? `[${text}](/docs/reference/glossary/?term=${term})` : text;
|
|
61
|
+
},
|
|
62
|
+
// 38 uses. Inlines a glossary term's long description.
|
|
63
|
+
glossary_definition: (node, ctx) => {
|
|
64
|
+
const term = node.args.named.term_id ?? "";
|
|
65
|
+
ctx.report({
|
|
66
|
+
shortcode: "glossary_definition",
|
|
67
|
+
action: "degraded",
|
|
68
|
+
note: `glossary definition for "${term}" is generated from the site's glossary data files — emitted as a link`,
|
|
69
|
+
line: node.line,
|
|
70
|
+
});
|
|
71
|
+
return term ? `[${term}](/docs/reference/glossary/?term=${term})` : "";
|
|
72
|
+
},
|
|
73
|
+
// 402 uses. `{{< feature-state for_k8s_version="v1.29" state="stable" >}}`
|
|
74
|
+
// or the newer `feature_gate_name=` form.
|
|
75
|
+
"feature-state": (node, ctx) => {
|
|
76
|
+
const state = (node.args.named.state ?? "").toLowerCase();
|
|
77
|
+
const version = node.args.named.for_k8s_version;
|
|
78
|
+
const gate = node.args.named.feature_gate_name;
|
|
79
|
+
if (gate && !state) {
|
|
80
|
+
// The state is looked up from the site's feature-gate data files.
|
|
81
|
+
ctx.report({
|
|
82
|
+
shortcode: "feature-state",
|
|
83
|
+
action: "degraded",
|
|
84
|
+
note: `stability of feature gate "${gate}" comes from the site's data files — emitted without a state`,
|
|
85
|
+
line: node.line,
|
|
86
|
+
});
|
|
87
|
+
return directive("info", "", `Feature gate: \`${gate}\``);
|
|
88
|
+
}
|
|
89
|
+
const type = STATE_TYPES[state] ?? "info";
|
|
90
|
+
const label = [state && state.toUpperCase(), version].filter(Boolean).join(" · ");
|
|
91
|
+
return directive(type, "", `Feature state: ${label || "unspecified"}`);
|
|
92
|
+
},
|
|
93
|
+
// 298 uses. Version-skew arithmetic against the site params
|
|
94
|
+
// (`{{< skew currentVersion >}}`, `{{< skew latestVersionAddMinor -1 >}}`).
|
|
95
|
+
skew: (node, ctx) => {
|
|
96
|
+
const key = node.args.positional[0] ?? "currentVersion";
|
|
97
|
+
const value = lookupParam(ctx.config.params, key) ??
|
|
98
|
+
lookupParam(ctx.config.params, "version") ??
|
|
99
|
+
lookupParam(ctx.config.params, "currentVersion");
|
|
100
|
+
if (value === undefined) {
|
|
101
|
+
ctx.report({
|
|
102
|
+
shortcode: "skew",
|
|
103
|
+
action: "degraded",
|
|
104
|
+
note: `version-skew value "${key}" is computed by the site from Hugo params — substituted as empty`,
|
|
105
|
+
line: node.line,
|
|
106
|
+
});
|
|
107
|
+
return "";
|
|
108
|
+
}
|
|
109
|
+
if (node.args.positional.length > 1) {
|
|
110
|
+
ctx.report({
|
|
111
|
+
shortcode: "skew",
|
|
112
|
+
action: "degraded",
|
|
113
|
+
note: `version arithmetic (${node.args.positional.join(" ")}) is not evaluated — emitted as the base version`,
|
|
114
|
+
line: node.line,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
118
|
+
},
|
|
119
|
+
// 365 uses. Embeds a file from `content/<lang>/examples/` as a code block.
|
|
120
|
+
// The file IS the content, so failing to read it is a real loss.
|
|
121
|
+
code_sample: (node, ctx) => {
|
|
122
|
+
const file = arg(node.args, "file") ?? "";
|
|
123
|
+
const lang = node.args.named.language ?? guessLanguage(file);
|
|
124
|
+
const content = ctx.readContentFile?.(`examples/${file.replace(/^\//, "")}`, ctx.file);
|
|
125
|
+
if (content === undefined) {
|
|
126
|
+
ctx.report({
|
|
127
|
+
shortcode: "code_sample",
|
|
128
|
+
action: "degraded",
|
|
129
|
+
note: `could not read example file "${file}" — emitted as a link`,
|
|
130
|
+
line: node.line,
|
|
131
|
+
});
|
|
132
|
+
return `[${file}](/examples/${file.replace(/^\//, "")})`;
|
|
133
|
+
}
|
|
134
|
+
const body = content.replace(/\n+$/, "");
|
|
135
|
+
const fence = "`".repeat(Math.max(3, ...[...body.matchAll(/`{3,}/g)].map((m) => m[0].length + 1)));
|
|
136
|
+
return `${fence}${lang}\n${body}\n${fence}`;
|
|
137
|
+
},
|
|
138
|
+
// Older alias for the same thing.
|
|
139
|
+
codenew: (node, ctx) => KUBERNETES_SHORTCODES.code_sample(node, ctx),
|
|
140
|
+
// 96 uses. A version guard around content; for a static export the content
|
|
141
|
+
// inside is what the reader wants.
|
|
142
|
+
"version-check": (node, ctx) => {
|
|
143
|
+
ctx.report({
|
|
144
|
+
shortcode: "version-check",
|
|
145
|
+
action: "stripped",
|
|
146
|
+
note: "runtime version guard — has no meaning in a static export",
|
|
147
|
+
line: node.line,
|
|
148
|
+
});
|
|
149
|
+
return node.inner ? ctx.translate(node.inner) : null;
|
|
150
|
+
},
|
|
151
|
+
// 45 uses. A standing disclaimer about third-party content.
|
|
152
|
+
"thirdparty-content": (node, ctx) => directive("note", "", node.inner
|
|
153
|
+
? ctx.translate(node.inner)
|
|
154
|
+
: "This section links to third party projects that provide functionality required by Kubernetes. The Kubernetes project authors are not responsible for those projects."),
|
|
155
|
+
// 17 uses. A link into the generated API reference.
|
|
156
|
+
"api-reference": (node, ctx) => {
|
|
157
|
+
const kind = node.args.named.kind ?? "";
|
|
158
|
+
const placeholder = node.args.named.placeholder ?? kind;
|
|
159
|
+
ctx.report({
|
|
160
|
+
shortcode: "api-reference",
|
|
161
|
+
action: "degraded",
|
|
162
|
+
note: `generated API reference for "${kind}" — emitted as a link, the generator is a separate Go tool`,
|
|
163
|
+
line: node.line,
|
|
164
|
+
});
|
|
165
|
+
return kind ? `[${placeholder}](/docs/reference/kubernetes-api/)` : "";
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
/** Language for a code sample, from its file extension. */
|
|
169
|
+
function guessLanguage(file) {
|
|
170
|
+
const ext = file.split(".").pop()?.toLowerCase() ?? "";
|
|
171
|
+
const map = {
|
|
172
|
+
yaml: "yaml",
|
|
173
|
+
yml: "yaml",
|
|
174
|
+
json: "json",
|
|
175
|
+
sh: "shell",
|
|
176
|
+
bash: "shell",
|
|
177
|
+
go: "go",
|
|
178
|
+
py: "python",
|
|
179
|
+
js: "javascript",
|
|
180
|
+
ts: "typescript",
|
|
181
|
+
xml: "xml",
|
|
182
|
+
toml: "toml",
|
|
183
|
+
};
|
|
184
|
+
return map[ext] ?? "";
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=kubernetes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kubernetes.js","sourceRoot":"","sources":["../src/kubernetes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,GAAG,EAAa,SAAS,EAA0B,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,mEAAmE;AACnE,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,SAAS;IACjB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,SAAS;IAChB,UAAU,EAAE,SAAS;CACtB,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAsB;IACtD,2DAA2D;IAC3D,EAAE;IACF,oEAAoE;IACpE,wEAAwE;IACxE,qEAAqE;IACrE,4EAA4E;IAC5E,2EAA2E;IAC3E,+DAA+D;IAC/D,OAAO,EAAE,CAAC,IAAI,EAAE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CAAC,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IACvD,MAAM,GAAG,GAA2B;QAClC,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,MAAM;QACX,IAAI,EAAE,MAAM;QACZ,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,OAAO;QACb,EAAE,EAAE,IAAI;QACR,EAAE,EAAE,QAAQ;QACZ,EAAE,EAAE,YAAY;QAChB,EAAE,EAAE,YAAY;QAChB,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,MAAM;KACb,CAAC;IACF,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;AACxB,CAAC"}
|
package/dist/nav.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { NavItem } from "@dogsbay/types";
|
|
2
|
+
export interface HugoPage {
|
|
3
|
+
/** Absolute path of the source file. */
|
|
4
|
+
file: string;
|
|
5
|
+
/** Path relative to the content root, e.g. `docs/concepts/pods.md`. */
|
|
6
|
+
rel: string;
|
|
7
|
+
/** Site-root-relative slug with no leading or trailing slash. */
|
|
8
|
+
slug: string;
|
|
9
|
+
title: string;
|
|
10
|
+
/** Nav label — `linkTitle` when present, else `title`. */
|
|
11
|
+
linkTitle: string;
|
|
12
|
+
weight?: number;
|
|
13
|
+
frontmatter: Record<string, unknown>;
|
|
14
|
+
/** A `_index.md`: this page IS a section and has children. */
|
|
15
|
+
isSection: boolean;
|
|
16
|
+
/** A `index.md` leaf bundle: the directory is one page with co-located assets. */
|
|
17
|
+
isLeafBundle: boolean;
|
|
18
|
+
/** Whether the page asked not to be listed in nav (`_build`/`draft`/`headless`). */
|
|
19
|
+
hidden: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The source is an `.html` content page — Go template + HTML, with no
|
|
22
|
+
* markdown to import. It is still a PAGE (it has a title, a slug and a place
|
|
23
|
+
* in the nav), so it is collected and emitted as a stub rather than
|
|
24
|
+
* vanishing: kubernetes' own home is `content/en/_index.html`, and skipping
|
|
25
|
+
* it left the site with no root at all.
|
|
26
|
+
*/
|
|
27
|
+
unrenderable: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* An include FRAGMENT, not a routable page.
|
|
30
|
+
*
|
|
31
|
+
* Hugo has no formal marker for this, but the convention is universal: a
|
|
32
|
+
* file under `includes/` exists to be pulled in by `{{< include >}}`, and
|
|
33
|
+
* emitting it as its own page publishes the same text twice — once inside
|
|
34
|
+
* each of the 131 pages that include it, and once on a URL nobody links to.
|
|
35
|
+
*/
|
|
36
|
+
fragment: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Split Hugo frontmatter: `---` YAML, `+++` TOML, or `{ }` JSON. */
|
|
39
|
+
export declare function splitFrontmatter(source: string): {
|
|
40
|
+
frontmatter: Record<string, unknown>;
|
|
41
|
+
body: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Walk a Hugo content directory into a flat page list.
|
|
45
|
+
*
|
|
46
|
+
* Ordinary markdown only — `.html` content pages exist in Hugo but carry no
|
|
47
|
+
* markdown to import, and pulling them in would emit pages of raw template.
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Apply a Hugo `[permalinks]` pattern to a page.
|
|
51
|
+
*
|
|
52
|
+
* Tokens Hugo defines that matter for docs corpora: `:section`, `:sections`,
|
|
53
|
+
* `:year`, `:month`, `:day`, `:slug`, `:title`, `:filename`, `:contentbasename`.
|
|
54
|
+
* An unknown token is left in place rather than silently emitting an empty
|
|
55
|
+
* segment — a wrong URL you can see beats one you cannot.
|
|
56
|
+
*/
|
|
57
|
+
export declare function applyPermalink(pattern: string, ctx: {
|
|
58
|
+
section: string;
|
|
59
|
+
sections: string[];
|
|
60
|
+
slug: string;
|
|
61
|
+
filename: string;
|
|
62
|
+
title: string;
|
|
63
|
+
date?: Date;
|
|
64
|
+
}): string;
|
|
65
|
+
export declare function collectHugoPages(contentRoot: string, permalinks?: Record<string, string>, sectionPermalinks?: Record<string, string>): HugoPage[];
|
|
66
|
+
/**
|
|
67
|
+
* Build the nav tree from the page set.
|
|
68
|
+
*
|
|
69
|
+
* Ordering is Hugo's: `weight` ascending, then title. Pages with no weight
|
|
70
|
+
* sort AFTER weighted ones — Hugo treats a missing weight as 0 and then falls
|
|
71
|
+
* back to date/title, but for docs the practical rule authors rely on is
|
|
72
|
+
* "weighted items lead, the rest follow alphabetically".
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildHugoNav(pages: HugoPage[], hrefPrefix?: string): NavItem[];
|
|
75
|
+
/**
|
|
76
|
+
* Resolve a `{{< ref >}}` / `{{< relref >}}` target against the page set.
|
|
77
|
+
*
|
|
78
|
+
* 2,570 calls in the kubernetes corpus — the most common shortcode by a wide
|
|
79
|
+
* margin, and every unresolved one is a broken link. Hugo accepts a lot of
|
|
80
|
+
* forms for the same page:
|
|
81
|
+
*
|
|
82
|
+
* "/docs/concepts/_index.md" root-relative with the file name
|
|
83
|
+
* "docs/concepts" root-relative, no extension
|
|
84
|
+
* "pods.md" relative to the calling page
|
|
85
|
+
* "#anchor" / "page.md#anchor" with a fragment
|
|
86
|
+
*/
|
|
87
|
+
export declare function makeRefResolver(pages: HugoPage[], hrefPrefix?: string): (target: string, from?: string) => string | undefined;
|
|
88
|
+
//# sourceMappingURL=nav.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nav.d.ts","sourceRoot":"","sources":["../src/nav.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,WAAW,QAAQ;IACvB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAC;IACZ,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;I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