@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.
@@ -1,185 +0,0 @@
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
- }