33 * Build GitHub Pages site from catalog markdown frontmatter.
44 * Add/edit one catalog/<category>/<id>.md → rebuild regenerates everything.
55 */
6+ import { execFileSync } from "node:child_process" ;
67import fs from "node:fs" ;
78import path from "node:path" ;
89import { fileURLToPath } from "node:url" ;
9- import { commercialLabel , ENGINE_LOCK_LABELS , ENGINE_LOCK_NOTES , esc , latestAllowedDate , MAINTENANCE_NOTES , PERSPECTIVE_LABELS , sponsorButtonHtml , verifiedAge } from "./lib/shared.mjs" ;
10+ import { baseHeadHtml , commercialLabel , ENGINE_LOCK_LABELS , ENGINE_LOCK_NOTES , esc , latestAllowedDate , MAINTENANCE_NOTES , OG_CARD_NAME , PERSPECTIVE_LABELS , sponsorButtonHtml , verifiedAge } from "./lib/shared.mjs" ;
1011import { parseFrontmatter , summaryFromBody } from "./lib/frontmatter.mjs" ;
1112import { listEntryFiles } from "./lib/entry-files.mjs" ;
1213import { entryPageHtml , scriptJson } from "./lib/entry-page.mjs" ;
1314import { LinkError , makeLinkResolver } from "./lib/links.mjs" ;
14- import { atomFeed , catalogCsv , homeJsonLd } from "./lib/exports.mjs" ;
15+ import { atomFeed , catalogCsv , homeJsonLd , sitemapXml } from "./lib/exports.mjs" ;
1516import { llmsFullTxt , llmsTxt } from "./lib/llms.mjs" ;
1617import { deprecationReason , MarkdownError , renderBlocks , renderInline , splitEntryBody } from "./lib/markdown.mjs" ;
1718import { checkPage } from "./lib/page-checks.mjs" ;
@@ -32,7 +33,6 @@ const FORMATS_PATH = path.join(__dirname, "format-vocabulary.json");
3233// Social preview image: a first-party screenshot of this site, kept with the
3334// other first-party stills (the validator allows binaries there) and copied
3435// into dist at build time.
35- const OG_CARD_NAME = "og-card.png" ;
3636const OG_CARD_SRC = path . join ( ROOT , "docs" , "images" , "readme" , OG_CARD_NAME ) ;
3737
3838/** Sort rank for "license permissiveness": least owed first. */
@@ -186,7 +186,7 @@ function entryRowHtml(entry, repo, now) {
186186 <p>${ esc ( entry . summary || "" ) } </p>
187187 <div class="meta-line">
188188 <span>${ esc ( entry . category ) } </span>${ formats } ${ taxonomy }
189- <span class="verified is-${ age . bucket } " data-verified="${ esc ( entry . verified || "" ) } " title="License last checked at the source">${ esc ( ageText ) } </span>
189+ <span class="verified is-${ age . bucket } " data-verified="${ esc ( entry . verified || "" ) } " title="Licence last checked at the source">${ esc ( ageText ) } </span>
190190 </div>
191191 <div class="entry-links">
192192 <a href="${ esc ( entry . url ) } " rel="noopener noreferrer">Open source</a>
@@ -269,54 +269,43 @@ function guideRowsHtml(guides, repo) {
269269}
270270
271271function headMetaHtml ( site , stats , generatedAt , hasCard ) {
272- const url = site . siteUrl ;
273- const title = site . title ;
274- const desc = site . tagline ;
275- const card = `${ url . replace ( / \/ + $ / , "" ) } /${ OG_CARD_NAME } ` ;
276- const cardMeta = hasCard
277- ? [
278- `<meta property="og:image" content="${ esc ( card ) } " />` ,
279- `<meta property="og:image:width" content="1200" />` ,
280- `<meta property="og:image:height" content="630" />` ,
281- `<meta property="og:image:alt" content="${ esc ( `${ title } : ${ desc } ` ) } " />` ,
282- `<meta name="twitter:card" content="summary_large_image" />` ,
283- `<meta name="twitter:image" content="${ esc ( card ) } " />` ,
284- ]
285- : [ `<meta name="twitter:card" content="summary" />` ] ;
286272 return [
287- `<link rel="canonical" href="${ esc ( url ) } " />` ,
288- // robots.txt is only read at a host's root, so under a project Pages path
289- // its Sitemap line is never seen; point at the sitemap from the page too.
290- `<link rel="sitemap" type="application/xml" href="${ esc ( url . replace ( / \/ + $ / , "" ) ) } /sitemap.xml" />` ,
291- `<link rel="alternate" type="application/atom+xml" title="${ esc ( title ) } : recently verified" href="${ esc ( url . replace ( / \/ + $ / , "" ) ) } /feed.xml" />` ,
292- `<meta name="theme-color" content="#1a4d3e" media="(prefers-color-scheme: light)" />` ,
293- `<meta name="theme-color" content="#0f1216" media="(prefers-color-scheme: dark)" />` ,
294- `<meta property="og:type" content="website" />` ,
295- `<meta property="og:site_name" content="${ esc ( title ) } " />` ,
296- `<meta property="og:title" content="${ esc ( title ) } " />` ,
297- `<meta property="og:description" content="${ esc ( desc ) } " />` ,
298- `<meta property="og:url" content="${ esc ( url ) } " />` ,
299- ...cardMeta ,
300- `<meta name="twitter:title" content="${ esc ( title ) } " />` ,
301- `<meta name="twitter:description" content="${ esc ( desc ) } " />` ,
273+ baseHeadHtml ( { site, title : site . title , description : site . tagline , url : site . siteUrl , hasCard } ) ,
302274 `<meta name="generator" content="site/build.mjs ${ esc ( generatedAt ) } " />` ,
303275 `<meta name="catalog:entries" content="${ stats . total } " />` ,
304276 `<script type="application/ld+json">${ scriptJson ( homeJsonLd ( { site, generatedAt, total : stats . total } ) ) } </script>` ,
305277 ] . join ( "\n " ) ;
306278}
307279
308- function sitemapXml ( site , entries , stacks = [ ] ) {
309- const base = site . siteUrl . replace ( / \/ + $ / , "" ) ;
310- const urls = [
311- ` <url><loc>${ esc ( base ) } /</loc></url>` ,
312- ` <url><loc>${ esc ( base ) } /freshness/</loc></url>` ,
313- ...stacks . map ( ( s ) => ` <url><loc>${ esc ( base ) } /stack/${ esc ( s . meta . id ) } /</loc><lastmod>${ esc ( s . meta . walked ) } </lastmod></url>` ) ,
314- ...entries . map (
315- ( e ) =>
316- ` <url><loc>${ esc ( base ) } /entry/${ esc ( e . id ) } /</loc>${ e . verified ? `<lastmod>${ esc ( e . verified ) } </lastmod>` : "" } </url>`
317- ) ,
318- ] ;
319- return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${ urls . join ( "\n" ) } \n</urlset>\n` ;
280+ /**
281+ * Repo-relative file => date of its last commit, from one `git log` over the
282+ * catalog and stacks. The sitemap's lastmod must never be earlier than the
283+ * last content change, and an entry's `verified` date is not that. Empty when
284+ * git is unavailable (a tarball, a shallow CI checkout with no history).
285+ */
286+ function lastCommitDates ( ) {
287+ const dates = new Map ( ) ;
288+ try {
289+ const out = execFileSync ( "git" , [ "log" , "--format=%x00%cs" , "--name-only" , "--" , "catalog" , "stacks" ] , {
290+ cwd : ROOT ,
291+ encoding : "utf8" ,
292+ maxBuffer : 64 * 1024 * 1024 ,
293+ stdio : [ "ignore" , "pipe" , "ignore" ] ,
294+ } ) ;
295+ let date = null ;
296+ for ( const line of out . split ( "\n" ) ) {
297+ if ( line . startsWith ( "\0" ) ) {
298+ date = line . slice ( 1 ) . trim ( ) ;
299+ continue ;
300+ }
301+ const file = line . trim ( ) ;
302+ // Newest commit first, so the first date seen for a file is its latest.
303+ if ( file && date && ! dates . has ( file ) ) dates . set ( file , date ) ;
304+ }
305+ } catch {
306+ // No git: the sitemap falls back to the build date.
307+ }
308+ return dates ;
320309}
321310
322311function robotsTxt ( site ) {
@@ -622,7 +611,7 @@ function main() {
622611 }
623612 fs . writeFileSync ( indexPath , html ) ;
624613
625- fs . writeFileSync ( path . join ( DIST , "sitemap.xml" ) , sitemapXml ( config . site , visible , stacks ) ) ;
614+ fs . writeFileSync ( path . join ( DIST , "sitemap.xml" ) , sitemapXml ( { site : config . site , entries : visible , stacks, stamp , modified : lastCommitDates ( ) } ) ) ;
626615 fs . writeFileSync ( path . join ( DIST , "robots.txt" ) , robotsTxt ( config . site ) ) ;
627616 fs . writeFileSync ( path . join ( DIST , "404.html" ) , notFoundHtml ( config . site ) ) ;
628617 fs . mkdirSync ( path . join ( DIST , "freshness" ) , { recursive : true } ) ;
0 commit comments