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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ site/sitemap.xml
site/sitemap-index.xml
site/sitemap-lessons-*.xml
site/translation-coverage.json
site/releases.json
site/llms.txt
site/build-meta.js
site/certification-data.js
Expand Down
30 changes: 30 additions & 0 deletions site/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
populateCurriculumSummary();
populateStats();
renderPhases();
renderReleases();
initStaggerIndex();
initModal();
initCopyButton();
Expand Down Expand Up @@ -181,6 +182,35 @@
}
}

function releaseItemHtml(release) {
return '<li class="whats-new-item">'
+ '<time class="whats-new-date" datetime="' + escapeHtml(release.date) + '">' + escapeHtml(release.date) + '</time>'
+ '<a href="' + escapeHtml(release.url) + '" target="_blank" rel="noopener">' + escapeHtml(release.title) + '</a>'
+ (release.summary ? '<p class="whats-new-summary">' + escapeHtml(release.summary) + '</p>' : '')
+ '</li>';
}

function renderReleases() {
var section = document.getElementById('whats-new');
var list = document.getElementById('whatsNewList');
if (!section || !list || !window.fetch) return;
fetch('releases.json')
.then(function (response) { return response.ok ? response.json() : null; })
.then(function (data) {
var releases = data && Array.isArray(data.releases) ? data.releases : [];
var html = '';
for (var i = 0; i < releases.length; i++) {
var release = releases[i];
if (!release || !/^https:\/\/github\.com\//.test(release.url || '')) continue;
html += releaseItemHtml(release);
}
if (!html) return;
list.innerHTML = html;
section.hidden = false;
})
.catch(function () {});
}

function toRoman(num) {
var lookup = [
['M', 1000], ['CM', 900], ['D', 500], ['CD', 400],
Expand Down
88 changes: 88 additions & 0 deletions site/fetch-releases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env node
'use strict';

const fs = require('fs');
const path = require('path');

const REPOSITORY = 'rohitg00/ai-engineering-from-scratch';
const OUTPUT_PATH = path.join(__dirname, 'releases.json');
const RELEASE_URL = new RegExp(`^https://github\\.com/${REPOSITORY}/releases/tag/[A-Za-z0-9._-]+$`);
const MAX_RELEASES = 6;
const PAGE_SIZE = 30;
const MAX_SUMMARY = 180;
const NON_PROSE_START = /^(?:#|\||>|[-*+] |\d+\. )/;
const MARKDOWN_LINK = /\[([^\]]*)\](?:\([^)]*\)|\[[^\]]*\])/g;
const MARKDOWN_IMAGE = /!\[[^\]]*\](?:\([^)]*\)|\[[^\]]*\])/g;
const FENCED_BLOCK = /^((`|~)\2{2,}).*\n(?:[\s\S]*?\n)?\1\2*[ \t]*$/gm;
const HEADING_LINE = /^#{1,6} .*$/gm;

function plainText(markdown) {
return String(markdown || '')
.replace(MARKDOWN_IMAGE, '')
.replace(MARKDOWN_LINK, '$1')
.replace(/[`*_]/g, '')
.replace(/\s+/g, ' ')
.trim();
}

function isProse(paragraph) {
if (!paragraph || NON_PROSE_START.test(paragraph)) return false;
return /[\p{L}\p{N}]/u.test(paragraph.replace(MARKDOWN_LINK, ''));
}

function summaryOf(body) {
const paragraphs = String(body || '').replace(/\r\n/g, '\n').replace(FENCED_BLOCK, '').replace(HEADING_LINE, '').split(/\n\s*\n/);
const firstProse = paragraphs.map(paragraph => paragraph.trim()).find(isProse);
const text = plainText(firstProse);
if (text.length <= MAX_SUMMARY) return text;
const clipped = text.slice(0, MAX_SUMMARY);
return `${clipped.slice(0, Math.max(clipped.lastIndexOf(' '), 1)).replace(/[,;:.]$/, '')}...`;
}

