Skip to content

Commit 5777730

Browse files
TMHSDigitalclaude
andcommitted
site: entry page template, styles and Copy script
entryPageHtml renders one entry: breadcrumb, h1, lead, an "At a glance" facts panel with the credit line, three actions (source, GitHub file, report a problem via the correction template), the rendered body, and prev/next within the category. Canonical, Open Graph and Twitter tags, JSON-LD with `<` escaped, and noindex plus a banner for deprecated entries. entry.js only enables the Copy button; the page is complete without it. 17 new assertions (72 total). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wc67NX9MM964uaVGn4bpZJ
1 parent 94eabd5 commit 5777730

4 files changed

Lines changed: 370 additions & 0 deletions

File tree

‎site/lib/entry-page.mjs‎

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/** One entry's page. Pure: everything it needs is passed in. */
2+
import {
3+
commercialLabel,
4+
entryPageUrl,
5+
esc,
6+
PERSPECTIVE_LABELS,
7+
STATUS_NOTES,
8+
verifiedAge,
9+
} from "./shared.mjs";
10+
11+
export function jsonLd(entry, site) {
12+
const work = { "@type": "CreativeWork", name: entry.name, url: entry.url };
13+
if (entry.summary) work.description = entry.summary;
14+
if (entry.publisher) work.publisher = { "@type": "Organization", name: entry.publisher };
15+
if (entry.license_spdx) work.license = `https://spdx.org/licenses/${entry.license_spdx}.html`;
16+
const page = {
17+
"@context": "https://schema.org",
18+
"@type": "WebPage",
19+
name: `${entry.name} (${entry.license})`,
20+
url: entryPageUrl(site, entry.id),
21+
isPartOf: { "@type": "WebSite", name: site.title, url: site.siteUrl },
22+
mainEntity: work,
23+
};
24+
if (entry.summary) page.description = entry.summary;
25+
if (entry.verified) page.dateModified = entry.verified;
26+
return page;
27+
}
28+
29+
/** JSON for a <script> element: `<` escaped so no string can close the tag. */
30+
export function scriptJson(value) {
31+
return JSON.stringify(value).replace(/</g, "\\u003c");
32+
}
33+
34+
function credit(entry) {
35+
if (entry.attribution_required === true && entry.attribution_string) {
36+
return {
37+
value: "Required",
38+
script: true,
39+
block: `<div class="attribution">
40+
<p class="attribution-label">Credit line</p>
41+
<p class="attribution-string" id="attribution-string">${esc(entry.attribution_string)}</p>
42+
<button type="button" class="btn-ghost" id="copy-attribution" data-copy="${esc(entry.attribution_string)}" hidden>Copy credit line</button>
43+
<span class="copy-status" id="copy-status" role="status" aria-live="polite"></span>
44+
</div>`,
45+
};
46+
}
47+
if (entry.attribution_required === true) {
48+
return {
49+
value: "Required",
50+
script: false,
51+
block: `<p class="attribution-note">Attribution is required and no canned credit line is recorded. Read the Notes for what the source asks for.</p>`,
52+
};
53+
}
54+
if (entry.attribution_required === false) return { value: "Not required", script: false, block: "" };
55+
return { value: "Unclear: read the Notes", script: false, block: "" };
56+
}
57+
58+
export function entryPageHtml({ entry, leadHtml, restHtml, deprecatedReasonHtml, prev, next, site, categoryLabel, stamp, total, hasCard, now }) {
59+
const repo = site.repo;
60+
const url = entryPageUrl(site, entry.id);
61+
const title = `${entry.name} (${entry.license}) | ${site.title}`;
62+
const desc = entry.summary || site.tagline;
63+
const age = verifiedAge(entry.verified, now);
64+
const ageText = age.days === null ? "verified date unknown" : `${entry.verified} (${age.days}d ago)`;
65+
const c = credit(entry);
66+
const licence =
67+
entry.license_spdx && entry.license_spdx !== entry.license ? `${entry.license} (${entry.license_spdx})` : entry.license;
68+
const rows = [
69+
["Licence", esc(licence)],
70+
["Commercial use", esc(commercialLabel(entry.commercial))],
71+
["Credit", esc(c.value)],
72+
["Status", `${esc(entry.status)}: ${esc(STATUS_NOTES[entry.status] || "")}`],
73+
["Verified", `<span class="verified is-${age.bucket}">${esc(ageText)}</span>`],
74+
entry.publisher ? ["Publisher", esc(entry.publisher)] : null,
75+
["Formats", esc((entry.formats || []).join(", ") || "none listed")],
76+
entry.camera_perspective
77+
? ["Perspective", esc(PERSPECTIVE_LABELS[entry.camera_perspective] || entry.camera_perspective)]
78+
: null,
79+
entry.grid_dimensions ? ["Grid", esc(entry.grid_dimensions)] : null,
80+
]
81+
.filter(Boolean)
82+
.map(([k, v]) => `<div><dt>${k}</dt><dd>${v}</dd></div>`)
83+
.join("\n ");
84+
const deprecated = entry.status === "deprecated";
85+
const banner = deprecated
86+
? `<p class="deprecated-banner" role="note"><strong>Deprecated.</strong> ${deprecatedReasonHtml || "This entry is kept for history only."}</p>`
87+
: "";
88+
const issue = `${repo}/issues/new?template=correction.yml&title=${encodeURIComponent(`[correction] ${entry.id}`)}&entry=${encodeURIComponent(entry.id)}`;
89+
const card = `${String(site.siteUrl).replace(/\/+$/, "")}/og-card.png`;
90+
const cardMeta = hasCard
91+
? `<meta property="og:image" content="${esc(card)}" />
92+
<meta name="twitter:card" content="summary_large_image" />
93+
<meta name="twitter:image" content="${esc(card)}" />`
94+
: `<meta name="twitter:card" content="summary" />`;
95+
const pager =
96+
prev || next
97+
? `<nav class="page-pager" aria-label="More in ${esc(categoryLabel)}">
98+
${prev ? `<a class="btn-ghost" href="../${esc(prev.id)}/" rel="prev"><span aria-hidden="true">&larr;</span> ${esc(prev.name)}</a>` : "<span></span>"}
99+
${next ? `<a class="btn-ghost" href="../${esc(next.id)}/" rel="next">${esc(next.name)} <span aria-hidden="true">&rarr;</span></a>` : "<span></span>"}
100+
</nav>`
101+
: "";
102+
return `<!DOCTYPE html>
103+
<html lang="en">
104+
<head>
105+
<meta charset="utf-8" />
106+
<meta name="viewport" content="width=device-width, initial-scale=1" />
107+
<title>${esc(title)}</title>
108+
<meta name="description" content="${esc(desc)}" />
109+
<link rel="canonical" href="${esc(url)}" />
110+
${deprecated ? '<meta name="robots" content="noindex" />' : ""}
111+
<meta property="og:type" content="article" />
112+
<meta property="og:site_name" content="${esc(site.title)}" />
113+
<meta property="og:title" content="${esc(title)}" />
114+
<meta property="og:description" content="${esc(desc)}" />
115+
<meta property="og:url" content="${esc(url)}" />
116+
${cardMeta}
117+
<meta name="twitter:title" content="${esc(title)}" />
118+
<meta name="twitter:description" content="${esc(desc)}" />
119+
<link rel="icon" href="../../favicon.svg" type="image/svg+xml" />
120+
<link rel="preconnect" href="https://fonts.googleapis.com" />
121+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
122+
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Public+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap" rel="stylesheet" />
123+
<link rel="stylesheet" href="../../styles.css" />
124+
<script type="application/ld+json">${scriptJson(jsonLd(entry, site))}</script>
125+
</head>
126+
<body>
127+
<a class="skip-link" href="#content">Skip to entry</a>
128+
<header class="topbar">
129+
<a class="brand" href="../../">Free Game Dev Assets</a>
130+
<nav class="topnav" aria-label="Primary">
131+
<a href="../../#catalog">Catalog</a>
132+
<a href="../../#starters">Starters</a>
133+
<a href="../../#guides">Guides</a>
134+
<a href="${esc(repo)}" rel="noopener noreferrer">GitHub</a>
135+
</nav>
136+
</header>
137+
<main class="section entry-page" id="content">
138+
<nav class="breadcrumb" aria-label="Breadcrumb">
139+
<a href="../../#catalog">Catalog</a> <span aria-hidden="true">/</span>
140+
<a href="../../?cat=${encodeURIComponent(entry.category)}#catalog">${esc(categoryLabel)}</a> <span aria-hidden="true">/</span>
141+
<span aria-current="page">${esc(entry.name)}</span>
142+
</nav>
143+
${banner}
144+
<h1>${esc(entry.name)}</h1>
145+
<div class="entry-lead">${leadHtml}</div>
146+
<section class="facts-panel" aria-labelledby="facts-title">
147+
<h2 id="facts-title">At a glance</h2>
148+
<dl class="facts">
149+
${rows}
150+
</dl>
151+
${c.block}
152+
</section>
153+
<p class="page-actions">
154+
<a class="btn" href="${esc(entry.url)}" rel="noopener noreferrer">Go to source</a>
155+
<a class="btn-ghost" href="${esc(`${repo}/blob/main/${entry.path}`)}" rel="noopener noreferrer">View the file on GitHub</a>
156+
<a class="btn-ghost" href="${esc(issue)}" rel="noopener noreferrer">Report a problem with this entry</a>
157+
</p>
158+
<div class="entry-content">${restHtml}</div>
159+
${pager}
160+
</main>
161+
<footer class="footer">
162+
<p>Catalog metadata is CC0. Linked assets keep their own licenses: re-check the live source before shipping.</p>
163+
<p class="footer-stamp">Built ${esc(stamp)} from ${total} catalog entries.</p>
164+
</footer>
165+
${c.script ? '<script src="../../entry.js" defer></script>' : ""}
166+
</body>
167+
</html>
168+
`;
169+
}

