website-xp-phone 2.2.12 → 2.4.0
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/.github/workflows/ci.yml +2 -2
- package/README.md +17 -3
- package/build/blogDirsPlugin.ts +100 -0
- package/build/env.ts +4 -1
- package/build/routeSkeletonsPlugin.ts +44 -2
- package/package.json +14 -10
- package/public/blog/archive/eighth-post-lost-in-the-sauce.json +36 -0
- package/public/blog/archive/noise/eleventh-post-discussion-java-gist.md +5 -0
- package/public/blog/archive/noise/fifteenth-post-very-rare-windows-funny.md +8 -0
- package/public/blog/archive/noise/fourth-post-meta-blog.md +3 -0
- package/public/blog/archive/noise/sixteenth-post-meta-fantasy-blog.md +4 -0
- package/public/blog/archive/noise/tenth-post-meta-funny-redacted-and-timetravelled.md +3 -0
- package/public/blog/archive/noise/twelfth-post-mixing-phase-technique-audio-music.md +48 -0
- package/public/blog/archive/noise/welcome-back-ramble-meta.md +6 -0
- package/public/blog/archive/noise/welcome-to-my-blog-meta-blog-welcome-to-my-website.md +7 -0
- package/public/blog/archive/seventh-post-lie-theory-na2000.json +22 -0
- package/public/blog/archive/sophus-lie.json +36 -0
- package/public/blog/hlwm_and_herbstutil.md +11 -0
- package/public/blog/random/hlwm.md +8 -0
- package/public/blog/writing/hot-action-under-a-cold-moon.json +9 -0
- package/public/checksums.txt +91 -66
- package/public/documents/drift-report.json +42 -28
- package/render.yaml +11 -1
- package/scripts/mutable-assets.mjs +13 -22
- package/scripts/refresh-content.mjs +53 -32
- package/scripts/refresh-soundcloud.mjs +221 -136
- package/scripts/write-dist-checksums.mjs +48 -4
- package/src/content/blog.json +16 -363
- package/src/content/blogDirs.ts +196 -0
- package/src/content/configs.json +1 -1
- package/src/content/contacts.json +2 -2
- package/src/content/includes/make-recipes.md +18 -0
- package/src/content/index.ts +156 -57
- package/src/content/music-ext.json +1 -1
- package/src/content/projects/doftiles.json +88 -4
- package/src/content/projects/herbctl.json +58 -0
- package/src/content/projects/herbstutil.json +50 -20
- package/src/content/projects/on-deploy.json +57 -0
- package/src/content/projects/polyframes.json +83 -0
- package/src/content/schema.ts +7 -4
- package/src/content/sections.json +11 -10
- package/src/content/soundcloud.json +95 -47
- package/src/lib/clippy.ts +29 -8
- package/src/lib/embeds.ts +43 -24
- package/src/lib/history.ts +152 -0
- package/src/lib/markdown.tsx +19 -22
- package/src/lib/rehypeYoutubeEmbed.ts +65 -0
- package/src/lib/sanitizeSchema.ts +32 -0
- package/src/lib/scrollTo.ts +45 -0
- package/src/lib/signals.tsx +271 -0
- package/src/main.tsx +20 -4
- package/src/pages/BlogDirPage.tsx +36 -0
- package/src/pages/BlogPostPage.tsx +76 -3
- package/src/pages/ProjectPage.tsx +9 -3
- package/src/pages/WowPage.tsx +8 -3
- package/src/pages/index.ts +2 -0
- package/src/shell/App.tsx +14 -8
- package/src/shell/Clippy.tsx +13 -3
- package/src/shell/MenuBar.tsx +7 -4
- package/src/shell/resolveRoute.ts +41 -2
- package/src/shell/routerSignals.ts +34 -0
- package/src/styles/extras.css +27 -0
- package/src/styles/layout.css +2 -2
- package/src/styles/menu.css +1 -1
- package/src/styles/window.css +19 -9
- package/src/themes/pageSlide/index.ts +120 -42
- package/src/themes/pageSlide/pageSlide.css +20 -9
- package/src/virtual.d.ts +14 -0
- package/src/window/MaximizedWindow.tsx +97 -64
- package/src/window/OkButton.tsx +42 -25
- package/src/window/PageWindows.tsx +7 -0
- package/src/window/TitleBar.tsx +3 -1
- package/src/window/Window.tsx +132 -87
- package/src/window/closeSounds.ts +27 -0
- package/src/window/model.ts +11 -0
- package/src/window/state.tsx +290 -50
- package/src/window/themes.ts +23 -2
- package/test/content.test.js +15 -10
- package/test/deploy-pipeline.test.js +73 -0
- package/test/embeds.test.js +89 -0
- package/test/markdown-tables.test.js +96 -0
- package/test/mutable-assets.test.js +16 -4
- package/test/route-skeletons.test.js +38 -0
- package/test/soundcloud-refresh.test.js +68 -0
- package/test/youtubeEmbed.test.js +157 -0
- package/tsconfig.node.tsbuildinfo +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/vite.config.ts +7 -1
- package/.opencode/cache/index.akinevz.html +0 -54
- package/public/blog/4th.md +0 -28
- package/public/blog/wsl.1.md +0 -40
- package/src/window/hidden.ts +0 -22
- /package/public/blog/{ → archive/noise/}/321/200/321/203/320/275/320/270/321/201/321/207-/320/263/320/273/320/276/321/201/321/201/320/260/321/200/320/270/320/271.md" +0 -0
- /package/src/content/{characters.json → includes/characters.json} +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
resolveEmbed,
|
|
5
|
+
youtubeVideoId,
|
|
6
|
+
youTubeThumbnail,
|
|
7
|
+
} from "../src/lib/embeds.ts";
|
|
8
|
+
|
|
9
|
+
test("youtubeVideoId parses every common URL form", () => {
|
|
10
|
+
const cases = [
|
|
11
|
+
["https://youtu.be/n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
12
|
+
["https://www.youtube.com/watch?v=n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
13
|
+
["https://youtube.com/watch?v=n_L-E8K_gcg&t=30s", "n_L-E8K_gcg"],
|
|
14
|
+
["https://m.youtube.com/watch?v=n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
15
|
+
["https://music.youtube.com/watch?v=n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
16
|
+
["https://www.youtube.com/embed/n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
17
|
+
["https://www.youtube.com/shorts/n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
18
|
+
["https://www.youtube.com/live/n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
19
|
+
["https://www.youtube-nocookie.com/embed/n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
20
|
+
];
|
|
21
|
+
for (const [url, id] of cases) {
|
|
22
|
+
assert.equal(youtubeVideoId(url), id, url);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("youtubeVideoId rejects playlists, other sites and junk", () => {
|
|
27
|
+
const rejects = [
|
|
28
|
+
"not a url",
|
|
29
|
+
"/relative/path",
|
|
30
|
+
"#clippy",
|
|
31
|
+
"https://example.com/watch?v=n_L-E8K_gcg",
|
|
32
|
+
"https://www.youtube.com/playlist?list=PLAOwLA0fz3HQCtJ5",
|
|
33
|
+
"https://www.youtube.com/watch?v=n_L-E8K_gcg&list=PLAOwLA0fz3HQCtJ5",
|
|
34
|
+
"https://youtu.be/n_L-E8K_gcg?list=PLAOwLA0fz3HQCtJ5",
|
|
35
|
+
"https://www.youtube.com/watch", // no v
|
|
36
|
+
"https://www.youtube.com/watch?v=not a valid id",
|
|
37
|
+
];
|
|
38
|
+
for (const url of rejects) {
|
|
39
|
+
assert.equal(youtubeVideoId(url), null, url);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("resolveEmbed keeps playlists as plain links (they are often unlisted)", () => {
|
|
44
|
+
assert.equal(
|
|
45
|
+
resolveEmbed("https://www.youtube.com/watch?v=x&list=PLAOwLA0fz3HQCtJ5"),
|
|
46
|
+
null,
|
|
47
|
+
);
|
|
48
|
+
assert.equal(
|
|
49
|
+
resolveEmbed("https://www.youtube.com/playlist?list=PLAOwLA0fz3HQCtJ5"),
|
|
50
|
+
null,
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("resolveEmbed maps youtube videos to embed cards", () => {
|
|
55
|
+
const spec = resolveEmbed("https://youtu.be/n_L-E8K_gcg");
|
|
56
|
+
assert.equal(spec?.provider, "youtube");
|
|
57
|
+
assert.equal(spec?.label, "YouTube");
|
|
58
|
+
assert.equal(spec?.src, "https://www.youtube.com/embed/n_L-E8K_gcg");
|
|
59
|
+
// No fixed height: 16:9 players size from their width via CSS.
|
|
60
|
+
assert.equal(spec?.height, undefined);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("resolveEmbed gives fixed-aspect players a fixed height", () => {
|
|
64
|
+
assert.equal(resolveEmbed("https://open.spotify.com/track/abc")?.height, 152);
|
|
65
|
+
assert.equal(
|
|
66
|
+
resolveEmbed("https://soundcloud.com/artist/track")?.height,
|
|
67
|
+
250,
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("youTubeThumbnail builds the maxres thumbnail for video URLs only", () => {
|
|
72
|
+
assert.equal(
|
|
73
|
+
youTubeThumbnail("https://www.youtube.com/watch?v=n_L-E8K_gcg"),
|
|
74
|
+
"https://i.ytimg.com/vi/n_L-E8K_gcg/maxresdefault.jpg",
|
|
75
|
+
);
|
|
76
|
+
assert.equal(
|
|
77
|
+
youTubeThumbnail("https://youtu.be/n_L-E8K_gcg"),
|
|
78
|
+
"https://i.ytimg.com/vi/n_L-E8K_gcg/maxresdefault.jpg",
|
|
79
|
+
);
|
|
80
|
+
// Shorts now get thumbnails too (the old parser missed them).
|
|
81
|
+
assert.equal(
|
|
82
|
+
youTubeThumbnail("https://www.youtube.com/shorts/n_L-E8K_gcg"),
|
|
83
|
+
"https://i.ytimg.com/vi/n_L-E8K_gcg/maxresdefault.jpg",
|
|
84
|
+
);
|
|
85
|
+
assert.equal(
|
|
86
|
+
youTubeThumbnail("https://www.youtube.com/playlist?list=PLAOwLA0fz3HQCtJ5"),
|
|
87
|
+
null,
|
|
88
|
+
);
|
|
89
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { unified } from "unified";
|
|
4
|
+
import remarkParse from "remark-parse";
|
|
5
|
+
import remarkBreaks from "remark-breaks";
|
|
6
|
+
import remarkGfm from "remark-gfm";
|
|
7
|
+
import remarkRehype from "remark-rehype";
|
|
8
|
+
import rehypeRaw from "rehype-raw";
|
|
9
|
+
import rehypeSanitize from "rehype-sanitize";
|
|
10
|
+
// The exact schema the real pipeline uses (src/lib/markdown.tsx) — no
|
|
11
|
+
// local mirror that could drift from it.
|
|
12
|
+
import { sanitizeSchema } from "../src/lib/sanitizeSchema.ts";
|
|
13
|
+
|
|
14
|
+
const processor = unified()
|
|
15
|
+
.use(remarkParse)
|
|
16
|
+
.use(remarkBreaks)
|
|
17
|
+
.use(remarkGfm)
|
|
18
|
+
.use(remarkRehype, { allowDangerousHtml: true })
|
|
19
|
+
.use(rehypeRaw)
|
|
20
|
+
.use(rehypeSanitize, sanitizeSchema);
|
|
21
|
+
|
|
22
|
+
function process(md) {
|
|
23
|
+
return processor.runSync(processor.parse(md));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function collect(node, tagName, acc = []) {
|
|
27
|
+
if (!node || typeof node !== "object") return acc;
|
|
28
|
+
if (node.tagName === tagName) acc.push(node);
|
|
29
|
+
for (const child of node.children ?? []) collect(child, tagName, acc);
|
|
30
|
+
return acc;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function textOf(nodes) {
|
|
34
|
+
const walk = (node, acc = []) => {
|
|
35
|
+
if (node?.type === "text") acc.push(node.value);
|
|
36
|
+
for (const child of node?.children ?? []) walk(child, acc);
|
|
37
|
+
return acc.join("");
|
|
38
|
+
};
|
|
39
|
+
return nodes.map((node) => walk(node)).join(" | ");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
test("GFM pipe tables render through the Md pipeline", () => {
|
|
43
|
+
const md = [
|
|
44
|
+
"\n\n| Recipe | Effect |",
|
|
45
|
+
"|---|---|",
|
|
46
|
+
"| `install` | full host setup |",
|
|
47
|
+
"| `wm` -> `herbst` | stows `herbst` + `herbstclient reload` |",
|
|
48
|
+
"\n\n",
|
|
49
|
+
].join("\n");
|
|
50
|
+
const tree = process(md);
|
|
51
|
+
const tables = collect(tree, "table");
|
|
52
|
+
assert.equal(tables.length, 1);
|
|
53
|
+
assert.equal(collect(tree, "thead").length, 1);
|
|
54
|
+
assert.equal(collect(tree, "tr").length, 3);
|
|
55
|
+
assert.equal(collect(tree, "th").length, 2);
|
|
56
|
+
assert.equal(collect(tree, "td").length, 4);
|
|
57
|
+
// inline code survives inside cells
|
|
58
|
+
assert.equal(collect(tree, "code").length, 5);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("remarkBreaks does not inject <br> between table rows", () => {
|
|
62
|
+
const md = "| a | b |\n|---|---|\n| x | y |\n\n";
|
|
63
|
+
const tables = collect(process(md), "table");
|
|
64
|
+
assert.equal(tables.length, 1);
|
|
65
|
+
// every br that remarkBreaks produces must stay outside table cells
|
|
66
|
+
const row = collect(tables[0], "tr").pop();
|
|
67
|
+
assert.equal(collect(row, "br").length, 0);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("removal check: sanitize keeps tables but strips alignment/style", () => {
|
|
71
|
+
const md =
|
|
72
|
+
"| a | b |\n|:--|--:|\n| x | y |\n\n" + // alignment colons
|
|
73
|
+
"<style>body{}</style>\n\n";
|
|
74
|
+
const tree = process(md);
|
|
75
|
+
assert.equal(collect(tree, "table").length, 1);
|
|
76
|
+
// <style> is sanitized away
|
|
77
|
+
assert.deepEqual(collect(tree, "style"), []);
|
|
78
|
+
for (const cell of [...collect(tree, "th"), ...collect(tree, "td")]) {
|
|
79
|
+
// no inline-style smuggling (align survives the whitelist — the
|
|
80
|
+
// content-table CSS overrides it, so it is inert either way)
|
|
81
|
+
assert.equal(cell.properties.style, undefined);
|
|
82
|
+
assert.ok(
|
|
83
|
+
["left", "center", "right", undefined].includes(cell.properties.align),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("line-oriented writing still breaks outside tables (remarkBreaks)", () => {
|
|
89
|
+
const tree = process("line one\nline two\n\n");
|
|
90
|
+
const paragraphs = collect(tree, "p");
|
|
91
|
+
assert.equal(paragraphs.length, 1);
|
|
92
|
+
assert.equal(collect(paragraphs[0], "br").length, 1);
|
|
93
|
+
// and the two lines are kept apart by that break
|
|
94
|
+
assert.match(textOf(paragraphs), /line one/);
|
|
95
|
+
assert.match(textOf(paragraphs), /line two/);
|
|
96
|
+
});
|
|
@@ -15,9 +15,12 @@ test("blog post artifacts are mutable, so new posts are never drift", () => {
|
|
|
15
15
|
assert.equal(isMutablePath("stories/1.md"), true);
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
test("blog pages
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
test("blog pages are not hand-listed anymore", () => {
|
|
19
|
+
// generated pages (blog.html, webuser/index.html, ...) are auto-marked
|
|
20
|
+
// mutable via dist/.generated.json, emitted by routeSkeletonsPlugin —
|
|
21
|
+
// see test/route-skeletons.test.js
|
|
22
|
+
assert.equal(isMutablePath("blog.html"), false);
|
|
23
|
+
assert.equal(isMutablePath("webuser/index.html"), false);
|
|
21
24
|
});
|
|
22
25
|
|
|
23
26
|
test("LFS and self-referential artifacts are mutable", () => {
|
|
@@ -27,8 +30,17 @@ test("LFS and self-referential artifacts are mutable", () => {
|
|
|
27
30
|
assert.equal(isMutablePath("documents/drift-report.json"), true);
|
|
28
31
|
});
|
|
29
32
|
|
|
33
|
+
test("vite-emitted bundles are mutable (rebuild noise)", () => {
|
|
34
|
+
// hashed names + chunk hashing/module ordering vary between rebuilds
|
|
35
|
+
assert.equal(isMutablePath("assets/index-D4oX1XA7.js"), true);
|
|
36
|
+
assert.equal(isMutablePath("assets/index-8bBd-nO8.css"), true);
|
|
37
|
+
assert.equal(isMutablePath("assets/toastify-DVtug25g.css"), true);
|
|
38
|
+
});
|
|
39
|
+
|
|
30
40
|
test("stable non-blog artifacts are not mutable", () => {
|
|
31
41
|
assert.equal(isMutablePath("configs.html"), false);
|
|
32
42
|
assert.equal(isMutablePath("spinner.svg"), false);
|
|
33
|
-
|
|
43
|
+
// public/-copied css lands at the dist ROOT, not in assets/ — only
|
|
44
|
+
// vite-emitted bundles under assets/ are mutable.
|
|
45
|
+
assert.equal(isMutablePath("loading.css"), false);
|
|
34
46
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { generatedPathsForRoutes } from "../build/routeSkeletonsPlugin.ts";
|
|
4
|
+
|
|
5
|
+
const routes = [
|
|
6
|
+
{ path: "/", title: "home", description: "d" },
|
|
7
|
+
{ path: "/blog", title: "blog", description: "d" },
|
|
8
|
+
{ path: "/resume", title: "resume", description: "d" },
|
|
9
|
+
{ path: "/webuser", title: "webuser", description: "d" },
|
|
10
|
+
{ path: "/projects/webuser", title: "webuser", description: "d" },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
// resume.html is hand-written in public/ and wins over the generated sibling
|
|
14
|
+
const publicSiblingExists = (slug) => slug === "resume";
|
|
15
|
+
|
|
16
|
+
test("every route generates a page pair, auto-marked mutable", () => {
|
|
17
|
+
const generated = generatedPathsForRoutes(routes, publicSiblingExists);
|
|
18
|
+
// route pages: <slug>/index.html plus <slug>.html for static hosts
|
|
19
|
+
assert.ok(generated.includes("webuser/index.html"));
|
|
20
|
+
assert.ok(generated.includes("webuser.html"));
|
|
21
|
+
assert.ok(generated.includes("projects/webuser/index.html"));
|
|
22
|
+
assert.ok(generated.includes("blog/index.html"));
|
|
23
|
+
// root index.html and sitemap.xml are always generated
|
|
24
|
+
assert.ok(generated.includes("index.html"));
|
|
25
|
+
assert.ok(generated.includes("sitemap.xml"));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("a hand-written public/<slug>.html suppresses the generated sibling", () => {
|
|
29
|
+
const generated = generatedPathsForRoutes(routes, publicSiblingExists);
|
|
30
|
+
assert.ok(generated.includes("resume/index.html"));
|
|
31
|
+
assert.ok(!generated.includes("resume.html"));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("generated paths are unique and deterministically sorted", () => {
|
|
35
|
+
const generated = generatedPathsForRoutes(routes, publicSiblingExists);
|
|
36
|
+
assert.equal(new Set(generated).size, generated.length);
|
|
37
|
+
assert.deepEqual(generated, [...generated].sort());
|
|
38
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { snapshotsMatch } from "../scripts/refresh-soundcloud.mjs";
|
|
4
|
+
|
|
5
|
+
const snapshot = (stamp, extra = {}) => ({
|
|
6
|
+
generatedAt: stamp,
|
|
7
|
+
source: "https://soundcloud.com/akinevz",
|
|
8
|
+
trackCount: 1,
|
|
9
|
+
tracks: [{ owner: "akinevz", path: "/akinevz/roam", title: "Roam" }],
|
|
10
|
+
profiles: [{ owner: "akinevz", trackCount: 1 }],
|
|
11
|
+
...extra,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("a refresh that only stamps a new generatedAt is treated as unchanged", () => {
|
|
15
|
+
// The core no-op case: same track list, new timestamp — discard the write.
|
|
16
|
+
assert.equal(
|
|
17
|
+
snapshotsMatch(
|
|
18
|
+
snapshot("2026-10-27T21:16:00Z"),
|
|
19
|
+
snapshot("2026-10-28T08:00:00Z"),
|
|
20
|
+
),
|
|
21
|
+
true,
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("a changed discography is never treated as unchanged", () => {
|
|
26
|
+
const fresh = snapshot("2026-10-28T08:00:00Z");
|
|
27
|
+
// a new upload
|
|
28
|
+
assert.equal(
|
|
29
|
+
snapshotsMatch(
|
|
30
|
+
snapshot("2026-10-27T21:16:00Z"),
|
|
31
|
+
snapshot("2026-10-28T08:00:00Z", {
|
|
32
|
+
trackCount: 2,
|
|
33
|
+
tracks: [
|
|
34
|
+
...snapshot("").tracks,
|
|
35
|
+
{ owner: "akinevz", path: "/akinevz/outer", title: "Outer" },
|
|
36
|
+
],
|
|
37
|
+
}),
|
|
38
|
+
),
|
|
39
|
+
false,
|
|
40
|
+
);
|
|
41
|
+
// a rename moves the permalinks and titles
|
|
42
|
+
const renamed = snapshot("2026-10-28T08:00:00Z");
|
|
43
|
+
renamed.tracks[0].title = "Roam (remastered)";
|
|
44
|
+
assert.equal(
|
|
45
|
+
snapshotsMatch(snapshot("2026-10-27T21:16:00Z"), renamed),
|
|
46
|
+
false,
|
|
47
|
+
);
|
|
48
|
+
// metadata the script emits also counts
|
|
49
|
+
assert.equal(
|
|
50
|
+
snapshotsMatch(
|
|
51
|
+
snapshot("2026-10-27T21:16:00Z"),
|
|
52
|
+
snapshot("2026-10-28T08:00:00Z", { asOfUploadingTrackCount: 94 }),
|
|
53
|
+
),
|
|
54
|
+
false,
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("nothing on disk (missing or unparseable file) always counts as changed", () => {
|
|
59
|
+
assert.equal(snapshotsMatch(null, snapshot("2026-10-27T21:16:00Z")), false);
|
|
60
|
+
assert.equal(
|
|
61
|
+
snapshotsMatch(undefined, snapshot("2026-10-27T21:16:00Z")),
|
|
62
|
+
false,
|
|
63
|
+
);
|
|
64
|
+
assert.equal(
|
|
65
|
+
snapshotsMatch("not an object", snapshot("2026-10-27T21:16:00Z")),
|
|
66
|
+
false,
|
|
67
|
+
);
|
|
68
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { unified } from "unified";
|
|
4
|
+
import remarkParse from "remark-parse";
|
|
5
|
+
import remarkRehype from "remark-rehype";
|
|
6
|
+
import rehypeRaw from "rehype-raw";
|
|
7
|
+
import rehypeSanitize from "rehype-sanitize";
|
|
8
|
+
import { rehypeYoutubeEmbed } from "../src/lib/rehypeYoutubeEmbed.ts";
|
|
9
|
+
// The exact schema the real pipeline uses (src/lib/markdown.tsx) — no
|
|
10
|
+
// local mirror that could drift from it.
|
|
11
|
+
import { sanitizeSchema } from "../src/lib/sanitizeSchema.ts";
|
|
12
|
+
|
|
13
|
+
const processor = unified()
|
|
14
|
+
.use(remarkParse)
|
|
15
|
+
.use(remarkRehype, { allowDangerousHtml: true })
|
|
16
|
+
.use(rehypeRaw)
|
|
17
|
+
.use(rehypeYoutubeEmbed)
|
|
18
|
+
.use(rehypeSanitize, sanitizeSchema);
|
|
19
|
+
|
|
20
|
+
function process(md) {
|
|
21
|
+
return processor.runSync(processor.parse(md));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function collect(node, tagName, acc = []) {
|
|
25
|
+
if (!node || typeof node !== "object") return acc;
|
|
26
|
+
if (node.tagName === tagName) acc.push(node);
|
|
27
|
+
for (const child of node.children ?? []) collect(child, tagName, acc);
|
|
28
|
+
return acc;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
test("a bare youtu.be autolink becomes an iframe embed", () => {
|
|
32
|
+
const tree = process("Here is my video:\n\n<https://youtu.be/n_L-E8K_gcg>\n");
|
|
33
|
+
const iframes = collect(tree, "iframe");
|
|
34
|
+
const links = collect(tree, "a");
|
|
35
|
+
assert.equal(iframes.length, 1);
|
|
36
|
+
assert.equal(links.length, 0);
|
|
37
|
+
assert.equal(
|
|
38
|
+
iframes[0].properties.src,
|
|
39
|
+
"https://www.youtube-nocookie.com/embed/n_L-E8K_gcg",
|
|
40
|
+
);
|
|
41
|
+
assert.equal(iframes[0].properties.title, "YouTube video");
|
|
42
|
+
assert.equal(iframes[0].properties.loading, "lazy");
|
|
43
|
+
// Error 153 fix: the iframe must send a referrer despite the site's
|
|
44
|
+
// no-referrer header, so the plugin sets its own policy.
|
|
45
|
+
assert.equal(
|
|
46
|
+
iframes[0].properties.referrerPolicy,
|
|
47
|
+
"strict-origin-when-cross-origin",
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("watch, embed, shorts and plain links all convert", () => {
|
|
52
|
+
const cases = [
|
|
53
|
+
["https://www.youtube.com/watch?v=n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
54
|
+
["https://youtube.com/watch?v=n_L-E8K_gcg&t=30s", "n_L-E8K_gcg"],
|
|
55
|
+
["https://www.youtube.com/embed/n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
56
|
+
["https://www.youtube.com/shorts/n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
57
|
+
["https://youtu.be/Ab12Cd34_-x", "Ab12Cd34_-x"],
|
|
58
|
+
["https://m.youtube.com/watch?v=n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
59
|
+
["https://music.youtube.com/watch?v=n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
60
|
+
["https://www.youtube-nocookie.com/embed/n_L-E8K_gcg", "n_L-E8K_gcg"],
|
|
61
|
+
];
|
|
62
|
+
for (const [url, id] of cases) {
|
|
63
|
+
const tree = process(`See <${url}> for details.\n`);
|
|
64
|
+
const iframes = collect(tree, "iframe");
|
|
65
|
+
assert.equal(iframes.length, 1, url);
|
|
66
|
+
assert.equal(
|
|
67
|
+
iframes[0].properties.src,
|
|
68
|
+
`https://www.youtube-nocookie.com/embed/${id}`,
|
|
69
|
+
url,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("the embed stays inside its container and keeps its 16:9 shape", () => {
|
|
75
|
+
const tree = process("<https://youtu.be/n_L-E8K_gcg>\n");
|
|
76
|
+
const style = String(collect(tree, "iframe")[0].properties.style);
|
|
77
|
+
assert.match(style, /width:\s*100%/);
|
|
78
|
+
// A 560px-wide embed overflowed narrow (mobile) window bodies.
|
|
79
|
+
assert.match(style, /max-width:\s*560px/);
|
|
80
|
+
assert.match(style, /aspect-ratio:\s*16\s*\/\s*9/);
|
|
81
|
+
// `height: auto` lets the ratio win over the height attribute.
|
|
82
|
+
assert.match(style, /height:\s*auto/);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("markdown link text becomes the accessible player title", () => {
|
|
86
|
+
const tree = process("[my talk](https://youtu.be/n_L-E8K_gcg)\n");
|
|
87
|
+
const iframes = collect(tree, "iframe");
|
|
88
|
+
assert.equal(iframes.length, 1);
|
|
89
|
+
assert.equal(iframes[0].properties.title, "my talk");
|
|
90
|
+
assert.equal(
|
|
91
|
+
iframes[0].properties.src,
|
|
92
|
+
"https://www.youtube-nocookie.com/embed/n_L-E8K_gcg",
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("bare URLs in plain text are not links and stay untouched", () => {
|
|
97
|
+
// remark-parse without remark-gfm does not autolink bare URLs, so the
|
|
98
|
+
// plugin has nothing to transform — the text passes through unchanged.
|
|
99
|
+
const tree = process("Visit https://youtu.be/n_L-E8K_gcg some day.\n");
|
|
100
|
+
assert.equal(collect(tree, "iframe").length, 0);
|
|
101
|
+
assert.equal(collect(tree, "a").length, 0);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("non-YouTube links are left as links", () => {
|
|
105
|
+
const tree = process("Docs at <https://example.com/watch?v=x> live here.\n");
|
|
106
|
+
const iframes = collect(tree, "iframe");
|
|
107
|
+
const links = collect(tree, "a");
|
|
108
|
+
assert.equal(iframes.length, 0);
|
|
109
|
+
assert.equal(links.length, 1);
|
|
110
|
+
assert.equal(links[0].properties.href, "https://example.com/watch?v=x");
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("playlist links stay links instead of dropping the playlist", () => {
|
|
114
|
+
const cases = [
|
|
115
|
+
"https://www.youtube.com/watch?v=n_L-E8K_gcg&list=PLAOwLA0fz3HQCtJ5",
|
|
116
|
+
"https://youtu.be/n_L-E8K_gcg?list=PLAOwLA0fz3HQCtJ5",
|
|
117
|
+
"https://www.youtube.com/playlist?list=PLAOwLA0fz3HQCtJ5",
|
|
118
|
+
];
|
|
119
|
+
for (const url of cases) {
|
|
120
|
+
const tree = process(`Playlist: <${url}>\n`);
|
|
121
|
+
assert.equal(collect(tree, "iframe").length, 0, url);
|
|
122
|
+
const links = collect(tree, "a");
|
|
123
|
+
assert.equal(links.length, 1, url);
|
|
124
|
+
assert.equal(links[0].properties.href, url);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("in-page anchor links (e.g. the clippy trigger) stay links", () => {
|
|
129
|
+
const tree = process("[talk to me](#clippy)\n");
|
|
130
|
+
const iframes = collect(tree, "iframe");
|
|
131
|
+
const links = collect(tree, "a");
|
|
132
|
+
assert.equal(iframes.length, 0);
|
|
133
|
+
assert.equal(links.length, 1);
|
|
134
|
+
assert.equal(links[0].properties.href, "#clippy");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("youtube link used inline within a paragraph still converts", () => {
|
|
138
|
+
const tree = process(
|
|
139
|
+
"I recorded my herbstluftwm talk: <https://youtu.be/n_L-E8K_gcg> — enjoy.",
|
|
140
|
+
);
|
|
141
|
+
const iframes = collect(tree, "iframe");
|
|
142
|
+
const links = collect(tree, "a");
|
|
143
|
+
assert.equal(iframes.length, 1);
|
|
144
|
+
assert.equal(links.length, 0);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("embeds survive rehype-sanitize", () => {
|
|
148
|
+
const tree = process("<https://youtu.be/n_L-E8K_gcg>\n");
|
|
149
|
+
const iframes = collect(tree, "iframe");
|
|
150
|
+
assert.equal(iframes.length, 1);
|
|
151
|
+
assert.equal(
|
|
152
|
+
iframes[0].properties.src,
|
|
153
|
+
"https://www.youtube-nocookie.com/embed/n_L-E8K_gcg",
|
|
154
|
+
);
|
|
155
|
+
// The responsive style must survive sanitization too.
|
|
156
|
+
assert.ok(String(iframes[0].properties.style).includes("aspect-ratio"));
|
|
157
|
+
});
|