From 9db77bdab33a3c5ce0d9743c3d639dd977e60cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20=C5=BDydyk?= Date: Fri, 27 Nov 2026 13:59:51 +0100 Subject: [PATCH] Audit fixes: SRI for CDN files, OG extras, Course structured data, 404 page --- index.html | 13 ++++++++----- scripts/build-pages.mjs | 28 +++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index df77392..143e201 100644 --- a/index.html +++ b/index.html @@ -9,15 +9,18 @@ + + + - + - - - + + + + diff --git a/scripts/build-pages.mjs b/scripts/build-pages.mjs index 644aaa2..d012541 100644 --- a/scripts/build-pages.mjs +++ b/scripts/build-pages.mjs @@ -25,7 +25,10 @@ const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '&l const strip = (s) => String(s).replace(/<[^>]+>/g, '').replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&').replace(/\s+/g, ' ').trim(); const pre = (label, src) => `
${esc(label)}
${esc(src)}
`; -function page({ slug, title, description, body }) { +// JSON for a `; + +function page({ slug, title, description, body, head = '' }) { const url = slug ? `${SITE}${slug}/` : SITE; const set = (s, re, value) => { if (!re.test(s)) throw new Error(`index.html: ${re} not found`); @@ -39,6 +42,7 @@ function page({ slug, title, description, body }) { s = set(s, //, ``); s = set(s, //, ``); s = set(s, //, ``); + if (head) s = set(s, /<\/head>/, `${head}\n`); if (slug) s = set(s, //, ``); s = set(s, /
<\/main>/, `
${body}
`); const file = path.join(out, slug, 'index.html'); @@ -56,6 +60,19 @@ urls.push( description: 'Learn to read Rust and make small changes to it, using the Python you already know. Side-by-side examples, quizzes and runnable exercises.', body: `

Learn to read Rust using the Python you already know

    ${lessonLinks}

Python → Rust phrasebook · Rust compiler error index

`, + head: ldJson({ + '@context': 'https://schema.org', + '@type': 'Course', + name: 'Rust for Pythonistas', + description: 'Learn to read Rust and make small changes to it, using the Python you already know.', + url: SITE, + inLanguage: 'en', + isAccessibleForFree: true, + educationalLevel: 'Beginner', + teaches: 'Reading and changing Rust code, for Python developers', + provider: { '@type': 'Person', name: 'Roman Žydyk', url: 'https://romanzdk.com' }, + hasPart: LESSONS.map((l) => ({ '@type': 'LearningResource', name: strip(l.title), url: `${SITE}${l.id}/` })), + }), }), ); @@ -93,6 +110,15 @@ urls.push( }), ); +// GitHub Pages serves this for any missing URL, at any depth: absolute base, not indexed, the app shows the course start. +fs.writeFileSync( + path.join(out, '404.html'), + html + .replace('', '\n \n ') + .replace(/[^<]*<\/title>/, '<title>Page not found · Rust for Pythonistas') + .replace(/\s*/, ''), +); + fs.writeFileSync(path.join(out, 'sitemap.xml'), ` ${urls.map((u) => ` ${u}`).join('\n')}