Repository navigation
feat(site): show recent releases on the home page #779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ab0f455
feat(site): show recent releases on the home page
rohitg00 a250a32
fix(site): keep the build command under the host limit and harden rel…
rohitg00 97cc4b1
fix(site): keep release prose that follows a heading without a blank …
rohitg00 ddcd22f
fix(site): pick release summaries from prose only
rohitg00 62deb60
fix(site): close a release code fence only on a matching fence line
rohitg00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #!/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 = /^(?:#|\||[-*] )/; | ||
| const MARKDOWN_LINK = /\[[^\]]*\]\([^)]*\)/g; | ||
|
|
||
| function plainText(markdown) { | ||
| return String(markdown || '') | ||
| .replace(/!\[[^\]]*\]\([^)]*\)/g, '') | ||
| .replace(/\[([^\]]*)\]\([^)]*\)/g, '$1') | ||
| .replace(/[`*_]/g, '') | ||
| .replace(/\s+/g, ' ') | ||
| .trim(); | ||
| } | ||
|
|
||
| function isProse(paragraph) { | ||
| if (!paragraph || NON_PROSE_START.test(paragraph)) return false; | ||
| return /[A-Za-z0-9]/.test(paragraph.replace(MARKDOWN_LINK, '')); | ||
|
rohitg00 marked this conversation as resolved.
Resolved
rohitg00 marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| function summaryOf(body) { | ||
| const paragraphs = String(body || '').replace(/\r\n/g, '\n').replace(/^#{1,6} .*$/gm, '').split(/\n\s*\n/); | ||
|
rohitg00 marked this conversation as resolved.
Resolved
|
||
| 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 }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| '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(''), ''); | ||
| }); | ||
|
|
||
| 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'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.