function titleOf(release) {
const name = plainText(release.name) || String(release.tag_name || '');
const subtitle = /^Edition\s+\S+:\s*(.+)$/.exec(name);
return subtitle ? subtitle[1] : name;
}

function toEntries(releases) {
if (!Array.isArray(releases)) return [];
return releases
.filter(release => release && !release.draft && !release.prerelease)
.filter(release => RELEASE_URL.test(String(release.html_url || '')) && /^\d{4}-\d{2}-\d{2}/.test(String(release.published_at || '')))
.slice(0, MAX_RELEASES)
.map(release => ({
tag: String(release.tag_name),
title: titleOf(release),
date: String(release.published_at).slice(0, 10),
summary: summaryOf(release.body),
url: String(release.html_url),
}));
}

async function collectReleases({ fetchImpl = globalThis.fetch, token = process.env.GITHUB_TOKEN, timeoutMs = 8000 } = {}) {
const headers = { Accept: 'application/vnd.github+json', 'User-Agent': 'aifs-site-build' };
if (token) headers.Authorization = `Bearer ${token}`;
const response = await fetchImpl(`https://api.github.com/repos/${REPOSITORY}/releases?per_page=${PAGE_SIZE}`, {
headers,
signal: AbortSignal.timeout(timeoutMs),
redirect: 'error',
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return toEntries(await response.json());
}

async function main() {
let releases = [];
try {
releases = await collectReleases();
} catch (error) {
console.warn(`releases.json: GitHub releases unavailable (${error.message}); the home page hides the release list in this build`);
}
fs.writeFileSync(OUTPUT_PATH, JSON.stringify({ releases }, null, 2) + '\n', 'utf8');
console.log(`releases.json: ${releases.length} release${releases.length === 1 ? '' : 's'}`);
}

if (require.main === module) main();

module.exports = { collectReleases, toEntries, summaryOf, titleOf, OUTPUT_PATH };
82 changes: 82 additions & 0 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,79 @@
border-bottom: 1px solid var(--rule-soft);
}

.whats-new {
padding: 32px 0 40px;
border-bottom: 1px solid var(--rule-soft);
}

.whats-new[hidden] { display: none; }

.whats-new-title {
font-family: var(--font-mono);
font-size: 0.78rem;
letter-spacing: 0.16em;
text-transform: uppercase;
color: var(--blueprint);
margin-bottom: 16px;
}

.whats-new-list {
margin: 0;
padding: 0;
list-style: none;
border-top: 1px solid var(--rule-soft);
}

.whats-new-item {
display: grid;
grid-template-columns: 7.5rem minmax(0, 1fr);
gap: 4px 20px;
padding: 12px 0;
border-bottom: 1px solid var(--rule-soft);
}

.whats-new-date {
font-family: var(--font-mono);
font-size: 0.74rem;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--ink-soft);
padding-top: 3px;
}

.whats-new-item a {
font-family: var(--font-body);
font-size: 1.05rem;
font-weight: 600;
color: var(--ink);
}

.whats-new-item a:hover { color: var(--blueprint); }

.whats-new-summary {
grid-column: 2;
margin: 0;
font-size: 0.92rem;
line-height: 1.45;
color: var(--ink-soft);
}

.whats-new-links {
display: flex;
flex-wrap: wrap;
gap: 8px 24px;
margin: 16px 0 0;
font-family: var(--font-mono);
font-size: 0.78rem;
letter-spacing: 0.06em;
text-transform: uppercase;
}

@media (max-width: 600px) {
.whats-new-item { grid-template-columns: 1fr; }
.whats-new-summary { grid-column: 1; }
}

