@dogsbay/site-files 0.2.0-beta.149 → 0.2.0-beta.151
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/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/inline-markdown.d.ts +20 -0
- package/dist/inline-markdown.js +154 -0
- package/dist/site-chrome.d.ts +95 -0
- package/dist/site-chrome.js +203 -0
- package/dist/static-folder.d.ts +7 -0
- package/dist/static-folder.js +10 -0
- package/dist/version-menu.d.ts +9 -4
- package/dist/version-menu.js +12 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline Markdown to HTML for the site chrome's one-line texts (`site.copyright`,
|
|
3
|
+
* `site.announcement.text`): code spans, links, strong, emphasis and backslash escapes;
|
|
4
|
+
* entity references (`©`) are kept, and everything else is text, HTML included. One
|
|
5
|
+
* renderer, so the dogsbay CLI and dogsbay-ssg write the same markup; `href` maps a site path
|
|
6
|
+
* as each pipeline serves it. Pure and Worker-safe. See plans/site-chrome.md.
|
|
7
|
+
*/
|
|
8
|
+
export interface InlineMarkdownOptions {
|
|
9
|
+
/** A link's href as the page writes it (a base path added, or made relative); default as written. */
|
|
10
|
+
href?: (href: string) => string;
|
|
11
|
+
}
|
|
12
|
+
/** The longest text taken: the chrome's texts are one line. */
|
|
13
|
+
export declare const INLINE_MARKDOWN_MAX = 2000;
|
|
14
|
+
/** A link in the chrome's texts: a site path, an http(s) address or a `mailto:` address. */
|
|
15
|
+
export declare function isTextLinkHref(href: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* `text` as inline HTML. A link whose href is not a site path, an http(s) or a `mailto:` address throws
|
|
18
|
+
* `ProductConfigError` (the config check: siteChrome renders each text once to find them).
|
|
19
|
+
*/
|
|
20
|
+
export declare function inlineMarkdownHtml(text: string, options?: InlineMarkdownOptions): string;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline Markdown to HTML for the site chrome's one-line texts (`site.copyright`,
|
|
3
|
+
* `site.announcement.text`): code spans, links, strong, emphasis and backslash escapes;
|
|
4
|
+
* entity references (`©`) are kept, and everything else is text, HTML included. One
|
|
5
|
+
* renderer, so the dogsbay CLI and dogsbay-ssg write the same markup; `href` maps a site path
|
|
6
|
+
* as each pipeline serves it. Pure and Worker-safe. See plans/site-chrome.md.
|
|
7
|
+
*/
|
|
8
|
+
import { ProductConfigError } from "./errors.js";
|
|
9
|
+
import { isSiteLinkHref } from "./version-menu.js";
|
|
10
|
+
/** The longest text taken: the chrome's texts are one line. */
|
|
11
|
+
export const INLINE_MARKDOWN_MAX = 2000;
|
|
12
|
+
/** A mail address link: `mailto:` and one plain address; no `?subject=`/`bcc=`, `%`-escapes or lists. */
|
|
13
|
+
const MAILTO = /^mailto:[A-Za-z0-9._+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$/;
|
|
14
|
+
/** A link in the chrome's texts: a site path, an http(s) address or a `mailto:` address. */
|
|
15
|
+
export function isTextLinkHref(href) {
|
|
16
|
+
return isSiteLinkHref(href) || MAILTO.test(href);
|
|
17
|
+
}
|
|
18
|
+
/** Emphasis inside emphasis deeper than this is text. */
|
|
19
|
+
const MAX_DEPTH = 8;
|
|
20
|
+
const PUNCT = /[!-/:-@[-`{-~]/;
|
|
21
|
+
const ENTITY = /^&(?:#\d{1,7}|#[xX][0-9a-fA-F]{1,6}|[A-Za-z][A-Za-z0-9]{1,31});/;
|
|
22
|
+
const escText = (c) => c === "&" ? "&" : c === "<" ? "<" : c === ">" ? ">" : c === '"' ? """ : c === "'" ? "'" : c;
|
|
23
|
+
const escAll = (s) => s.replace(/[&<>"']/g, escText);
|
|
24
|
+
/**
|
|
25
|
+
* `text` as inline HTML. A link whose href is not a site path, an http(s) or a `mailto:` address throws
|
|
26
|
+
* `ProductConfigError` (the config check: siteChrome renders each text once to find them).
|
|
27
|
+
*/
|
|
28
|
+
export function inlineMarkdownHtml(text, options = {}) {
|
|
29
|
+
if (text.length > INLINE_MARKDOWN_MAX)
|
|
30
|
+
throw new ProductConfigError(`inline Markdown longer than ${INLINE_MARKDOWN_MAX} characters`);
|
|
31
|
+
const line = text.replace(/\s+/g, " ").trim();
|
|
32
|
+
return render(line, options, 0, false);
|
|
33
|
+
}
|
|
34
|
+
function render(s, o, depth, inLink) {
|
|
35
|
+
let out = "";
|
|
36
|
+
let i = 0;
|
|
37
|
+
const n = s.length;
|
|
38
|
+
while (i < n) {
|
|
39
|
+
const c = s[i];
|
|
40
|
+
if (c === "\\" && i + 1 < n && PUNCT.test(s[i + 1])) {
|
|
41
|
+
out += escText(s[i + 1]);
|
|
42
|
+
i += 2;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (c === "`") {
|
|
46
|
+
let run = 1;
|
|
47
|
+
while (s[i + run] === "`")
|
|
48
|
+
run++;
|
|
49
|
+
const close = findRun(s, i + run, run);
|
|
50
|
+
if (close < 0) {
|
|
51
|
+
out += "`".repeat(run);
|
|
52
|
+
i += run;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
let code = s.slice(i + run, close);
|
|
56
|
+
if (code.length > 2 && code.startsWith(" ") && code.endsWith(" ") && code.trim())
|
|
57
|
+
code = code.slice(1, -1);
|
|
58
|
+
out += `<code>${escAll(code)}</code>`;
|
|
59
|
+
i = close + run;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (c === "[" && !inLink) {
|
|
63
|
+
const link = readLink(s, i);
|
|
64
|
+
if (link) {
|
|
65
|
+
if (!isTextLinkHref(link.href))
|
|
66
|
+
throw new ProductConfigError(`a link to ${JSON.stringify(link.href)}: a path from the site root (/guide/), an http(s) address or a mailto: address`);
|
|
67
|
+
const href = o.href && !link.href.toLowerCase().startsWith("mailto:") ? o.href(link.href) : link.href;
|
|
68
|
+
out += `<a href="${escAll(href)}">${render(link.label, o, depth, true)}</a>`;
|
|
69
|
+
i = link.end;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if ((c === "*" || c === "_") && depth < MAX_DEPTH) {
|
|
74
|
+
const span = readEmphasis(s, i);
|
|
75
|
+
if (span) {
|
|
76
|
+
const tag = span.strong ? "strong" : "em";
|
|
77
|
+
out += `<${tag}>${render(span.inner, o, depth + 1, inLink)}</${tag}>`;
|
|
78
|
+
i = span.end;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (c === "&") {
|
|
83
|
+
const m = ENTITY.exec(s.slice(i, i + 40));
|
|
84
|
+
if (m) {
|
|
85
|
+
out += m[0];
|
|
86
|
+
i += m[0].length;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
out += escText(c);
|
|
91
|
+
i++;
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
/** The next run of exactly `len` backticks from `from`, or -1. */
|
|
96
|
+
function findRun(s, from, len) {
|
|
97
|
+
for (let j = s.indexOf("`", from); j >= 0; j = s.indexOf("`", j)) {
|
|
98
|
+
let run = 1;
|
|
99
|
+
while (s[j + run] === "`")
|
|
100
|
+
run++;
|
|
101
|
+
if (run === len)
|
|
102
|
+
return j;
|
|
103
|
+
j += run;
|
|
104
|
+
}
|
|
105
|
+
return -1;
|
|
106
|
+
}
|
|
107
|
+
/** `[label](href)` at `at`: brackets balanced, backslash escapes skipped, href without spaces. */
|
|
108
|
+
function readLink(s, at) {
|
|
109
|
+
let depth = 0;
|
|
110
|
+
let j = at;
|
|
111
|
+
for (; j < s.length; j++) {
|
|
112
|
+
const c = s[j];
|
|
113
|
+
if (c === "\\") {
|
|
114
|
+
j++;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (c === "[")
|
|
118
|
+
depth++;
|
|
119
|
+
else if (c === "]" && --depth === 0)
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
if (j >= s.length || s[j + 1] !== "(")
|
|
123
|
+
return null;
|
|
124
|
+
const close = s.indexOf(")", j + 2);
|
|
125
|
+
if (close < 0)
|
|
126
|
+
return null;
|
|
127
|
+
const href = s.slice(j + 2, close).trim();
|
|
128
|
+
if (!href || /\s/.test(href))
|
|
129
|
+
return null;
|
|
130
|
+
return { label: s.slice(at + 1, j), href, end: close + 1 };
|
|
131
|
+
}
|
|
132
|
+
/** `**x**` / `__x__` (strong) or `*x*` / `_x_` (em) at `at`; `_` not inside a word, as CommonMark. */
|
|
133
|
+
function readEmphasis(s, at) {
|
|
134
|
+
const ch = s[at];
|
|
135
|
+
if (ch === "_" && at > 0 && /[\p{L}\p{N}]/u.test(s[at - 1]))
|
|
136
|
+
return null;
|
|
137
|
+
for (const len of s[at + 1] === ch ? [2, 1] : [1]) {
|
|
138
|
+
const delim = ch.repeat(len);
|
|
139
|
+
const start = at + len;
|
|
140
|
+
if (start >= s.length || s[start] === " ")
|
|
141
|
+
continue;
|
|
142
|
+
for (let j = s.indexOf(delim, start + 1); j >= 0; j = s.indexOf(delim, j + 1)) {
|
|
143
|
+
if (s[j - 1] === " " || s[j - 1] === "\\")
|
|
144
|
+
continue;
|
|
145
|
+
// A single delimiter must not be half of a double one
|
|
146
|
+
if (len === 1 && (s[j + 1] === ch || s[j - 1] === ch))
|
|
147
|
+
continue;
|
|
148
|
+
if (ch === "_" && j + len < s.length && /[\p{L}\p{N}]/u.test(s[j + len]))
|
|
149
|
+
continue;
|
|
150
|
+
return { strong: len === 2, inner: s.slice(start, j), end: j + len };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The site's chrome, read and checked once for the dogsbay CLI and dogsbay-ssg (agreed with the
|
|
3
|
+
* SSG team 2026-10-30): the logo, the colour mode, an announcement bar, header links and the
|
|
4
|
+
* footer's columns, so a migrated site needs no theme partials for them.
|
|
5
|
+
*
|
|
6
|
+
* site:
|
|
7
|
+
* logo: { light: assets/logo.svg, dark: assets/logo-dark.svg, alt: Acme, replacesName: true }
|
|
8
|
+
* colorMode: light # light | dark | system (default)
|
|
9
|
+
* announcement: { id: launch-2026, text: "We launched. [Read more](/blog/)", tone: tip, closeable: true }
|
|
10
|
+
* copyright: "© 2026 [Acme](https://acme.example)" # inline Markdown
|
|
11
|
+
* repoUrl: https://github.com/acme/docs # header.social's default
|
|
12
|
+
* header:
|
|
13
|
+
* links:
|
|
14
|
+
* - { label: Blog, href: "https://acme.example/blog/" }
|
|
15
|
+
* - { label: Products, items: [{ label: Gizmo, href: /gizmo/ }] }
|
|
16
|
+
* social: [{ icon: github, href: "https://github.com/acme", label: GitHub }]
|
|
17
|
+
* footer:
|
|
18
|
+
* columns: [{ title: Learn, links: [{ label: Tutorials, href: /tutorials/ }] }]
|
|
19
|
+
* social: [{ icon: slack, href: "https://acme.slack.com/", label: Slack }]
|
|
20
|
+
*
|
|
21
|
+
* Refused configs throw `ProductConfigError`, naming the key. Logo files are checked here only as
|
|
22
|
+
* paths; whether one is inside the project, and copying it, is the pipeline's. Texts are inline
|
|
23
|
+
* Markdown (`inlineMarkdownHtml`), never HTML. Pure and Worker-safe. See plans/site-chrome.md.
|
|
24
|
+
*/
|
|
25
|
+
/** The brand icons a `social` entry may name (Simple Icons, CC0; drawn by @dogsbay/icons `socialIconSvg`). */
|
|
26
|
+
export declare const SOCIAL_ICON_NAMES: readonly ["bitbucket", "bluesky", "discord", "facebook", "git", "github", "gitlab", "huggingface", "instagram", "linkedin", "mastodon", "medium", "npm", "reddit", "rss", "slack", "stackoverflow", "telegram", "threads", "twitch", "x", "youtube"];
|
|
27
|
+
export type SocialIconName = (typeof SOCIAL_ICON_NAMES)[number];
|
|
28
|
+
export declare const ANNOUNCEMENT_TONES: readonly ["note", "tip", "warning", "caution"];
|
|
29
|
+
export type AnnouncementTone = (typeof ANNOUNCEMENT_TONES)[number];
|
|
30
|
+
export type ColorMode = "light" | "dark" | "system";
|
|
31
|
+
export interface ChromeLink {
|
|
32
|
+
label: string;
|
|
33
|
+
href: string;
|
|
34
|
+
}
|
|
35
|
+
/** A header dropdown: one level, its links only. */
|
|
36
|
+
export interface ChromeMenu {
|
|
37
|
+
label: string;
|
|
38
|
+
items: ChromeLink[];
|
|
39
|
+
}
|
|
40
|
+
export type HeaderLink = ChromeLink | ChromeMenu;
|
|
41
|
+
export interface SocialLink {
|
|
42
|
+
icon: SocialIconName;
|
|
43
|
+
href: string;
|
|
44
|
+
/** The link's accessible name (the icon is all that shows). */
|
|
45
|
+
label: string;
|
|
46
|
+
}
|
|
47
|
+
export interface SiteLogo {
|
|
48
|
+
/** A project path, as written (`assets/logo.svg`); also the dark mode's without `dark`. */
|
|
49
|
+
light: string;
|
|
50
|
+
dark?: string;
|
|
51
|
+
alt: string;
|
|
52
|
+
/** The logo is a wordmark: the site name beside it is for screen readers only. */
|
|
53
|
+
replacesName: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface Announcement {
|
|
56
|
+
/** Closing the bar is remembered per reader under this id; a new id shows again. */
|
|
57
|
+
id: string;
|
|
58
|
+
/** Inline Markdown. */
|
|
59
|
+
text: string;
|
|
60
|
+
tone: AnnouncementTone;
|
|
61
|
+
closeable: boolean;
|
|
62
|
+
}
|
|
63
|
+
export interface FooterColumn {
|
|
64
|
+
title: string;
|
|
65
|
+
links: ChromeLink[];
|
|
66
|
+
}
|
|
67
|
+
export interface SiteChrome {
|
|
68
|
+
logo?: SiteLogo;
|
|
69
|
+
colorMode: ColorMode;
|
|
70
|
+
announcement?: Announcement;
|
|
71
|
+
/** `site.copyright`, inline Markdown. */
|
|
72
|
+
copyright?: string;
|
|
73
|
+
header: {
|
|
74
|
+
links: HeaderLink[];
|
|
75
|
+
social: SocialLink[];
|
|
76
|
+
};
|
|
77
|
+
footer: {
|
|
78
|
+
columns: FooterColumn[];
|
|
79
|
+
social: SocialLink[];
|
|
80
|
+
};
|
|
81
|
+
/** What the build should say (a copyright written as HTML, shown as text now). */
|
|
82
|
+
warnings: string[];
|
|
83
|
+
}
|
|
84
|
+
export declare function isChromeMenu(link: HeaderLink): link is ChromeMenu;
|
|
85
|
+
/** `site.repoUrl` as a social entry: the icon by host. */
|
|
86
|
+
export declare function repoSocialLink(repoUrl: string): SocialLink | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* The chrome from a config's `site`, `header` and `footer` (as parsed from YAML). Throws
|
|
89
|
+
* `ProductConfigError` on a config both pipelines refuse.
|
|
90
|
+
*/
|
|
91
|
+
export declare function siteChrome(config: {
|
|
92
|
+
site?: unknown;
|
|
93
|
+
header?: unknown;
|
|
94
|
+
footer?: unknown;
|
|
95
|
+
}): SiteChrome;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The site's chrome, read and checked once for the dogsbay CLI and dogsbay-ssg (agreed with the
|
|
3
|
+
* SSG team 2026-10-30): the logo, the colour mode, an announcement bar, header links and the
|
|
4
|
+
* footer's columns, so a migrated site needs no theme partials for them.
|
|
5
|
+
*
|
|
6
|
+
* site:
|
|
7
|
+
* logo: { light: assets/logo.svg, dark: assets/logo-dark.svg, alt: Acme, replacesName: true }
|
|
8
|
+
* colorMode: light # light | dark | system (default)
|
|
9
|
+
* announcement: { id: launch-2026, text: "We launched. [Read more](/blog/)", tone: tip, closeable: true }
|
|
10
|
+
* copyright: "© 2026 [Acme](https://acme.example)" # inline Markdown
|
|
11
|
+
* repoUrl: https://github.com/acme/docs # header.social's default
|
|
12
|
+
* header:
|
|
13
|
+
* links:
|
|
14
|
+
* - { label: Blog, href: "https://acme.example/blog/" }
|
|
15
|
+
* - { label: Products, items: [{ label: Gizmo, href: /gizmo/ }] }
|
|
16
|
+
* social: [{ icon: github, href: "https://github.com/acme", label: GitHub }]
|
|
17
|
+
* footer:
|
|
18
|
+
* columns: [{ title: Learn, links: [{ label: Tutorials, href: /tutorials/ }] }]
|
|
19
|
+
* social: [{ icon: slack, href: "https://acme.slack.com/", label: Slack }]
|
|
20
|
+
*
|
|
21
|
+
* Refused configs throw `ProductConfigError`, naming the key. Logo files are checked here only as
|
|
22
|
+
* paths; whether one is inside the project, and copying it, is the pipeline's. Texts are inline
|
|
23
|
+
* Markdown (`inlineMarkdownHtml`), never HTML. Pure and Worker-safe. See plans/site-chrome.md.
|
|
24
|
+
*/
|
|
25
|
+
import { ProductConfigError } from "./errors.js";
|
|
26
|
+
import { inlineMarkdownHtml } from "./inline-markdown.js";
|
|
27
|
+
import { isSiteLinkHref } from "./version-menu.js";
|
|
28
|
+
/** The brand icons a `social` entry may name (Simple Icons, CC0; drawn by @dogsbay/icons `socialIconSvg`). */
|
|
29
|
+
export const SOCIAL_ICON_NAMES = [
|
|
30
|
+
"bitbucket", "bluesky", "discord", "facebook", "git", "github", "gitlab", "huggingface", "instagram",
|
|
31
|
+
"linkedin", "mastodon", "medium", "npm", "reddit", "rss", "slack", "stackoverflow", "telegram",
|
|
32
|
+
"threads", "twitch", "x", "youtube",
|
|
33
|
+
];
|
|
34
|
+
export const ANNOUNCEMENT_TONES = ["note", "tip", "warning", "caution"];
|
|
35
|
+
export function isChromeMenu(link) {
|
|
36
|
+
return "items" in link;
|
|
37
|
+
}
|
|
38
|
+
const LOGO_TYPES = /\.(svg|png|webp|jpe?g)$/i;
|
|
39
|
+
const ANNOUNCEMENT_ID = /^[A-Za-z0-9._-]{1,64}$/;
|
|
40
|
+
const HTML_TAG = /<\/?[A-Za-z][^>]*>/;
|
|
41
|
+
/** Links in one list, at most; a config is someone's site, not a data set. */
|
|
42
|
+
const MAX_LINKS = 100;
|
|
43
|
+
const fail = (msg) => {
|
|
44
|
+
throw new ProductConfigError(msg);
|
|
45
|
+
};
|
|
46
|
+
const isMap = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
47
|
+
function text(raw, at, required = true) {
|
|
48
|
+
if (raw === undefined || raw === null)
|
|
49
|
+
return required ? fail(`${at}: required`) : undefined;
|
|
50
|
+
if (typeof raw !== "string" || !raw.trim())
|
|
51
|
+
return fail(`${at}: expected text`);
|
|
52
|
+
return raw.trim();
|
|
53
|
+
}
|
|
54
|
+
function list(raw, at) {
|
|
55
|
+
if (raw === undefined || raw === null)
|
|
56
|
+
return [];
|
|
57
|
+
if (!Array.isArray(raw))
|
|
58
|
+
return fail(`${at}: expected a list`);
|
|
59
|
+
if (raw.length > MAX_LINKS)
|
|
60
|
+
fail(`${at}: more than ${MAX_LINKS} entries`);
|
|
61
|
+
return raw;
|
|
62
|
+
}
|
|
63
|
+
function link(raw, at) {
|
|
64
|
+
if (!isMap(raw))
|
|
65
|
+
return fail(`${at}: expected a mapping { label, href }`);
|
|
66
|
+
const label = text(raw.label, `${at}.label`);
|
|
67
|
+
if (!isSiteLinkHref(raw.href))
|
|
68
|
+
fail(`${at}.href: a path from the site root (/guide/) or an http(s) address; got ${JSON.stringify(raw.href ?? null)}`);
|
|
69
|
+
return { label, href: raw.href };
|
|
70
|
+
}
|
|
71
|
+
function social(raw, at) {
|
|
72
|
+
return list(raw, at).map((e, i) => {
|
|
73
|
+
const where = `${at}[${i}]`;
|
|
74
|
+
if (!isMap(e))
|
|
75
|
+
return fail(`${where}: expected a mapping { icon, href, label }`);
|
|
76
|
+
if (!SOCIAL_ICON_NAMES.includes(e.icon))
|
|
77
|
+
fail(`${where}.icon: one of ${SOCIAL_ICON_NAMES.join(", ")}; got ${JSON.stringify(e.icon ?? null)}`);
|
|
78
|
+
const { href } = link({ label: e.label ?? e.icon, href: e.href }, where);
|
|
79
|
+
return { icon: e.icon, href, label: text(e.label, `${where}.label`, false) ?? String(e.icon) };
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** Inline Markdown text, its links checked; HTML in it is text (a warning names it). A number (`copyright: 2026`) is its text. */
|
|
83
|
+
function markdown(raw, at, warnings) {
|
|
84
|
+
const t = text(typeof raw === "number" && Number.isFinite(raw) ? String(raw) : raw, at, false);
|
|
85
|
+
if (t === undefined)
|
|
86
|
+
return undefined;
|
|
87
|
+
try {
|
|
88
|
+
inlineMarkdownHtml(t);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
fail(`${at}: ${e.message}`);
|
|
92
|
+
}
|
|
93
|
+
if (HTML_TAG.test(t))
|
|
94
|
+
warnings.push(`${at}: HTML is shown as text; write inline Markdown ([label](https://…), **bold**)`);
|
|
95
|
+
return t;
|
|
96
|
+
}
|
|
97
|
+
/** A project path to an image: relative, no `..`, no scheme, an image type. */
|
|
98
|
+
function logoPath(raw, at) {
|
|
99
|
+
const p = text(raw, at).replace(/^\.\//, "");
|
|
100
|
+
if (p.startsWith("/") || /^[A-Za-z][A-Za-z0-9+.-]*:/.test(p) || p.includes("\\") || p.split("/").some((s) => s === ".." || s === "." || s === ""))
|
|
101
|
+
fail(`${at}: a path inside the project, relative to the config (assets/logo.svg); got ${JSON.stringify(raw)}`);
|
|
102
|
+
if (!LOGO_TYPES.test(p))
|
|
103
|
+
fail(`${at}: an SVG, PNG, WebP or JPEG image; got ${JSON.stringify(raw)}`);
|
|
104
|
+
return p;
|
|
105
|
+
}
|
|
106
|
+
/** `site.repoUrl` as a social entry: the icon by host. */
|
|
107
|
+
export function repoSocialLink(repoUrl) {
|
|
108
|
+
if (!/^https?:\/\/\S+$/.test(repoUrl))
|
|
109
|
+
return undefined;
|
|
110
|
+
let host;
|
|
111
|
+
try {
|
|
112
|
+
host = new URL(repoUrl).hostname.toLowerCase();
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
const icon = /(^|\.)github\.com$/.test(host) ? "github" : /(^|\.)gitlab\.com$/.test(host) ? "gitlab" : /(^|\.)bitbucket\.org$/.test(host) ? "bitbucket" : "git";
|
|
118
|
+
return { icon, href: repoUrl, label: "Source repository" };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The chrome from a config's `site`, `header` and `footer` (as parsed from YAML). Throws
|
|
122
|
+
* `ProductConfigError` on a config both pipelines refuse.
|
|
123
|
+
*/
|
|
124
|
+
export function siteChrome(config) {
|
|
125
|
+
const warnings = [];
|
|
126
|
+
const site = config.site === undefined || config.site === null ? {} : isMap(config.site) ? config.site : fail("site: expected a mapping");
|
|
127
|
+
const header = config.header === undefined || config.header === null ? {} : isMap(config.header) ? config.header : fail("header: expected a mapping (links, social)");
|
|
128
|
+
const footer = config.footer === undefined || config.footer === null ? {} : isMap(config.footer) ? config.footer : fail("footer: expected a mapping (columns, social)");
|
|
129
|
+
let logo;
|
|
130
|
+
if (site.logo !== undefined && site.logo !== null) {
|
|
131
|
+
const l = isMap(site.logo) ? site.logo : fail("site.logo: expected a mapping { light, dark, alt, replacesName }");
|
|
132
|
+
if (l.replacesName !== undefined && typeof l.replacesName !== "boolean")
|
|
133
|
+
fail("site.logo.replacesName: true or false");
|
|
134
|
+
logo = {
|
|
135
|
+
light: logoPath(l.light, "site.logo.light"),
|
|
136
|
+
...(l.dark !== undefined && l.dark !== null ? { dark: logoPath(l.dark, "site.logo.dark") } : {}),
|
|
137
|
+
alt: text(l.alt, "site.logo.alt", false) ?? (typeof site.name === "string" ? site.name : ""),
|
|
138
|
+
replacesName: l.replacesName === true,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const colorMode = (site.colorMode ?? "system");
|
|
142
|
+
if (colorMode !== "light" && colorMode !== "dark" && colorMode !== "system")
|
|
143
|
+
fail(`site.colorMode: light, dark or system; got ${JSON.stringify(site.colorMode)}`);
|
|
144
|
+
let announcement;
|
|
145
|
+
if (site.announcement !== undefined && site.announcement !== null) {
|
|
146
|
+
const a = isMap(site.announcement) ? site.announcement : fail("site.announcement: expected a mapping { id, text, tone, closeable }");
|
|
147
|
+
const id = text(a.id, "site.announcement.id");
|
|
148
|
+
if (!ANNOUNCEMENT_ID.test(id))
|
|
149
|
+
fail(`site.announcement.id: letters, digits, ".", "_" and "-" (up to 64); got ${JSON.stringify(id)}`);
|
|
150
|
+
const tone = (a.tone ?? "note");
|
|
151
|
+
if (!ANNOUNCEMENT_TONES.includes(tone))
|
|
152
|
+
fail(`site.announcement.tone: one of ${ANNOUNCEMENT_TONES.join(", ")}; got ${JSON.stringify(a.tone)}`);
|
|
153
|
+
if (a.closeable !== undefined && typeof a.closeable !== "boolean")
|
|
154
|
+
fail("site.announcement.closeable: true or false");
|
|
155
|
+
const t = markdown(a.text, "site.announcement.text", warnings);
|
|
156
|
+
if (t === undefined)
|
|
157
|
+
fail("site.announcement.text: required");
|
|
158
|
+
announcement = { id, text: t, tone, closeable: a.closeable !== false };
|
|
159
|
+
}
|
|
160
|
+
const copyright = markdown(site.copyright, "site.copyright", warnings);
|
|
161
|
+
const links = list(header.links, "header.links").map((e, i) => {
|
|
162
|
+
const at = `header.links[${i}]`;
|
|
163
|
+
if (isMap(e) && e.items !== undefined) {
|
|
164
|
+
if (e.href !== undefined)
|
|
165
|
+
fail(`${at}: a dropdown has items, not an href`);
|
|
166
|
+
const items = list(e.items, `${at}.items`).map((item, j) => {
|
|
167
|
+
if (isMap(item) && item.items !== undefined)
|
|
168
|
+
fail(`${at}.items[${j}]: dropdowns are one level deep`);
|
|
169
|
+
return link(item, `${at}.items[${j}]`);
|
|
170
|
+
});
|
|
171
|
+
if (!items.length)
|
|
172
|
+
fail(`${at}.items: at least one link`);
|
|
173
|
+
return { label: text(e.label, `${at}.label`), items };
|
|
174
|
+
}
|
|
175
|
+
return link(e, at);
|
|
176
|
+
});
|
|
177
|
+
// site.repoUrl is the header's repository icon unless header.social is written ([] turns it off)
|
|
178
|
+
let headerSocial;
|
|
179
|
+
if (header.social !== undefined)
|
|
180
|
+
headerSocial = social(header.social, "header.social");
|
|
181
|
+
else {
|
|
182
|
+
const repo = typeof site.repoUrl === "string" ? repoSocialLink(site.repoUrl) : undefined;
|
|
183
|
+
if (typeof site.repoUrl === "string" && site.repoUrl.trim() && !repo) {
|
|
184
|
+
warnings.push(`site.repoUrl: ${JSON.stringify(site.repoUrl)} is not an http(s) address, so the header has no repository icon (set header.social)`);
|
|
185
|
+
}
|
|
186
|
+
headerSocial = repo ? [repo] : [];
|
|
187
|
+
}
|
|
188
|
+
const columns = list(footer.columns, "footer.columns").map((e, i) => {
|
|
189
|
+
const at = `footer.columns[${i}]`;
|
|
190
|
+
if (!isMap(e))
|
|
191
|
+
return fail(`${at}: expected a mapping { title, links }`);
|
|
192
|
+
return { title: text(e.title, `${at}.title`), links: list(e.links, `${at}.links`).map((l, j) => link(l, `${at}.links[${j}]`)) };
|
|
193
|
+
});
|
|
194
|
+
return {
|
|
195
|
+
...(logo ? { logo } : {}),
|
|
196
|
+
colorMode,
|
|
197
|
+
...(announcement ? { announcement } : {}),
|
|
198
|
+
...(copyright !== undefined ? { copyright } : {}),
|
|
199
|
+
header: { links, social: headerSocial },
|
|
200
|
+
footer: { columns, social: social(footer.social, "footer.social") },
|
|
201
|
+
warnings,
|
|
202
|
+
};
|
|
203
|
+
}
|
package/dist/static-folder.d.ts
CHANGED
|
@@ -14,6 +14,13 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Pure and Worker-safe: paths in, decisions out.
|
|
16
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* Whether a static folder serves a path at all (folder-relative, `/`-separated): no hidden file
|
|
19
|
+
* or folder (`.git`, `.DS_Store`), except `.well-known/` at the folder's root (security.txt,
|
|
20
|
+
* assetlinks.json), which hosts serve as it is. The one rule for `site build`, dogsbay-ssg and
|
|
21
|
+
* the importers; whether a file in it is served untrusted is `isPassiveStaticFile`'s question.
|
|
22
|
+
*/
|
|
23
|
+
export declare function staticPathServed(path: string): boolean;
|
|
17
24
|
/** Whether an untrusted build may serve `path` by its type alone (no HTML, scripts, CSS, XML or SVG). */
|
|
18
25
|
export declare function isPassiveStaticFile(path: string): boolean;
|
|
19
26
|
/**
|
package/dist/static-folder.js
CHANGED
|
@@ -30,6 +30,16 @@ const PASSIVE = new Set([
|
|
|
30
30
|
"epub", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "odt", "ods", "odp",
|
|
31
31
|
"sh", "ps1", "py", "conf", "ini", "env", "cfg", "pem", "crt", "pub", "asc", "sig", "sha256",
|
|
32
32
|
]);
|
|
33
|
+
/**
|
|
34
|
+
* Whether a static folder serves a path at all (folder-relative, `/`-separated): no hidden file
|
|
35
|
+
* or folder (`.git`, `.DS_Store`), except `.well-known/` at the folder's root (security.txt,
|
|
36
|
+
* assetlinks.json), which hosts serve as it is. The one rule for `site build`, dogsbay-ssg and
|
|
37
|
+
* the importers; whether a file in it is served untrusted is `isPassiveStaticFile`'s question.
|
|
38
|
+
*/
|
|
39
|
+
export function staticPathServed(path) {
|
|
40
|
+
const segments = path.split("/");
|
|
41
|
+
return segments.every((seg, i) => !seg.startsWith(".") || (i === 0 && seg === ".well-known" && segments.length > 1));
|
|
42
|
+
}
|
|
33
43
|
/** Whether an untrusted build may serve `path` by its type alone (no HTML, scripts, CSS, XML or SVG). */
|
|
34
44
|
export function isPassiveStaticFile(path) {
|
|
35
45
|
const name = path.slice(path.lastIndexOf("/") + 1);
|
package/dist/version-menu.d.ts
CHANGED
|
@@ -27,13 +27,18 @@ export interface VersionMenu {
|
|
|
27
27
|
/** List the first `limit` versions, plus the page's own when it comes later. */
|
|
28
28
|
limit?: number;
|
|
29
29
|
}
|
|
30
|
-
/**
|
|
31
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Whether `href` is a link the site's chrome takes (the version menu, header and footer links,
|
|
32
|
+
* links in the copyright and announcement): a site path or an http(s) address.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isSiteLinkHref(href: unknown): href is string;
|
|
35
|
+
/** The version menu's name for {@link isSiteLinkHref}. */
|
|
36
|
+
export declare const isVersionMenuHref: typeof isSiteLinkHref;
|
|
32
37
|
/**
|
|
33
38
|
* Read and check a `versionMenu:` mapping (`at` names it in errors:
|
|
34
39
|
* `content.versionMenu`, `content.products.gizmo.versionMenu`). Undefined when
|
|
35
|
-
* it is not written
|
|
36
|
-
* it turns the site's off.
|
|
40
|
+
* it is not written, or written with no value (YAML null: a product then falls back to the
|
|
41
|
+
* site's). `{}` is a menu with no links and no limit: on a product, it turns the site's off.
|
|
37
42
|
*/
|
|
38
43
|
export declare function readVersionMenu(raw: unknown, at: string): VersionMenu | undefined;
|
|
39
44
|
/** A version's `badge:`, checked as the other version flags: true or false, never a word. */
|
package/dist/version-menu.js
CHANGED
|
@@ -23,20 +23,26 @@ const WEB = /^https?:\/\/\S+$/;
|
|
|
23
23
|
const fail = (msg) => {
|
|
24
24
|
throw new ProductConfigError(msg);
|
|
25
25
|
};
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Whether `href` is a link the site's chrome takes (the version menu, header and footer links,
|
|
28
|
+
* links in the copyright and announcement): a site path or an http(s) address.
|
|
29
|
+
*/
|
|
30
|
+
export function isSiteLinkHref(href) {
|
|
28
31
|
return typeof href === "string" && (SITE_PATH.test(href) || WEB.test(href));
|
|
29
32
|
}
|
|
33
|
+
/** The version menu's name for {@link isSiteLinkHref}. */
|
|
34
|
+
export const isVersionMenuHref = isSiteLinkHref;
|
|
30
35
|
/**
|
|
31
36
|
* Read and check a `versionMenu:` mapping (`at` names it in errors:
|
|
32
37
|
* `content.versionMenu`, `content.products.gizmo.versionMenu`). Undefined when
|
|
33
|
-
* it is not written
|
|
34
|
-
* it turns the site's off.
|
|
38
|
+
* it is not written, or written with no value (YAML null: a product then falls back to the
|
|
39
|
+
* site's). `{}` is a menu with no links and no limit: on a product, it turns the site's off.
|
|
35
40
|
*/
|
|
36
41
|
export function readVersionMenu(raw, at) {
|
|
37
|
-
|
|
42
|
+
// `versionMenu:` with no value is not written (a product falls back to the site's); `{}` is off
|
|
43
|
+
if (raw === undefined || raw === null)
|
|
38
44
|
return undefined;
|
|
39
|
-
if (
|
|
45
|
+
if (typeof raw !== "object" || Array.isArray(raw))
|
|
40
46
|
return fail(`${at}: expected a mapping (links, limit)`);
|
|
41
47
|
const m = raw;
|
|
42
48
|
const links = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dogsbay/site-files",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.151",
|
|
4
4
|
"description": "robots.txt, _headers, llms.txt, sitemaps, redirects and JSON-LD for docs sites; shared by the dogsbay Astro pipeline and dogsbay-ssg, Worker-safe",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|