Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/docs-site/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ function communityInvite(locale) {
const followLabel = strings.communityFollowLabel.replace("{platform}", "X");
return `<aside class="community-invite" aria-labelledby="community-invite-title" hidden>
<div class="community-invite__header">
<img class="community-invite__art community-invite__art--dark" src="${publicPath("/assets/community-invite-dark.webp")}" alt="" width="1024" height="512" loading="lazy" decoding="async">
<img class="community-invite__art community-invite__art--light" src="${publicPath("/assets/community-invite-light.webp")}" alt="" width="1024" height="512" loading="lazy" decoding="async">
<img class="community-invite__art community-invite__art--dark" src="${publicPath("/assets/community-invite-dark.webp")}" alt="" width="1024" height="512" loading="lazy" decoding="async" nopin="nopin" data-pin-nopin="true">
<img class="community-invite__art community-invite__art--light" src="${publicPath("/assets/community-invite-light.webp")}" alt="" width="1024" height="512" loading="lazy" decoding="async" nopin="nopin" data-pin-nopin="true">
<div class="community-invite__marks" aria-hidden="true"><span dir="ltr">${icon("reddit")}${icon("discord")}${icon("x-social")}</span></div>
<button class="community-invite__close" type="button" data-community-invite-dismiss aria-label="${escapeAttr(strings.communityDismissLabel)}">${icon("x")}</button>
</div>
Expand Down
58 changes: 58 additions & 0 deletions scripts/docs-site/community-invite.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import test from "node:test";
import { DomUtils, parseDocument } from "htmlparser2";
import { chromeStrings } from "./chrome-strings.mjs";
import { fixture, write } from "./test-helpers/redirect-fixture.mjs";

test("community artwork opts out of Pinterest without changing the invitation or other images in any locale", (t) => {
const locales = Object.keys(chromeStrings);
const f = fixture(t, [], {
...Object.fromEntries(locales.map(locale => [`${locale === "en" ? "" : `${locale}/`}index.md`, "# Home\n"])),
"guide.md": "# Guide\n\n![Article image](/images/example.png)\n",
}, "/manual");
write(f.root, "docs/docs.json", JSON.stringify({
name: "Community invitation fixture",
navigation: { languages: locales.map(language => ({ language, tabs: [] })) },
}));
const built = f.build();
assert.equal(built.status, 0, built.stderr);

for (const [locale, slug] of [...locales.map(locale => [locale, "index"]), ["en", "guide"]]) {
const file = path.join(f.root, "dist/docs-site", locale === "en" ? "" : locale, slug === "index" ? "" : slug, "index.html");
const document = parseDocument(fs.readFileSync(file, "utf8"));
const all = predicate => DomUtils.findAll(predicate, document.children);
const invites = all(node => node.name === "aside" && node.attribs.class === "community-invite");
assert.equal(invites.length, 1, `${locale}/${slug}: invitation remains in the shared shell`);
const invite = invites[0];
const art = DomUtils.findAll(node => node.name === "img", invite.children);
assert.equal(art.length, 2);
for (const [index, theme] of ["dark", "light"].entries()) {
assert.deepEqual(art[index].attribs, {
class: `community-invite__art community-invite__art--${theme}`,
src: `/manual/assets/community-invite-${theme}.webp`,
alt: "", width: "1024", height: "512", loading: "lazy", decoding: "async",
nopin: "nopin", "data-pin-nopin": "true",
}, `${locale}/${slug}: ${theme} artwork retains its presentation and image-level opt-outs`);
}
const strings = chromeStrings[locale];
const title = DomUtils.findOne(node => node.attribs?.id === "community-invite-title", invite.children);
assert.equal(invite.attribs["aria-labelledby"], title.attribs.id);
assert.equal(DomUtils.textContent(title), strings.communityTitle);
const body = DomUtils.findOne(node => node.attribs?.class === "community-invite__text", invite.children);
assert.equal(DomUtils.textContent(body), strings.communityBody);
const dismiss = DomUtils.findOne(node => node.name === "button" && "data-community-invite-dismiss" in node.attribs, invite.children);
assert.equal(dismiss.attribs["aria-label"], strings.communityDismissLabel);
const links = DomUtils.findAll(node => node.name === "a", invite.children);
assert.deepEqual(links.map(node => [DomUtils.textContent(node).trim(), node.attribs.href]), [
[strings.communityJoin, "https://www.reddit.com/r/openclaw/"],
[strings.communityJoin, "https://discord.com/invite/clawd"],
[strings.communityFollow, "https://x.com/openclaw"],
]);
const optedOut = all(node => node.attribs && ("nopin" in node.attribs || "data-pin-nopin" in node.attribs));
assert.deepEqual(optedOut, art, `${locale}/${slug}: only invitation images opt out`);
assert.equal(all(node => node.name === "meta" && node.attribs.name === "pinterest").length, 0);
assert.ok(all(node => node.name === "img" && !art.includes(node)).length > 0, "other images remain available");
}
});
5 changes: 5 additions & 0 deletions scripts/docs-site/smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ if (!communityInvite
DomUtils.findOne((node) => node.attribs?.class?.split(" ").includes("home-community"), indexDocument.children)?.children ?? [])) {
throw new Error("community invitation, dismissal control, or homepage Discord link is missing");
}
const communityArt = DomUtils.findAll((node) => node.name === "img", communityInvite.children);
if (communityArt.length !== 2
|| communityArt.some((node) => node.attribs.nopin !== "nopin" || node.attribs["data-pin-nopin"] !== "true")) {
throw new Error("community invitation artwork must opt out of Pinterest saves in both themes");
}
const communityLinks = DomUtils.findAll((node) => node.name === "a", communityInvite.children);
const expectedCommunityLinks = [
["Join", "https://www.reddit.com/r/openclaw/", "Join the OpenClaw community on Reddit"],
Expand Down
Loading