@dogsbay/format-hugo 0.2.0-beta.183 → 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,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Docsy, the theme of kubernetes.io and of many other Hugo docs sites.
|
|
3
|
+
*
|
|
4
|
+
* Its shortcodes come with the theme, so a site that uses Docsy has them without defining them.
|
|
5
|
+
* Only the ones measured on real content are mapped; `blocks/*`, `cardpane`, `imgproc`,
|
|
6
|
+
* `readfile`, `swaggerui` are left as written and reported.
|
|
7
|
+
*/
|
|
8
|
+
import { arg, attrBlock, directive } from "../registry.js";
|
|
9
|
+
import { tabMapping } from "./conventions.js";
|
|
10
|
+
/** Docsy `alert` colours → Dogsbay callout types. */
|
|
11
|
+
const ALERT_COLOURS = {
|
|
12
|
+
primary: "info",
|
|
13
|
+
secondary: "note",
|
|
14
|
+
info: "info",
|
|
15
|
+
success: "success",
|
|
16
|
+
warning: "warning",
|
|
17
|
+
danger: "danger",
|
|
18
|
+
dark: "note",
|
|
19
|
+
light: "note",
|
|
20
|
+
};
|
|
21
|
+
export const DOCSY = {
|
|
22
|
+
name: "docsy",
|
|
23
|
+
description: "the Docsy theme: alert, pageinfo, tabpane and tab",
|
|
24
|
+
// The reason is our own words, never the site's: a theme's name is whatever its config says.
|
|
25
|
+
detect: (site) => {
|
|
26
|
+
const isDocsy = (name) => /^(?:[\w.~-]+\/)*docsy(?:\/[\w.~-]+)*$/i.test(name);
|
|
27
|
+
if (site.themes.some(isDocsy))
|
|
28
|
+
return "the site's theme is Docsy";
|
|
29
|
+
if (site.modules.some(isDocsy))
|
|
30
|
+
return "the site uses the Docsy module";
|
|
31
|
+
return undefined;
|
|
32
|
+
},
|
|
33
|
+
shortcodes: {
|
|
34
|
+
// Docsy's own callout. 91 uses. `color=` selects the variant and `title=`
|
|
35
|
+
// is a heading on the box.
|
|
36
|
+
alert: (node, ctx) => {
|
|
37
|
+
const colour = (node.args.named.color ?? "").toLowerCase();
|
|
38
|
+
const type = ALERT_COLOURS[colour] ?? "note";
|
|
39
|
+
if (colour && !ALERT_COLOURS[colour]) {
|
|
40
|
+
ctx.report({
|
|
41
|
+
shortcode: "alert",
|
|
42
|
+
action: "degraded",
|
|
43
|
+
note: `unknown alert colour "${colour}" → :::note`,
|
|
44
|
+
line: node.line,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return directive(type, attrBlock({ title: node.args.named.title }), ctx.translate(node.inner));
|
|
48
|
+
},
|
|
49
|
+
// Docsy `pageinfo` — a page-level banner. Same shape as an alert.
|
|
50
|
+
pageinfo: (node, ctx) => directive(ALERT_COLOURS[(node.args.named.color ?? "").toLowerCase()] ?? "info", "", ctx.translate(node.inner)),
|
|
51
|
+
// Docsy's newer tab syntax.
|
|
52
|
+
tabpane: (node, ctx) => directive("tabs", "", ctx.translate(node.inner)),
|
|
53
|
+
"tab-pane": (node, ctx) => directive("tab", attrBlock({ title: arg(node.args, "header", "title", "name") }), ctx.translate(node.inner)),
|
|
54
|
+
// `{{% tab header="Linux" %}}` inside a `tabpane`.
|
|
55
|
+
tab: tabMapping,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The adapters this package ships, lowest first, and how a site's are chosen.
|
|
3
|
+
*
|
|
4
|
+
* To add one: a file here exporting a `HugoSiteAdapter`, and its entry in `HUGO_ADAPTERS`
|
|
5
|
+
* (after the adapters it should win over).
|
|
6
|
+
*/
|
|
7
|
+
import type { HugoSiteAdapter, HugoSiteFacts } from "../registry.js";
|
|
8
|
+
import { CONVENTIONS } from "./conventions.js";
|
|
9
|
+
import { DOCSY } from "./docsy.js";
|
|
10
|
+
import { KUBERNETES } from "./kubernetes.js";
|
|
11
|
+
import { DATADOG } from "./datadog.js";
|
|
12
|
+
export { CONVENTIONS, DOCSY, KUBERNETES, DATADOG };
|
|
13
|
+
export declare const HUGO_ADAPTERS: readonly HugoSiteAdapter[];
|
|
14
|
+
export interface ChosenAdapter {
|
|
15
|
+
adapter: HugoSiteAdapter;
|
|
16
|
+
/** Why it is used, for the report. */
|
|
17
|
+
why: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The adapters for a site. `choice`:
|
|
21
|
+
* - `auto` (default): each adapter whose `detect` matches the site;
|
|
22
|
+
* - `none`: Hugo's own shortcodes only;
|
|
23
|
+
* - a comma-separated list of names: exactly those, matched or not.
|
|
24
|
+
*
|
|
25
|
+
* The result keeps the order of `adapters`, whatever order the names were given in.
|
|
26
|
+
* An unknown name throws, listing the names there are.
|
|
27
|
+
*/
|
|
28
|
+
export declare function chooseAdapters(site: HugoSiteFacts, choice?: string, adapters?: readonly HugoSiteAdapter[]): ChosenAdapter[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CONVENTIONS } from "./conventions.js";
|
|
2
|
+
import { DOCSY } from "./docsy.js";
|
|
3
|
+
import { KUBERNETES } from "./kubernetes.js";
|
|
4
|
+
import { DATADOG } from "./datadog.js";
|
|
5
|
+
export { CONVENTIONS, DOCSY, KUBERNETES, DATADOG };
|
|
6
|
+
export const HUGO_ADAPTERS = [CONVENTIONS, DOCSY, KUBERNETES, DATADOG];
|
|
7
|
+
/**
|
|
8
|
+
* The adapters for a site. `choice`:
|
|
9
|
+
* - `auto` (default): each adapter whose `detect` matches the site;
|
|
10
|
+
* - `none`: Hugo's own shortcodes only;
|
|
11
|
+
* - a comma-separated list of names: exactly those, matched or not.
|
|
12
|
+
*
|
|
13
|
+
* The result keeps the order of `adapters`, whatever order the names were given in.
|
|
14
|
+
* An unknown name throws, listing the names there are.
|
|
15
|
+
*/
|
|
16
|
+
export function chooseAdapters(site, choice = "auto", adapters = HUGO_ADAPTERS) {
|
|
17
|
+
const wanted = choice.trim().toLowerCase();
|
|
18
|
+
if (wanted === "none")
|
|
19
|
+
return [];
|
|
20
|
+
if (wanted === "" || wanted === "auto") {
|
|
21
|
+
return adapters.flatMap((adapter) => {
|
|
22
|
+
const why = adapter.detect(site);
|
|
23
|
+
return why ? [{ adapter, why }] : [];
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const names = wanted.split(",").map((n) => n.trim()).filter(Boolean);
|
|
27
|
+
const known = adapters.map((a) => a.name).join(", ");
|
|
28
|
+
if (names.length === 0)
|
|
29
|
+
throw new Error(`no Hugo adapter is named: give auto, none, or a list of ${known}`);
|
|
30
|
+
if (names.includes("auto") || names.includes("none")) {
|
|
31
|
+
throw new Error(`"auto" and "none" stand alone: give one of them, or a list of ${known}`);
|
|
32
|
+
}
|
|
33
|
+
const unknown = names.filter((n) => !adapters.some((a) => a.name === n));
|
|
34
|
+
if (unknown.length > 0) {
|
|
35
|
+
// the names asked for are the caller's own words, shown as plain word characters only
|
|
36
|
+
const shown = unknown.map((n) => n.replace(/[^\w.-]/g, "?").slice(0, 40)).join('", "');
|
|
37
|
+
throw new Error(`unknown Hugo adapter "${shown}": there are ${known} (or auto, none)`);
|
|
38
|
+
}
|
|
39
|
+
return adapters.filter((a) => names.includes(a.name)).map((adapter) => ({ adapter, why: "asked for" }));
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { type HugoIntentStore } from "../intent.js";
|
|
13
|
+
import { type HugoSiteAdapter, type ShortcodeRegistry } from "../registry.js";
|
|
14
|
+
/**
|
|
15
|
+
* The version params as attributes: kubernetes writes `version = "v1.36"`, `{{< param >}}`
|
|
16
|
+
* prints that, and `{{< skew >}}` prints `1.36`. One attribute serves both when it holds the
|
|
17
|
+
* number and `param` writes the "v" in front, so the prefix is settled before any page is read
|
|
18
|
+
* (settled by whichever shortcode came first, the other form could not use the attribute).
|
|
19
|
+
*/
|
|
20
|
+
export declare function declareVersionAttributes(store: HugoIntentStore, params: Record<string, unknown>): void;
|
|
21
|
+
export declare const KUBERNETES_SHORTCODES: ShortcodeRegistry;
|
|
22
|
+
export declare const KUBERNETES: HugoSiteAdapter;
|