|
| 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">←</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">→</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 | +} |
0 commit comments