‎site/lib/lib.test.mjs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,31 @@ eq("external flagged", resolve("https://a.test/x").external, true);
108108
throws("missing target fails", () => resolve("nope.md"), 'link target "nope.md" does not exist');
109109
throws("escaping the repo fails", () => resolve("../../../outside.md"), "does not exist");
110110

111+
/* entry page --------------------------------------------------------------- */
112+
import { entryPageHtml, jsonLd, scriptJson } from "./entry-page.mjs";
113+
const site = { siteUrl: "https://x.test/s/", title: "Free Game Dev Assets", tagline: "T", repo: "https://github.com/o/r" };
114+
const base = { id: "e1", name: 'A "quoted" <Name>', url: "https://src.test/", category: "2d", license: "CC-BY-4.0", license_spdx: "CC-BY-4.0", commercial: true, attribution_required: true, attribution_string: 'Art by "X" </script>', formats: ["PNG"], verified: "2026-09-01", status: "active", path: "catalog/2d/e1.md", summary: "Sum </script> <b>" };
115+
const page = (over = {}) => entryPageHtml({ entry: { ...base, ...over }, leadHtml: "<p>Lead</p>", restHtml: '<h2 id="notes">Notes</h2>', deprecatedReasonHtml: null, prev: null, next: { id: "e2", name: "Next one" }, site, categoryLabel: "2D", stamp: "2026-09-24", total: 319, hasCard: true, now: Date.parse("2026-09-24T00:00:00Z") });
116+
const p = page();
117+
has("title is escaped", p, "<title>A &quot;quoted&quot; &lt;Name&gt; (CC-BY-4.0) | Free Game Dev Assets</title>");
118+
has("canonical", p, '<link rel="canonical" href="https://x.test/s/entry/e1/" />');
119+
eq("one h1", (p.match(/<h1[\s>]/g) || []).length, 1);
120+
has("credit line escaped", p, "Art by &quot;X&quot; &lt;/script&gt;");
121+
has("copy script with a credit line", p, '<script src="../../entry.js" defer></script>');
122+
lacks("no copy script without one", page({ attribution_string: undefined }), "entry.js");
123+
has("note when credit is required but not canned", page({ attribution_string: undefined }), "no canned credit line");
124+
has("breadcrumb category link", p, "../../?cat=2d#catalog");
125+
has("next link", p, 'href="../e2/" rel="next"');
126+
has("report link prefills the entry", p, "template=correction.yml");
127+
lacks("active is indexable", p, 'content="noindex"');
128+
has("deprecated is noindex", page({ status: "deprecated" }), '<meta name="robots" content="noindex" />');
129+
has("deprecated banner", page({ status: "deprecated" }), 'class="deprecated-banner"');
130+
const ldBlock = p.match(/<script type="application\/ld\+json">([\s\S]*?)<\/script>/)[1];
131+
lacks("json-ld cannot close its script", ldBlock, "</script");
132+
eq("json-ld parses with a licence URL", JSON.parse(ldBlock).mainEntity.license, "https://spdx.org/licenses/CC-BY-4.0.html");
133+
eq("json-ld omits licence without spdx", jsonLd({ ...base, license: "custom", license_spdx: undefined }, site).mainEntity.license, undefined);
134+
eq("scriptJson escapes <", scriptJson({ a: "</script>" }), '{"a":"\\u003c/script>"}');
135+
111136
/* report (keep last) ------------------------------------------------------ */
112137
if (failures.length) {
113138
console.error(`lib.test failed (${failures.length}):`);

‎site/public/entry.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/** Copy button for an entry page's credit line. The page works without it. */
2+
(() => {
3+
const btn = document.getElementById("copy-attribution");
4+
if (!btn) return;
5+
btn.hidden = false;
6+
btn.addEventListener("click", async () => {
7+
const status = document.getElementById("copy-status");
8+
try {
9+
await navigator.clipboard.writeText(btn.getAttribute("data-copy"));
10+
status.textContent = "Copied";
11+
} catch {
12+
// Clipboard access can be refused; select the text so it can be
13+
// copied by hand rather than failing silently.
14+
const range = document.createRange();
15+
range.selectNodeContents(document.getElementById("attribution-string"));
16+
const sel = getSelection();
17+
sel.removeAllRanges();
18+
sel.addRange(range);
19+
status.textContent = "Select and copy";
20+
}
21+
});
22+
})();

‎site/public/styles.css‎

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,3 +1059,157 @@ input:focus-visible {
10591059
color: var(--muted);
10601060
font-variant-numeric: tabular-nums;
10611061
}
1062+
1063+
/* ------------------------------------------------------------------ *
1064+
* Entry pages (/entry/<id>/).
1065+
* ------------------------------------------------------------------ */
1066+
.breadcrumb {
1067+
margin: 0 0 1rem;
1068+
font-size: 0.85rem;
1069+
color: var(--muted);
1070+
}
1071+
1072+
.breadcrumb a {
1073+
color: var(--muted);
1074+
}
1075+
1076+
.breadcrumb a:hover {
1077+
color: var(--ink);
1078+
}
1079+
1080+
.entry-page h1 {
1081+
margin: 0 0 0.5rem;
1082+
font-size: clamp(1.8rem, 5vw, 2.4rem);
1083+
line-height: 1.1;
1084+
letter-spacing: -0.03em;
1085+
}
1086+
1087+
.entry-lead p {
1088+
max-width: 42rem;
1089+
margin: 0 0 0.75rem;
1090+
color: var(--muted);
1091+
font-size: 1.05rem;
1092+
}
1093+
1094+
.facts-panel {
1095+
margin: 1.25rem 0;
1096+
}
1097+
1098+
.facts-panel h2 {
1099+
margin: 0 0 0.5rem;
1100+
font-family: var(--mono);
1101+
font-size: 0.78rem;
1102+
font-weight: 500;
1103+
letter-spacing: 0.06em;
1104+
text-transform: uppercase;
1105+
color: var(--muted);
1106+
}
1107+
1108+
.facts {
1109+
display: grid;
1110+
gap: 0.4rem;
1111+
margin: 0;
1112+
padding: 0.75rem;
1113+
border: 1px solid var(--line);
1114+
font-family: var(--mono);
1115+
font-size: 0.8rem;
1116+
}
1117+
1118+
.facts div {
1119+
display: flex;
1120+
justify-content: space-between;
1121+
gap: 1rem;
1122+
}
1123+
1124+
.facts dt {
1125+
margin: 0;
1126+
color: var(--muted);
1127+
}
1128+
1129+
.facts dd {
1130+
margin: 0;
1131+
text-align: right;
1132+
}
1133+
1134+
.page-actions {
1135+
display: flex;
1136+
flex-wrap: wrap;
1137+
gap: 0.6rem;
1138+
margin: 1.25rem 0;
1139+
}
1140+
1141+
.page-actions .btn {
1142+
min-height: 44px;
1143+
}
1144+
1145+
.page-actions .btn-ghost,
1146+
.page-pager .btn-ghost {
1147+
display: inline-flex;
1148+
align-items: center;
1149+
min-height: 44px;
1150+
padding: 0.55rem 0.9rem;
1151+
border: 1px solid var(--line);
1152+
background: transparent;
1153+
color: var(--ink);
1154+
font: inherit;
1155+
font-weight: 600;
1156+
text-decoration: none;
1157+
}
1158+
1159+
.page-actions .btn-ghost:hover,
1160+
.page-pager .btn-ghost:hover {
1161+
border-color: var(--ink);
1162+
}
1163+
1164+
.entry-content h2 {
1165+
margin: 1.75rem 0 0.5rem;
1166+
font-size: 1.15rem;
1167+
letter-spacing: -0.01em;
1168+
}
1169+
1170+
.entry-content ul {
1171+
margin: 0;
1172+
padding-left: 1.25rem;
1173+
}
1174+
1175+
.entry-content li {
1176+
margin: 0.35rem 0;
1177+
}
1178+
1179+
.entry-content code,
1180+
.entry-lead code {
1181+
font-size: 0.85em;
1182+
overflow-wrap: anywhere;
1183+
}
1184+
1185+
.entry-content a,
1186+
.entry-lead a {
1187+
overflow-wrap: anywhere;
1188+
}
1189+
1190+
.deprecated-banner {
1191+
margin: 0 0 1rem;
1192+
padding: 0.75rem;
1193+
border: 1px solid var(--danger);
1194+
}
1195+
1196+
.page-pager {
1197+
display: flex;
1198+
flex-wrap: wrap;
1199+
justify-content: space-between;
1200+
gap: 0.75rem;
1201+
margin-top: 2rem;
1202+
padding-top: 1rem;
1203+
border-top: 1px solid var(--line);
1204+
}
1205+
1206+
@media (max-width: 640px) {
1207+
.facts div {
1208+
flex-direction: column;
1209+
gap: 0.1rem;
1210+
}
1211+
1212+
.facts dd {
1213+
text-align: left;
1214+
}
1215+
}

0 commit comments

Comments
 (0)