.stat-block-title {
font-family: var(--font-mono);
font-size: 0.78rem;
Expand Down Expand Up @@ -2558,6 +2631,15 @@ <h2 id="coursePathsTitle">Choose the work you want to do</h2>
</div>
</section>

<section class="whats-new container" id="whats-new" aria-labelledby="whatsNewTitle" hidden>
<div class="whats-new-title" id="whatsNewTitle">What's new · updated every release</div>
<ol class="whats-new-list" id="whatsNewList"></ol>
<p class="whats-new-links">
<a href="https://github.com/rohitg00/ai-engineering-from-scratch/releases" target="_blank" rel="noopener">All releases</a>
<a href="https://www.google.com/preferences/source?q=aiengineeringfromscratch.com" target="_blank" rel="noopener">Prefer us on Google</a>
</p>
</section>

<section class="toc container" id="contents">
<div class="toc-title reveal reveal--left">Curriculum · <span id="tocPhaseCount">20 phases</span> · <span id="tocLessonCount">542 lessons</span></div>
<div class="toc-subtitle reveal" style="--stagger-delay: 80ms;">Tap a phase to expand its lessons. Each one ships when its math, code, and test are all written.</div>
Expand Down
11 changes: 11 additions & 0 deletions site/prebuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node
'use strict';

const { execFileSync } = require('node:child_process');
const path = require('node:path');

const STEPS = ['fetch-translation-coverage.js', 'fetch-releases.js'];

for (const step of STEPS) {
execFileSync(process.execPath, [path.join(__dirname, step)], { stdio: 'inherit' });
}
88 changes: 88 additions & 0 deletions site/test_releases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
'use strict';

const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');

const { collectReleases, toEntries, summaryOf, titleOf } = require('./fetch-releases.js');

const RELEASE = {
tag_name: 'v2026.11.2',
name: 'Edition 2026.11.2: Lessons in Five Languages',
published_at: '2026-11-09T10:00:00Z',
html_url: 'https://github.com/rohitg00/ai-engineering-from-scratch/releases/tag/v2026.11.2',
body: 'Read each lesson in the **language** you use at work.\n\n[Start](https://example.com) · [Catalog](https://example.com)\n\n## Site\n\n- One',
};

test('release entries keep the subtitle, the date, and the first prose paragraph', () => {
const [entry] = toEntries([RELEASE]);
assert.deepEqual(entry, {
tag: 'v2026.11.2',
title: 'Lessons in Five Languages',
date: '2026-11-09',
summary: 'Read each lesson in the language you use at work.',
url: RELEASE.html_url,
});
assert.equal(titleOf({ name: 'Edition 2026.10.3', tag_name: 'v2026.10.3' }), 'Edition 2026.10.3');
});

test('release entries skip drafts, prereleases, foreign links, and overflow', () => {
const many = Array.from({ length: 9 }, (_, index) => Object.assign({}, RELEASE, { tag_name: `v${index}` }));
assert.equal(toEntries(many).length, 6);
assert.deepEqual(toEntries([Object.assign({}, RELEASE, { draft: true })]), []);
assert.deepEqual(toEntries([Object.assign({}, RELEASE, { prerelease: true })]), []);
assert.deepEqual(toEntries([Object.assign({}, RELEASE, { html_url: 'https://example.com/releases/tag/v1' })]), []);
assert.deepEqual(toEntries([Object.assign({}, RELEASE, { published_at: null })]), []);
const prereleases = Array.from({ length: 7 }, () => Object.assign({}, RELEASE, { prerelease: true }));
assert.equal(toEntries(prereleases.concat(many)).length, 6);
assert.deepEqual(toEntries({ message: 'rate limited' }), []);
});

test('release summaries clip long text at a word boundary and skip headings, tables, and link rows', () => {
const long = summaryOf(`${'word '.repeat(80)}`);
assert.ok(long.length <= 183);
assert.match(long, /word\.\.\.$/);
assert.equal(summaryOf('## Heading\n\n| a | b |\n\n- item\n\nThe prose.'), 'The prose.');
assert.equal(summaryOf('[New lessons](lesson.md) are now available.\n\nMore.'), 'New lessons are now available.');
assert.equal(summaryOf('[Start](https://a.example) · [Catalog](https://b.example)\n\nThe prose.'), 'The prose.');
assert.equal(summaryOf('## Heading\nProse right under it.'), 'Prose right under it.');
assert.equal(summaryOf('修复错误。\n\nMore.'), '修复错误。');
assert.equal(summaryOf('[Start][docs] · [Catalog][index]\n\nNew lessons are available.'), 'New lessons are available.');
assert.equal(summaryOf('[New lessons][docs] are available.'), 'New lessons are available.');
assert.equal(summaryOf('## Changes\n> Preview only.\n\nNew lessons are available.'), 'New lessons are available.');
assert.equal(summaryOf('## Run\n```bash\nnpm test\n\nnpm run build\n```\n\nRun the suite first.'), 'Run the suite first.');
assert.equal(summaryOf('````md\n```js\nrun()\n```\n\nstill code\n````\n\nThe prose.'), 'The prose.');
assert.equal(summaryOf('```\ncode\n``` not a close\n\nmore code\n```\n\nThe prose.'), 'The prose.');
assert.equal(summaryOf('~~~\ncode\n\nmore\n~~~\n\nThe prose.'), 'The prose.');
assert.equal(summaryOf('```\n```\n\nThe prose.'), 'The prose.');
assert.equal(summaryOf('1. First step\n\nThe prose.'), 'The prose.');
assert.equal(summaryOf(''), '');
});

test('release collection sends the token only when present and fails on a bad status', async () => {
const calls = [];
const ok = async (url, options) => {
calls.push({ url, options });
return { ok: true, json: async () => [RELEASE] };
};
assert.equal((await collectReleases({ fetchImpl: ok, token: '' })).length, 1);
assert.equal(calls[0].options.headers.Authorization, undefined);
await collectReleases({ fetchImpl: ok, token: 'abc' });
assert.equal(calls[1].options.headers.Authorization, 'Bearer abc');
assert.match(calls[0].url, /^https:\/\/api\.github\.com\/repos\/rohitg00\/ai-engineering-from-scratch\/releases\?per_page=30$/);
await assert.rejects(collectReleases({ fetchImpl: async () => ({ ok: false, status: 403 }), token: '' }), /HTTP 403/);
});

test('the home page ships a hidden release list that the build step can fill', () => {
const homepage = fs.readFileSync(path.join(__dirname, 'index.html'), 'utf8');
const app = fs.readFileSync(path.join(__dirname, 'app.js'), 'utf8');
const config = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'vercel.json'), 'utf8'));
assert.match(homepage, /<section class="whats-new container" id="whats-new" aria-labelledby="whatsNewTitle" hidden>/);
assert.match(homepage, /href="https:\/\/www\.google\.com\/preferences\/source\?q=aiengineeringfromscratch\.com"/);
assert.match(app, /fetch\('releases\.json'\)/);
const prebuild = fs.readFileSync(path.join(__dirname, 'prebuild.js'), 'utf8');
assert.match(config.buildCommand, /^node site\/prebuild\.js && /);
assert.match(prebuild, /'fetch-translation-coverage\.js', 'fetch-releases\.js'/);
assert.ok(config.buildCommand.length <= 256, 'Vercel rejects a build command over 256 characters');
});
2 changes: 1 addition & 1 deletion vercel.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"buildCommand": "node site/fetch-translation-coverage.js && node site/build.js && node site/build-projects.js --strict && node site/build-agents.js && node site/build-manuals.js && node site/build-search.js && node site/clean-urls.js && node site/version-assets.js",
"buildCommand": "node site/prebuild.js && node site/build.js && node site/build-projects.js --strict && node site/build-agents.js && node site/build-manuals.js && node site/build-search.js && node site/clean-urls.js && node site/version-assets.js",
"outputDirectory": "site",
"framework": null,
"installCommand": "npm install --no-audit --no-fund",
Expand Down
Loading