@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
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kubernetes/website adapter: that site's own 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 { attributeRef, bakeIntent, define, expressionRef, includeRef, isAttributeName, templateBlock, templateRef, withoutMarkerChars } from "../intent.js";
|
|
13
|
+
import { arg, directive } from "../registry.js";
|
|
14
|
+
import { splitFrontmatter } from "../nav.js";
|
|
15
|
+
import { lookupParam } from "../config.js";
|
|
16
|
+
/** `stable` | `beta` | `alpha` | `deprecated` → a callout type. */
|
|
17
|
+
/** Where kubernetes keeps one page per feature gate, with its stages in the front matter. */
|
|
18
|
+
const FEATURE_GATES_DIR = "docs/reference/command-line-tools-reference/feature-gates";
|
|
19
|
+
/** The data file the pages read the gates from (`data.feature_gates`). */
|
|
20
|
+
const FEATURE_GATES_DATA = "feature_gates";
|
|
21
|
+
// One reading of the gates' pages per import: the import's own listing function is the key (a
|
|
22
|
+
// caller with another site, or none, is another key; keyed by the config, a second site that
|
|
23
|
+
// shared a config object got the first one's gates).
|
|
24
|
+
const gatesOf = new WeakMap();
|
|
25
|
+
/** The site's feature gates, from their pages. A page whose stages cannot be read is left out. */
|
|
26
|
+
function readGates(ctx) {
|
|
27
|
+
const gates = { all: new Map(), bodies: new Map(), data: Object.create(null), described: false };
|
|
28
|
+
if (!ctx.listContentDir)
|
|
29
|
+
return gates;
|
|
30
|
+
const cached = gatesOf.get(ctx.listContentDir);
|
|
31
|
+
if (cached)
|
|
32
|
+
return cached;
|
|
33
|
+
gatesOf.set(ctx.listContentDir, gates);
|
|
34
|
+
const text = (v) => typeof v === "string" || typeof v === "number" ? String(v).trim() : undefined;
|
|
35
|
+
const found = new Map();
|
|
36
|
+
for (const file of ctx.listContentDir(FEATURE_GATES_DIR) ?? []) {
|
|
37
|
+
const { frontmatter, body } = splitFrontmatter(file.text);
|
|
38
|
+
const title = text(frontmatter.title);
|
|
39
|
+
if (!title || !Array.isArray(frontmatter.stages))
|
|
40
|
+
continue;
|
|
41
|
+
const stages = [];
|
|
42
|
+
for (const raw of frontmatter.stages) {
|
|
43
|
+
if (!raw || typeof raw !== "object")
|
|
44
|
+
continue;
|
|
45
|
+
const s = raw;
|
|
46
|
+
const stage = text(s.stage);
|
|
47
|
+
const fromVersion = text(s.fromVersion);
|
|
48
|
+
// what a page prints goes into Markdown and into a data file: plain words and numbers only
|
|
49
|
+
if (!stage || !fromVersion || !/^[A-Za-z]+$/.test(stage) || !/^[\w.-]+$/.test(fromVersion))
|
|
50
|
+
continue;
|
|
51
|
+
const toVersion = text(s.toVersion);
|
|
52
|
+
stages.push({
|
|
53
|
+
stage,
|
|
54
|
+
fromVersion,
|
|
55
|
+
...(toVersion && /^[\w.-]+$/.test(toVersion) ? { toVersion } : {}),
|
|
56
|
+
// the site's table shows a dash for a stage that does not say
|
|
57
|
+
defaultValue: typeof s.defaultValue === "boolean" ? s.defaultValue : null,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (stages.length === 0 || found.has(title))
|
|
61
|
+
continue;
|
|
62
|
+
found.set(title, { stages, ...(frontmatter.removed ? { removed: true } : {}) });
|
|
63
|
+
gates.bodies.set(title, body);
|
|
64
|
+
}
|
|
65
|
+
for (const name of [...found.keys()].sort()) {
|
|
66
|
+
gates.all.set(name, found.get(name));
|
|
67
|
+
if (isAttributeName(name))
|
|
68
|
+
gates.data[name] = found.get(name);
|
|
69
|
+
}
|
|
70
|
+
return gates;
|
|
71
|
+
}
|
|
72
|
+
/** The site's feature gates by name. */
|
|
73
|
+
const featureGates = (ctx) => readGates(ctx).all;
|
|
74
|
+
/** The gates as the data file holds them: by name, in name order. */
|
|
75
|
+
const featureGateData = (ctx) => readGates(ctx).data;
|
|
76
|
+
/**
|
|
77
|
+
* The gates with each one's description: its page's text, as Markdown. Read once per import, by
|
|
78
|
+
* the first page that prints descriptions (what its shortcodes report is reported there).
|
|
79
|
+
*/
|
|
80
|
+
function describedGates(ctx) {
|
|
81
|
+
const gates = readGates(ctx);
|
|
82
|
+
if (gates.described)
|
|
83
|
+
return gates;
|
|
84
|
+
gates.described = true;
|
|
85
|
+
for (const [name, gate] of gates.all) {
|
|
86
|
+
// a description is data: its shortcodes give their values, and it holds none of the import's marks
|
|
87
|
+
const translated = (ctx.translateData ?? ctx.translate)((gates.bodies.get(name) ?? "").replace(/\r\n?/g, "\n"));
|
|
88
|
+
const description = withoutMarkerChars(ctx.intent ? bakeIntent(translated, ctx.intent.store) : translated)
|
|
89
|
+
.replace(/[ \t]+$/gm, "")
|
|
90
|
+
.trim();
|
|
91
|
+
if (description)
|
|
92
|
+
gate.description = description;
|
|
93
|
+
}
|
|
94
|
+
return gates;
|
|
95
|
+
}
|
|
96
|
+
/** Where kubernetes keeps one page per glossary term, and the data file the pages read. */
|
|
97
|
+
const GLOSSARY_DIR = "docs/reference/glossary";
|
|
98
|
+
const GLOSSARY_DATA = "glossary";
|
|
99
|
+
const glossaryOf = new WeakMap();
|
|
100
|
+
/** The site's glossary: each term's page by its id (the page's file name). */
|
|
101
|
+
function glossary(ctx) {
|
|
102
|
+
const none = { bodies: new Map(), data: Object.create(null), state: new Map() };
|
|
103
|
+
if (!ctx.listContentDir)
|
|
104
|
+
return none;
|
|
105
|
+
let terms = glossaryOf.get(ctx.listContentDir);
|
|
106
|
+
if (!terms) {
|
|
107
|
+
terms = none;
|
|
108
|
+
glossaryOf.set(ctx.listContentDir, terms);
|
|
109
|
+
for (const file of ctx.listContentDir(GLOSSARY_DIR) ?? []) {
|
|
110
|
+
const id = file.name.replace(/\.md$/, "");
|
|
111
|
+
// an id a page can write as `data.glossary["id"]`
|
|
112
|
+
if (id.startsWith("_") || !/^[A-Za-z0-9_-]+$/.test(id))
|
|
113
|
+
continue;
|
|
114
|
+
terms.bodies.set(id, splitFrontmatter(file.text).body);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return terms;
|
|
118
|
+
}
|
|
119
|
+
/** Markdown that is not a paragraph of text: a block of its own kind, or a paragraph that opens one. */
|
|
120
|
+
const NOT_A_PARAGRAPH = /^(?: {4}|\t|#{1,6}(?:\s|$)|[-*+] |\d+[.)] |>|\||<)|^[ \t]*(?:`{3,}|~{3,}|:{3,})/m;
|
|
121
|
+
/**
|
|
122
|
+
* One term: its page's text translated, shortcodes as values, split into its first paragraph
|
|
123
|
+
* and the rest. Read once per import. Undefined for a term with no page or no text, one whose
|
|
124
|
+
* page does not start with a paragraph (the site's shortcode takes the first paragraph; a code
|
|
125
|
+
* block or a callout cut at its first blank line would take the host page into it), and one
|
|
126
|
+
* that is being read (a term that prints its own definition).
|
|
127
|
+
*/
|
|
128
|
+
function glossaryTerm(ctx, id) {
|
|
129
|
+
const terms = glossary(ctx);
|
|
130
|
+
const body = terms.bodies.get(id);
|
|
131
|
+
if (body === undefined || terms.state.get(id) === "reading")
|
|
132
|
+
return undefined;
|
|
133
|
+
if (terms.state.get(id) === "read")
|
|
134
|
+
return Object.hasOwn(terms.data, id) ? terms.data[id] : undefined;
|
|
135
|
+
terms.state.set(id, "reading");
|
|
136
|
+
try {
|
|
137
|
+
// comments are not text (`<!--more-->` ends the summary in Hugo)
|
|
138
|
+
const source = body.replace(/\r\n?/g, "\n").replace(/<!--[\s\S]*?-->/g, "");
|
|
139
|
+
const translated = (ctx.translateData ?? ctx.translate)(source);
|
|
140
|
+
const text = withoutMarkerChars(ctx.intent ? bakeIntent(translated, ctx.intent.store) : translated)
|
|
141
|
+
.replace(/[ \t]+$/gm, "")
|
|
142
|
+
.replace(/^\s*\n/, "")
|
|
143
|
+
.trimEnd();
|
|
144
|
+
const gap = text.search(/\n\s*\n/);
|
|
145
|
+
const first = gap === -1 ? text : text.slice(0, gap);
|
|
146
|
+
const definition = first.replace(/^ {1,3}/, "");
|
|
147
|
+
const more = gap === -1 ? "" : text.slice(gap).replace(/^\s*\n/, "").trimEnd();
|
|
148
|
+
if (definition && !NOT_A_PARAGRAPH.test(first))
|
|
149
|
+
terms.data[id] = { definition, ...(more ? { more } : {}) };
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// a term whose page cannot be translated is a term with no definition; the others are read
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
terms.state.set(id, "read");
|
|
156
|
+
}
|
|
157
|
+
return Object.hasOwn(terms.data, id) ? terms.data[id] : undefined;
|
|
158
|
+
}
|
|
159
|
+
/** Every term, as the data file holds them: by id, in id order. */
|
|
160
|
+
function glossaryData(ctx) {
|
|
161
|
+
const terms = glossary(ctx);
|
|
162
|
+
for (const id of terms.bodies.keys())
|
|
163
|
+
glossaryTerm(ctx, id);
|
|
164
|
+
const sorted = Object.create(null);
|
|
165
|
+
for (const id of Object.keys(terms.data).sort())
|
|
166
|
+
sorted[id] = terms.data[id];
|
|
167
|
+
return sorted;
|
|
168
|
+
}
|
|
169
|
+
/** Text a template page's own text can hold: no template syntax, no code span, no control character. */
|
|
170
|
+
const plainLabel = (text) => !/[{}%`\u0000-\u001f\u007f\u2028\u2029\uFDD0-\uFDD3]/.test(text);
|
|
171
|
+
/** Inline code, as the template pages' `code` filter writes it. */
|
|
172
|
+
function codeSpan(text) {
|
|
173
|
+
const longest = Math.max(0, ...(text.match(/`+/g) ?? []).map((run) => run.length));
|
|
174
|
+
const fence = "`".repeat(longest + 1);
|
|
175
|
+
return longest > 0 ? `${fence} ${text} ${fence}` : `\`${text}\``;
|
|
176
|
+
}
|
|
177
|
+
/** Text as one cell of a Markdown table. */
|
|
178
|
+
const cell = (text) => text.replace(/\s+/g, " ").replace(/\|/g, "\\|").trim();
|
|
179
|
+
/** One line of a Markdown table, from cells. */
|
|
180
|
+
const row = (cells) => `| ${cells.join(" | ")} |`;
|
|
181
|
+
const GATE_STAGES = ["alpha", "beta", "stable", "deprecated"];
|
|
182
|
+
/** The name the stage labels have on a template page. */
|
|
183
|
+
const STAGE_LABELS = "feature_gate_stage_labels";
|
|
184
|
+
/** `{{< feature-gate-table >}}`: one row for each stage of each gate the call asks for. */
|
|
185
|
+
function featureGateTable(node, ctx) {
|
|
186
|
+
const gates = readGates(ctx);
|
|
187
|
+
const removedOnly = !!node.args.named["show-removed"];
|
|
188
|
+
const include = node.args.named.include ?? "";
|
|
189
|
+
// as the site's shortcode: gates still in alpha or beta, or the ones past it
|
|
190
|
+
const early = include.includes("alpha") || include.includes("beta");
|
|
191
|
+
const graduated = (gate) => gate.stages.some((s) => s.stage === "stable" || s.stage === "deprecated");
|
|
192
|
+
const shown = (gate) => (removedOnly ? !!gate.removed : !gate.removed && graduated(gate) !== early);
|
|
193
|
+
const t = (key, fallback) => ctx.i18n?.[key] ?? fallback;
|
|
194
|
+
// (no prototype: a stage called `constructor` is not a label)
|
|
195
|
+
const labels = Object.create(null);
|
|
196
|
+
for (const stage of GATE_STAGES)
|
|
197
|
+
labels[stage] = cell(t(`feature_gate_stage_${stage}`, stage));
|
|
198
|
+
const headers = [
|
|
199
|
+
t("feature_gate_table_header_feature", "Feature"),
|
|
200
|
+
t("feature_gate_table_header_default", "Default"),
|
|
201
|
+
t("feature_gate_table_header_stage", "Stage"),
|
|
202
|
+
removedOnly ? t("feature_gate_table_header_from", "From") : t("feature_gate_table_header_since", "Since"),
|
|
203
|
+
removedOnly ? t("feature_gate_table_header_to", "To") : t("feature_gate_table_header_until", "Until"),
|
|
204
|
+
];
|
|
205
|
+
const head = `${row(headers.map(cell))}\n|---|---|---|---|---|`;
|
|
206
|
+
const rows = [];
|
|
207
|
+
for (const [name, gate] of gates.all) {
|
|
208
|
+
if (!shown(gate))
|
|
209
|
+
continue;
|
|
210
|
+
for (const s of gate.stages) {
|
|
211
|
+
rows.push(row([
|
|
212
|
+
codeSpan(name),
|
|
213
|
+
s.defaultValue === null ? "–" : codeSpan(String(s.defaultValue)),
|
|
214
|
+
labels[s.stage] ?? s.stage,
|
|
215
|
+
s.fromVersion,
|
|
216
|
+
s.toVersion ?? "–",
|
|
217
|
+
]));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (gates.all.size === 0) {
|
|
221
|
+
ctx.report({ shortcode: node.name, action: "degraded", note: `no feature gate pages were found under ${FEATURE_GATES_DIR} — the table has no rows`, line: node.line });
|
|
222
|
+
}
|
|
223
|
+
const baked = [head, ...rows].join("\n");
|
|
224
|
+
// Keeping intent: the page loops over the gates' data file, so a new gate or a new stage is
|
|
225
|
+
// a change to the data. Every gate must be in the file, and every label must read as itself
|
|
226
|
+
// in the page's template.
|
|
227
|
+
const intent = ctx.intent;
|
|
228
|
+
const texts = [...headers, ...Object.values(labels)];
|
|
229
|
+
if (!intent || gates.all.size === 0 || Object.keys(gates.data).length !== gates.all.size || !texts.every(plainLabel))
|
|
230
|
+
return baked;
|
|
231
|
+
intent.store.data.set(FEATURE_GATES_DATA, gates.data);
|
|
232
|
+
define(intent, STAGE_LABELS, `{${GATE_STAGES.map((stage) => `${JSON.stringify(stage)}: ${JSON.stringify(labels[stage])}`).join(", ")}}`);
|
|
233
|
+
const past = `(gate.stages | selectattr("stage", "in", ["stable", "deprecated"]) | list | length)`;
|
|
234
|
+
const test = removedOnly
|
|
235
|
+
? `gate.removed | default(false)`
|
|
236
|
+
: `not (gate.removed | default(false)) and ${past} ${early ? "== 0" : "> 0"}`;
|
|
237
|
+
const template = [
|
|
238
|
+
head,
|
|
239
|
+
`{% for name, gate in data.${FEATURE_GATES_DATA} | items -%}`,
|
|
240
|
+
`{% if ${test} -%}`,
|
|
241
|
+
`{% for s in gate.stages -%}`,
|
|
242
|
+
`| {{ name | code }} | {{ "–" if s.defaultValue is none else (("true" if s.defaultValue else "false") | code) }} | {{ ${STAGE_LABELS}.get(s.stage, s.stage) }} | {{ s.fromVersion }} | {{ s.toVersion | default("–") }} |`,
|
|
243
|
+
`{% endfor -%}`,
|
|
244
|
+
`{% endif -%}`,
|
|
245
|
+
`{% endfor %}`,
|
|
246
|
+
].join("\n");
|
|
247
|
+
return templateBlock(intent, template, baked);
|
|
248
|
+
}
|
|
249
|
+
/** `{{< feature-gate-list >}}`: each gate the call asks for, with its description. */
|
|
250
|
+
function featureGateList(node, ctx) {
|
|
251
|
+
const gates = describedGates(ctx);
|
|
252
|
+
const removedToo = !!node.args.named["show-removed"];
|
|
253
|
+
const include = node.args.named.include ?? "";
|
|
254
|
+
// as the site's shortcode: a stage is asked for by its name, and stable also by "ga"
|
|
255
|
+
const wanted = GATE_STAGES.filter((stage) => include.includes(stage) || (stage === "stable" && include.includes("ga")));
|
|
256
|
+
const shown = (gate) => gate.removed ? removedToo : gate.stages.some((s) => wanted.includes(s.stage));
|
|
257
|
+
const entries = [];
|
|
258
|
+
for (const [name, gate] of gates.all) {
|
|
259
|
+
if (!shown(gate) || !gate.description)
|
|
260
|
+
continue;
|
|
261
|
+
// a definition's text sits four columns in
|
|
262
|
+
entries.push(`${codeSpan(name)}\n: ${gate.description.replace(/\n(?=[^\n])/g, "\n ")}`);
|
|
263
|
+
}
|
|
264
|
+
if (gates.all.size === 0) {
|
|
265
|
+
ctx.report({ shortcode: node.name, action: "degraded", note: `no feature gate pages were found under ${FEATURE_GATES_DIR} — the list is empty`, line: node.line });
|
|
266
|
+
}
|
|
267
|
+
const baked = entries.join("\n\n");
|
|
268
|
+
const intent = ctx.intent;
|
|
269
|
+
if (!intent || gates.all.size === 0 || Object.keys(gates.data).length !== gates.all.size)
|
|
270
|
+
return baked;
|
|
271
|
+
intent.store.data.set(FEATURE_GATES_DATA, gates.data);
|
|
272
|
+
const inStages = `(gate.stages | selectattr("stage", "in", ${JSON.stringify(wanted)}) | list | length > 0)`;
|
|
273
|
+
const test = removedToo
|
|
274
|
+
? `(gate.removed | default(false)) or ${inStages}`
|
|
275
|
+
: `not (gate.removed | default(false)) and ${inStages}`;
|
|
276
|
+
const template = [
|
|
277
|
+
`{% for name, gate in data.${FEATURE_GATES_DATA} | items -%}`,
|
|
278
|
+
`{% if gate.description | default("") and (${test}) -%}`,
|
|
279
|
+
`{{ name | code }}`,
|
|
280
|
+
`: {{ gate.description | indent(4) }}`,
|
|
281
|
+
``,
|
|
282
|
+
`{% endif -%}`,
|
|
283
|
+
`{% endfor %}`,
|
|
284
|
+
].join("\n");
|
|
285
|
+
return templateBlock(intent, template, baked);
|
|
286
|
+
}
|
|
287
|
+
/** The site's release schedule (its `schedule-builder` tool writes it), and the data file the pages read. */
|
|
288
|
+
const RELEASE_SCHEDULE_FILE = "releases/schedule";
|
|
289
|
+
const RELEASE_SCHEDULE_DATA = "release_schedule";
|
|
290
|
+
const schedulesOf = new WeakMap();
|
|
291
|
+
/** A value of the schedule a page may print: a version or a date, as text. */
|
|
292
|
+
const scheduleText = (v, decimals) => {
|
|
293
|
+
const text = typeof v === "number" && Number.isFinite(v) ? (decimals === undefined ? String(v) : v.toFixed(decimals)) : v;
|
|
294
|
+
return typeof text === "string" && /^[\w.:-]+$/.test(text) ? text : undefined;
|
|
295
|
+
};
|
|
296
|
+
/**
|
|
297
|
+
* One release or one patch of the schedule: its `release`, and its other fields that are plain
|
|
298
|
+
* versions and dates. Anything else in the site's file (nested values, free text) is left out:
|
|
299
|
+
* a page prints what the data file holds, so the file holds only what the import would print
|
|
300
|
+
* itself. Undefined for an entry with no usable `release`.
|
|
301
|
+
*/
|
|
302
|
+
function scheduleEntry(raw, decimals) {
|
|
303
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
304
|
+
return undefined;
|
|
305
|
+
const release = scheduleText(raw.release, decimals);
|
|
306
|
+
if (release === undefined)
|
|
307
|
+
return undefined;
|
|
308
|
+
const entry = Object.assign(Object.create(null), { release });
|
|
309
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
310
|
+
if (key === "release" || !isAttributeName(key))
|
|
311
|
+
continue;
|
|
312
|
+
const text = scheduleText(value);
|
|
313
|
+
if (text !== undefined)
|
|
314
|
+
entry[key] = text;
|
|
315
|
+
}
|
|
316
|
+
return entry;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* The release schedule as the data file holds it: the site's file (its `schedule-builder` tool
|
|
320
|
+
* writes it) reduced to releases, their patches, and their versions and dates. A release
|
|
321
|
+
* written as a number (`1.4`) is the two-decimal text the site's shortcode compares.
|
|
322
|
+
*/
|
|
323
|
+
function releaseSchedule(ctx) {
|
|
324
|
+
if (!ctx.readSiteData)
|
|
325
|
+
return undefined;
|
|
326
|
+
const cached = schedulesOf.get(ctx.readSiteData);
|
|
327
|
+
if (cached !== undefined)
|
|
328
|
+
return cached ?? undefined;
|
|
329
|
+
const raw = ctx.readSiteData(RELEASE_SCHEDULE_FILE);
|
|
330
|
+
let schedule = null;
|
|
331
|
+
if (raw && typeof raw === "object" && Array.isArray(raw.schedules)) {
|
|
332
|
+
const schedules = [];
|
|
333
|
+
for (const item of raw.schedules.slice(0, 1000)) {
|
|
334
|
+
const entry = scheduleEntry(item, 2);
|
|
335
|
+
if (!entry)
|
|
336
|
+
continue;
|
|
337
|
+
const patches = item.previousPatches;
|
|
338
|
+
if (Array.isArray(patches)) {
|
|
339
|
+
entry.previousPatches = patches.slice(0, 1000).map((p) => scheduleEntry(p)).filter((p) => !!p);
|
|
340
|
+
}
|
|
341
|
+
schedules.push(entry);
|
|
342
|
+
}
|
|
343
|
+
schedule = { schedules };
|
|
344
|
+
}
|
|
345
|
+
schedulesOf.set(ctx.readSiteData, schedule);
|
|
346
|
+
return schedule ?? undefined;
|
|
347
|
+
}
|
|
348
|
+
const STATE_TYPES = {
|
|
349
|
+
stable: "success",
|
|
350
|
+
beta: "info",
|
|
351
|
+
alpha: "warning",
|
|
352
|
+
deprecated: "caution",
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* The version params as attributes: kubernetes writes `version = "v1.36"`, `{{< param >}}`
|
|
356
|
+
* prints that, and `{{< skew >}}` prints `1.36`. One attribute serves both when it holds the
|
|
357
|
+
* number and `param` writes the "v" in front, so the prefix is settled before any page is read
|
|
358
|
+
* (settled by whichever shortcode came first, the other form could not use the attribute).
|
|
359
|
+
*/
|
|
360
|
+
export function declareVersionAttributes(store, params) {
|
|
361
|
+
for (const name of ["latest", "version", "latestVersion", "currentVersion"]) {
|
|
362
|
+
const value = lookupParam(params, name);
|
|
363
|
+
if (value && /^v\d/.test(value) && !store.attributes.has(name))
|
|
364
|
+
store.prefixes.set(name, "v");
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
export const KUBERNETES_SHORTCODES = {
|
|
368
|
+
// 1,162 uses — the single most structurally important one.
|
|
369
|
+
//
|
|
370
|
+
// It returns the TEXT ONLY. The source already supplies the hashes:
|
|
371
|
+
// `## {{% heading "whatsnext" %}}` — measured, 1,161 of 1,162 calls sit
|
|
372
|
+
// after a `#` run on the same line. Emitting `## Text` here produced
|
|
373
|
+
// `## ## Whatsnext` on every one of them, which markdown then rendered as a
|
|
374
|
+
// heading whose visible text began with two hashes. Caught only by looking
|
|
375
|
+
// at a real exported page; no fixture would have suggested it.
|
|
376
|
+
heading: (node, ctx) => {
|
|
377
|
+
const name = arg(node.args, "name") ?? "";
|
|
378
|
+
if (!name) {
|
|
379
|
+
ctx.report({
|
|
380
|
+
shortcode: "heading",
|
|
381
|
+
action: "degraded",
|
|
382
|
+
note: "heading had no name argument",
|
|
383
|
+
line: node.line,
|
|
384
|
+
});
|
|
385
|
+
return "";
|
|
386
|
+
}
|
|
387
|
+
// The argument is a translation KEY (`whatsnext`, `prerequisites`); the
|
|
388
|
+
// rendered text is the site's i18n string `<key>_heading`.
|
|
389
|
+
const known = ctx.i18n?.[`${name}_heading`];
|
|
390
|
+
// one line: it sits in a heading
|
|
391
|
+
if (known?.trim())
|
|
392
|
+
return known.replace(/\s+/g, " ").trim();
|
|
393
|
+
// No such string: title-casing the key is a readable, honest
|
|
394
|
+
// approximation and is recorded as one.
|
|
395
|
+
const text = name
|
|
396
|
+
.replace(/[_-]+/g, " ")
|
|
397
|
+
.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
398
|
+
ctx.report({
|
|
399
|
+
shortcode: "heading",
|
|
400
|
+
action: "degraded",
|
|
401
|
+
note: `i18n heading key "${name}" rendered as "${text}" — the translated string lives in the site's i18n files`,
|
|
402
|
+
line: node.line,
|
|
403
|
+
});
|
|
404
|
+
return text;
|
|
405
|
+
},
|
|
406
|
+
// 1,266 uses. A glossary term with a hover definition. The tooltip is a
|
|
407
|
+
// theme affordance; the LINK and the text are the content.
|
|
408
|
+
glossary_tooltip: (node) => {
|
|
409
|
+
const text = arg(node.args, "text") ?? node.args.named.term_id ?? "";
|
|
410
|
+
const term = node.args.named.term_id;
|
|
411
|
+
return term ? `[${text}](/docs/reference/glossary/?term=${term})` : text;
|
|
412
|
+
},
|
|
413
|
+
// 38 uses. Prints a glossary term's definition: its page's first paragraph (`short`) or
|
|
414
|
+
// all of it (`all`, `long`), with `prepend` put before a lower-cased first letter.
|
|
415
|
+
glossary_definition: (node, ctx) => {
|
|
416
|
+
const id = node.args.named.term_id ?? "";
|
|
417
|
+
const length = node.args.named.length ?? "";
|
|
418
|
+
const prepend = (node.args.named.prepend ?? "").trim();
|
|
419
|
+
const term = glossaryTerm(ctx, id);
|
|
420
|
+
if (!["short", "all", "long"].includes(length)) {
|
|
421
|
+
ctx.report({ shortcode: "glossary_definition", action: "degraded", note: `glossary definition length "${length}" is not short, all or long (Hugo fails the build) — the short definition is written`, line: node.line });
|
|
422
|
+
}
|
|
423
|
+
if (!term) {
|
|
424
|
+
ctx.report({
|
|
425
|
+
shortcode: "glossary_definition",
|
|
426
|
+
action: "degraded",
|
|
427
|
+
note: `glossary term "${id}" has no page under ${GLOSSARY_DIR} whose text starts with a paragraph (or the term prints its own definition) — emitted as a link`,
|
|
428
|
+
line: node.line,
|
|
429
|
+
});
|
|
430
|
+
return id ? `[${id}](/docs/reference/glossary/?term=${id})` : "";
|
|
431
|
+
}
|
|
432
|
+
const all = length === "all" || length === "long";
|
|
433
|
+
const first = term.definition;
|
|
434
|
+
const lowered = first.charAt(0).toLowerCase() + first.slice(1);
|
|
435
|
+
// Keeping intent: the definition is read from the glossary's data file, so it is written
|
|
436
|
+
// once. `prepend` is the page's own text and stays in the page.
|
|
437
|
+
const intent = ctx.intent;
|
|
438
|
+
const at = `data.${GLOSSARY_DATA}[${JSON.stringify(id)}]`;
|
|
439
|
+
if (intent)
|
|
440
|
+
intent.store.data.set(GLOSSARY_DATA, glossaryData(ctx));
|
|
441
|
+
const ref = (template, baked) => (intent ? templateRef(intent, template, baked) : baked);
|
|
442
|
+
const head = prepend
|
|
443
|
+
? `${prepend} ${ref(`{{ ${at}.definition[0] | lower }}{{ ${at}.definition[1:] }}`, lowered)}`
|
|
444
|
+
: ref(`{{ ${at}.definition }}`, first);
|
|
445
|
+
return all && term.more ? `${head}\n\n${ref(`{{ ${at}.more }}`, term.more)}` : head;
|
|
446
|
+
},
|
|
447
|
+
// 402 uses. `{{< feature-state for_k8s_version="v1.29" state="stable" >}}`
|
|
448
|
+
// or the newer `feature_gate_name=` form.
|
|
449
|
+
"feature-state": (node, ctx) => {
|
|
450
|
+
const state = (node.args.named.state ?? "").toLowerCase();
|
|
451
|
+
const version = node.args.named.for_k8s_version;
|
|
452
|
+
const gate = node.args.named.feature_gate_name;
|
|
453
|
+
if (gate && !state) {
|
|
454
|
+
// The state is the gate's latest stage, from the gate's own page (as the site's shortcode
|
|
455
|
+
// reads it, from the default language).
|
|
456
|
+
const stage = featureGates(ctx).get(gate)?.stages.at(-1);
|
|
457
|
+
if (!stage) {
|
|
458
|
+
ctx.report({
|
|
459
|
+
shortcode: "feature-state",
|
|
460
|
+
action: "degraded",
|
|
461
|
+
note: `feature gate "${gate}" has no page with its stages under ${FEATURE_GATES_DIR} — emitted without a state`,
|
|
462
|
+
line: node.line,
|
|
463
|
+
});
|
|
464
|
+
return directive("info", "", `Feature gate: \`${gate}\``);
|
|
465
|
+
}
|
|
466
|
+
const t = (key, fallback) => ctx.i18n?.[key] ?? fallback;
|
|
467
|
+
const enabled = t("feature_gate_enabled", "(enabled by default)");
|
|
468
|
+
const disabled = t("feature_gate_disabled", "(disabled by default)");
|
|
469
|
+
const heading = `${t("feature_state", "FEATURE STATE:")} `;
|
|
470
|
+
const label = t("feature_state_kubernetes_label", "Kubernetes");
|
|
471
|
+
const value = { version: stage.fromVersion, stage: stage.stage, byDefault: stage.defaultValue ? enabled : disabled };
|
|
472
|
+
// Keeping intent: the page reads the gate from the site's data file, so a gate that
|
|
473
|
+
// moves to its next stage is changed there, once. Only a template page can.
|
|
474
|
+
const intent = ctx.intent;
|
|
475
|
+
const name = `gate_${gate}`;
|
|
476
|
+
// The two labels are written into the page's template as string literals: only ones that
|
|
477
|
+
// read the same there (no template syntax, no backtick that would start a code span, no
|
|
478
|
+
// control character the template's strings spell differently from JSON's).
|
|
479
|
+
const kept = !!intent && isAttributeName(gate) &&
|
|
480
|
+
[enabled, disabled].every(plainLabel);
|
|
481
|
+
if (kept)
|
|
482
|
+
intent.store.data.set(FEATURE_GATES_DATA, featureGateData(ctx));
|
|
483
|
+
const ref = (field, print) => kept ? expressionRef(intent, name, `data.${FEATURE_GATES_DATA}.${gate}.stages | last`, value[field], print) : value[field];
|
|
484
|
+
const byDefault = ref("byDefault", `${JSON.stringify(enabled)} if ${name}.defaultValue else ${JSON.stringify(disabled)}`);
|
|
485
|
+
// The box is the same for every stage: its colour would be today's stage written down,
|
|
486
|
+
// and the page reads the stage from the data.
|
|
487
|
+
return directive("info", "", `${heading}\`${label} v${ref("version", `${name}.fromVersion`)} [${ref("stage", `${name}.stage`)}]\` ${byDefault}`);
|
|
488
|
+
}
|
|
489
|
+
const type = STATE_TYPES[state] ?? "info";
|
|
490
|
+
const label = [state && state.toUpperCase(), version].filter(Boolean).join(" · ");
|
|
491
|
+
return directive(type, "", `Feature state: ${label || "unspecified"}`);
|
|
492
|
+
},
|
|
493
|
+
// The gates as a table and as a list (the feature gates reference pages), and one gate's
|
|
494
|
+
// description. All read the gates' own pages, as `feature-state` does.
|
|
495
|
+
"feature-gate-table": featureGateTable,
|
|
496
|
+
"feature-gate-list": featureGateList,
|
|
497
|
+
"feature-gate-description": (node, ctx) => {
|
|
498
|
+
const name = arg(node.args, "name") ?? "";
|
|
499
|
+
const gates = describedGates(ctx);
|
|
500
|
+
const description = gates.all.get(name)?.description;
|
|
501
|
+
if (!gates.all.has(name)) {
|
|
502
|
+
ctx.report({ shortcode: node.name, action: "degraded", note: `feature gate "${name}" has no page with its stages under ${FEATURE_GATES_DIR} — emitted as its name`, line: node.line });
|
|
503
|
+
return name ? codeSpan(name) : "";
|
|
504
|
+
}
|
|
505
|
+
// as the site's shortcode: nothing for a gate whose page has no text
|
|
506
|
+
if (!description)
|
|
507
|
+
return "";
|
|
508
|
+
const intent = ctx.intent;
|
|
509
|
+
if (!intent || !isAttributeName(name))
|
|
510
|
+
return `${codeSpan(name)}: ${description}`;
|
|
511
|
+
intent.store.data.set(FEATURE_GATES_DATA, gates.data);
|
|
512
|
+
return `${codeSpan(name)}: ${templateRef(intent, `{{ data.${FEATURE_GATES_DATA}.${name}.description }}`, description)}`;
|
|
513
|
+
},
|
|
514
|
+
// 298 uses. Version-skew arithmetic against the site params
|
|
515
|
+
// (`{{< skew currentVersion >}}`, `{{< skew latestVersionAddMinor -1 >}}`).
|
|
516
|
+
skew: (node, ctx) => {
|
|
517
|
+
// As the site's own shortcode computes it: the leading "v" is dropped (pages write
|
|
518
|
+
// `v{{< skew currentVersion >}}`; keeping it gave "vv1.36"), and the minor is moved.
|
|
519
|
+
const key = node.args.positional[0] ?? "currentVersion";
|
|
520
|
+
const strip = (v) => v?.replace(/v/g, "");
|
|
521
|
+
// kubernetes names them `latest` and `version`; other sites, `latestVersion` / `currentVersion`
|
|
522
|
+
const param = (...names) => {
|
|
523
|
+
for (const name of names) {
|
|
524
|
+
const v = lookupParam(ctx.config.params, name);
|
|
525
|
+
if (v !== undefined)
|
|
526
|
+
return v;
|
|
527
|
+
}
|
|
528
|
+
return undefined;
|
|
529
|
+
};
|
|
530
|
+
const named = (...names) => names.find((name) => lookupParam(ctx.config.params, name) !== undefined);
|
|
531
|
+
const latestName = named("latest", "latestVersion");
|
|
532
|
+
const currentName = named("version", "currentVersion") ?? latestName;
|
|
533
|
+
const latest = strip(param("latest", "latestVersion"));
|
|
534
|
+
const current = strip(param("version", "currentVersion")) ?? latest;
|
|
535
|
+
// Keeping intent: the version is the site's attribute (the number, without its "v"), and a
|
|
536
|
+
// moved version is an expression on it, which only a template page computes.
|
|
537
|
+
const intent = ctx.intent;
|
|
538
|
+
const attribute = (name, value) => {
|
|
539
|
+
if (!intent || !name || value === undefined || !isAttributeName(name))
|
|
540
|
+
return undefined;
|
|
541
|
+
const raw = lookupParam(ctx.config.params, name);
|
|
542
|
+
// the attribute holds what skew prints (`declareVersionAttributes` took the "v" off);
|
|
543
|
+
// a param the two forms do not agree on stays a value
|
|
544
|
+
if (raw !== (intent.store.prefixes.get(name) ?? "") + value)
|
|
545
|
+
return undefined;
|
|
546
|
+
return attributeRef(intent, name, raw, true);
|
|
547
|
+
};
|
|
548
|
+
/** A moved version as a value the page computes, named for what it is. */
|
|
549
|
+
const keep = (value, name, by, separator = ".", label) => {
|
|
550
|
+
if (value === undefined)
|
|
551
|
+
return undefined;
|
|
552
|
+
if (!intent || !name || !latestName || !isAttributeName(name) || !isAttributeName(latestName))
|
|
553
|
+
return value;
|
|
554
|
+
const SEPARATORS = { ".": "", "-": "_dash", "_": "_underscore", "": "_joined" };
|
|
555
|
+
// a whole number of minors: `1.5` would not make a name, and is not a version step
|
|
556
|
+
if (!(separator in SEPARATORS) || !Number.isInteger(by))
|
|
557
|
+
return value;
|
|
558
|
+
// both attributes declared, each holding the number
|
|
559
|
+
if (attribute(name, name === latestName ? latest : current) === undefined)
|
|
560
|
+
return value;
|
|
561
|
+
if (attribute(latestName, latest) === undefined)
|
|
562
|
+
return value;
|
|
563
|
+
let computed = label ?? `${name}_minor_${by < 0 ? "minus" : "plus"}_${Math.abs(by)}${SEPARATORS[separator]}`;
|
|
564
|
+
// a site param of that name would be shadowed
|
|
565
|
+
while (lookupParam(ctx.config.params, computed) !== undefined)
|
|
566
|
+
computed += "_";
|
|
567
|
+
const minor = `${name}.split(".")[1] | int${by === 0 ? "" : by > 0 ? ` + ${by}` : ` - ${-by}`}`;
|
|
568
|
+
return expressionRef(intent, computed, `${latestName}.split(".")[0] ~ "${separator}" ~ (${minor})`, value);
|
|
569
|
+
};
|
|
570
|
+
const parts = (v) => {
|
|
571
|
+
const m = /^(\d+)\.(\d+)/.exec(v ?? "");
|
|
572
|
+
return m ? { major: m[1], minor: Number(m[2]) } : undefined;
|
|
573
|
+
};
|
|
574
|
+
const fail = (why) => {
|
|
575
|
+
// nothing is printed: the current version in place of another one would be a wrong fact
|
|
576
|
+
ctx.report({ shortcode: "skew", action: "degraded", note: why, line: node.line });
|
|
577
|
+
return "";
|
|
578
|
+
};
|
|
579
|
+
const moved = (base, by, separator = ".") => {
|
|
580
|
+
const p = parts(base);
|
|
581
|
+
// the major is the LATEST version's in every form, as the site writes it
|
|
582
|
+
const major = parts(latest ?? base)?.major;
|
|
583
|
+
return p && major !== undefined && Number.isFinite(by) ? `${major}${separator}${p.minor + by}` : undefined;
|
|
584
|
+
};
|
|
585
|
+
let value;
|
|
586
|
+
switch (key) {
|
|
587
|
+
case "currentVersion":
|
|
588
|
+
value = attribute(currentName, current) ?? current;
|
|
589
|
+
break;
|
|
590
|
+
case "latestVersion":
|
|
591
|
+
value = attribute(latestName, latest) ?? latest;
|
|
592
|
+
break;
|
|
593
|
+
case "nextMinorVersion":
|
|
594
|
+
value = keep(moved(latest, 1), latestName, 1, ".", "next_minor_version");
|
|
595
|
+
break;
|
|
596
|
+
case "prevMinorVersion":
|
|
597
|
+
value = keep(moved(latest, -1), latestName, -1, ".", "prev_minor_version");
|
|
598
|
+
break;
|
|
599
|
+
case "oldestMinorVersion":
|
|
600
|
+
value = keep(moved(latest, -2), latestName, -2, ".", "oldest_minor_version");
|
|
601
|
+
break;
|
|
602
|
+
case "latestVersionAddMinor":
|
|
603
|
+
case "currentVersionAddMinor":
|
|
604
|
+
if (!Number.isFinite(Number(node.args.positional[1] ?? "0"))) {
|
|
605
|
+
return fail(`version-skew offset "${node.args.positional[1]}" is not a number — substituted as empty`);
|
|
606
|
+
}
|
|
607
|
+
{
|
|
608
|
+
const by = Number(node.args.positional[1] ?? "0");
|
|
609
|
+
const separator = node.args.positional[2] || ".";
|
|
610
|
+
const fromLatest = key === "latestVersionAddMinor";
|
|
611
|
+
value = keep(moved(fromLatest ? latest : current, by, separator), fromLatest ? latestName : currentName, by, separator);
|
|
612
|
+
}
|
|
613
|
+
break;
|
|
614
|
+
case "currentPatchVersion": {
|
|
615
|
+
if (!current)
|
|
616
|
+
return fail(`version-skew value "${key}" needs the site's version param — substituted as empty`);
|
|
617
|
+
// As the site's shortcode: the newest patch of the current release in the release
|
|
618
|
+
// schedule, or `.0` when the schedule has none.
|
|
619
|
+
const schedule = releaseSchedule(ctx);
|
|
620
|
+
const today = schedule?.schedules.find((s) => s.release === current)?.previousPatches?.[0]?.release ?? `${current}.0`;
|
|
621
|
+
if (!schedule) {
|
|
622
|
+
ctx.report({ shortcode: "skew", action: "degraded", note: `the current patch version comes from the site's release schedule (data/${RELEASE_SCHEDULE_FILE}), which was not found or could not be read as one — emitted as ${today}`, line: node.line });
|
|
623
|
+
return today;
|
|
624
|
+
}
|
|
625
|
+
// The site's own shortcode compares the version with a number format of the release,
|
|
626
|
+
// which never matches a release the schedule writes in quotes: Hugo then prints `.0`.
|
|
627
|
+
// The patch is what the shortcode is written to print, so it is written, and said.
|
|
628
|
+
if (today !== `${current}.0`) {
|
|
629
|
+
ctx.report({ shortcode: "skew", action: "degraded", note: `the current patch version is written as ${today}, from the site's release schedule; the Hugo site prints ${current}.0 when the schedule writes the release in quotes (its shortcode's comparison does not match)`, line: node.line });
|
|
630
|
+
}
|
|
631
|
+
// Keeping intent: the schedule is a data file (the site's own tool writes it), and the
|
|
632
|
+
// page finds the patch in it with the version attribute.
|
|
633
|
+
if (!intent || !currentName || attribute(currentName, current) === undefined)
|
|
634
|
+
return today;
|
|
635
|
+
intent.store.data.set(RELEASE_SCHEDULE_DATA, schedule);
|
|
636
|
+
let name = "current_patch_version";
|
|
637
|
+
while (lookupParam(ctx.config.params, name) !== undefined)
|
|
638
|
+
name += "_";
|
|
639
|
+
const newest = `((data.${RELEASE_SCHEDULE_DATA}.schedules | selectattr("release", "eq", ${currentName}) | first | default({})).previousPatches | default([]) | first | default({})).release`;
|
|
640
|
+
return expressionRef(intent, name, `${newest} | default(${currentName} ~ ".0")`, today);
|
|
641
|
+
}
|
|
642
|
+
default: {
|
|
643
|
+
// not a form of the kubernetes shortcode: a site param of that name, as written
|
|
644
|
+
const direct = param(key);
|
|
645
|
+
return direct ?? fail(`unknown version-skew form "${key}" — substituted as empty`);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return value ?? fail(`version-skew value "${key}" needs the site's \`latest\` and \`version\` params — substituted as empty`);
|
|
649
|
+
},
|
|
650
|
+
// 365 uses. Embeds a file from `content/<lang>/examples/` as a code block.
|
|
651
|
+
// The file IS the content, so failing to read it is a real loss.
|
|
652
|
+
code_sample: (node, ctx) => {
|
|
653
|
+
const file = arg(node.args, "file") ?? "";
|
|
654
|
+
const lang = node.args.named.language ?? guessLanguage(file);
|
|
655
|
+
const located = ctx.locateContentFile?.(`examples/${file.replace(/^\//, "")}`, ctx.file);
|
|
656
|
+
const content = located?.text ?? ctx.readContentFile?.(`examples/${file.replace(/^\//, "")}`, ctx.file);
|
|
657
|
+
if (content === undefined) {
|
|
658
|
+
ctx.report({
|
|
659
|
+
shortcode: "code_sample",
|
|
660
|
+
action: "degraded",
|
|
661
|
+
note: `could not read example file "${file}" — emitted as a link`,
|
|
662
|
+
line: node.line,
|
|
663
|
+
});
|
|
664
|
+
return `[${file}](/examples/${file.replace(/^\//, "")})`;
|
|
665
|
+
}
|
|
666
|
+
// (a last line of only spaces would put the closing fence four columns in, where it closes nothing)
|
|
667
|
+
const body = content.replace(/\s+$/, "");
|
|
668
|
+
const fence = "`".repeat(Math.max(3, ...[...body.matchAll(/`{3,}/g)].map((m) => m[0].length + 1)));
|
|
669
|
+
// Keeping intent: the example stays ONE file, and the block includes it. Not when the file
|
|
670
|
+
// itself shows template text ({{ .Values.x }}): an included file is read as a template.
|
|
671
|
+
// Nor when it ends in more than its one newline: the include would show those blank lines.
|
|
672
|
+
if (ctx.intent && located && ctx.sharedPath && !/\{\{|\{%|\{#/.test(content) && /[^\s]\n?$/.test(content)) {
|
|
673
|
+
const out = ctx.sharedPath(located, "example");
|
|
674
|
+
if (out)
|
|
675
|
+
return `${fence}${lang}\n${includeRef(ctx.intent, out, located.path, "example", body, /[^\n]\n$/.test(content))}\n${fence}`;
|
|
676
|
+
}
|
|
677
|
+
return `${fence}${lang}\n${body}\n${fence}`;
|
|
678
|
+
},
|
|
679
|
+
// Older alias for the same thing.
|
|
680
|
+
codenew: (node, ctx) => KUBERNETES_SHORTCODES.code_sample(node, ctx),
|
|
681
|
+
// 96 uses. A version guard around content; for a static export the content
|
|
682
|
+
// inside is what the reader wants.
|
|
683
|
+
"version-check": (node, ctx) => {
|
|
684
|
+
ctx.report({
|
|
685
|
+
shortcode: "version-check",
|
|
686
|
+
action: "stripped",
|
|
687
|
+
note: "runtime version guard — has no meaning in a static export",
|
|
688
|
+
line: node.line,
|
|
689
|
+
});
|
|
690
|
+
return node.inner ? ctx.translate(node.inner) : null;
|
|
691
|
+
},
|
|
692
|
+
// 45 uses. A standing disclaimer about third-party content.
|
|
693
|
+
"thirdparty-content": (node, ctx) => directive("note", "", node.inner
|
|
694
|
+
? ctx.translate(node.inner)
|
|
695
|
+
: "This section links to third party projects that provide functionality required by Kubernetes. The Kubernetes project authors are not responsible for those projects."),
|
|
696
|
+
// 17 uses. A link into the generated API reference.
|
|
697
|
+
"api-reference": (node, ctx) => {
|
|
698
|
+
const kind = node.args.named.kind ?? "";
|
|
699
|
+
const placeholder = node.args.named.placeholder ?? kind;
|
|
700
|
+
ctx.report({
|
|
701
|
+
shortcode: "api-reference",
|
|
702
|
+
action: "degraded",
|
|
703
|
+
note: `generated API reference for "${kind}" — emitted as a link, the generator is a separate Go tool`,
|
|
704
|
+
line: node.line,
|
|
705
|
+
});
|
|
706
|
+
return kind ? `[${placeholder}](/docs/reference/kubernetes-api/)` : "";
|
|
707
|
+
},
|
|
708
|
+
};
|
|
709
|
+
/** Language for a code sample, from its file extension. */
|
|
710
|
+
function guessLanguage(file) {
|
|
711
|
+
const ext = file.split(".").pop()?.toLowerCase() ?? "";
|
|
712
|
+
const map = {
|
|
713
|
+
yaml: "yaml",
|
|
714
|
+
yml: "yaml",
|
|
715
|
+
json: "json",
|
|
716
|
+
sh: "shell",
|
|
717
|
+
bash: "shell",
|
|
718
|
+
go: "go",
|
|
719
|
+
py: "python",
|
|
720
|
+
js: "javascript",
|
|
721
|
+
ts: "typescript",
|
|
722
|
+
xml: "xml",
|
|
723
|
+
toml: "toml",
|
|
724
|
+
};
|
|
725
|
+
return map[ext] ?? "";
|
|
726
|
+
}
|
|
727
|
+
/** Shortcodes only kubernetes/website defines: all three present is that site (or a fork). */
|
|
728
|
+
const SIGNATURE = ["feature-state", "glossary_tooltip", "skew"];
|
|
729
|
+
export const KUBERNETES = {
|
|
730
|
+
name: "kubernetes",
|
|
731
|
+
description: "kubernetes/website: glossary_tooltip, feature-state, skew, code_sample, heading and its others",
|
|
732
|
+
detect: (site) => SIGNATURE.every((name) => site.shortcodes.has(name))
|
|
733
|
+
? `the site defines ${SIGNATURE.join(", ")}`
|
|
734
|
+
: undefined,
|
|
735
|
+
shortcodes: KUBERNETES_SHORTCODES,
|
|
736
|
+
valueShortcodes: ["skew"],
|
|
737
|
+
prepare: declareVersionAttributes,
|
|
738
|
+
};
|