From 2f811fc2ff70d68f41a4fa23896dccbdabf471d1 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 18:41:08 +1300 Subject: [PATCH] Blog: posts dated with a publish time and timezone, sorted by it; the date and author share a row with the page buttons under a full-width title --- frontend/content/blog/laravel-rust-rewrite.md | 2 +- .../content/blog/laravel-rust-starter-kit.md | 2 +- .../content/blog/weasyprint-case-study.md | 2 +- frontend/scripts/blog.d.mts | 19 ++++++ frontend/scripts/blog.mjs | 60 ++++++++++++++----- frontend/scripts/prerender.mjs | 15 ++--- frontend/src/__tests__/blog.test.ts | 40 +++++++++++++ frontend/src/pages/DocsPage.tsx | 19 +++--- frontend/src/styles.css | 26 +++++--- scripts/screenshots/pages.mjs | 3 + 10 files changed, 150 insertions(+), 38 deletions(-) create mode 100644 frontend/scripts/blog.d.mts create mode 100644 frontend/src/__tests__/blog.test.ts diff --git a/frontend/content/blog/laravel-rust-rewrite.md b/frontend/content/blog/laravel-rust-rewrite.md index 00c39987..73c9f4de 100644 --- a/frontend/content/blog/laravel-rust-rewrite.md +++ b/frontend/content/blog/laravel-rust-rewrite.md @@ -1,7 +1,7 @@ --- title: How we rewrote VisualCI in Laravel Rust description: VisualCI's server moved from Loco to Laravel Rust two days after Laravel Rust's first beta. How the port went, what fought us (Postgres arrays, composite keys, MCP and the request context), what the reviews and a screenshot run caught, and the fixes we sent upstream. -date: 2026-12-03 +date: 2026-12-03T21:51:22+13:00 author: Nathan Broadbent draft: false --- diff --git a/frontend/content/blog/laravel-rust-starter-kit.md b/frontend/content/blog/laravel-rust-starter-kit.md index 470b0d46..c97fed3f 100644 --- a/frontend/content/blog/laravel-rust-starter-kit.md +++ b/frontend/content/blog/laravel-rust-starter-kit.md @@ -1,7 +1,7 @@ --- title: A Laravel Rust starter kit for a production SaaS description: VisualCI is open source, and its server is a Laravel Rust app that runs in production. Clone it, delete the visual testing, and you start with sign-in, organizations, invitations, credit billing on Stripe, transactional email, an MCP server with OAuth, background jobs with heartbeats, and the tests and CI around them. -date: 2026-12-04 +date: 2026-12-04T03:49:04+13:00 author: Nathan Broadbent draft: false --- diff --git a/frontend/content/blog/weasyprint-case-study.md b/frontend/content/blog/weasyprint-case-study.md index 1273efd4..120b519f 100644 --- a/frontend/content/blog/weasyprint-case-study.md +++ b/frontend/content/blog/weasyprint-case-study.md @@ -1,7 +1,7 @@ --- title: "Case study: a WeasyPrint crash that shipped in four releases" description: For nine months and four releases, WeasyPrint crashed on documents with positioned content in a running header or footer. We replayed the commit that caused it with VisualCI and 17 realistic business documents, and the build flagged it on that commit. WeasyPrint's own sample documents never showed it. -date: 2026-12-04 +date: 2026-12-04T18:18:16+13:00 author: Nathan Broadbent image: linebreak-p23.png draft: false diff --git a/frontend/scripts/blog.d.mts b/frontend/scripts/blog.d.mts new file mode 100644 index 00000000..a160c7e7 --- /dev/null +++ b/frontend/scripts/blog.d.mts @@ -0,0 +1,19 @@ +// Types for src/__tests__/blog.test.ts. +export type Post = { + slug: string + title: string + description: string + date: string + day: string + time: number + author: string + image: string | null + draft: boolean + body: string +} +export function parsePost(slug: string, source: string): Post +export function loadPosts(options?: { drafts?: boolean }): Promise +export function sortPosts(posts: Post[]): Post[] +export function postMetaHtml(post: Post): string +export function postJsonLd(post: Post): string +export function atomFeed(posts: Post[], htmlBySlug: Map): string diff --git a/frontend/scripts/blog.mjs b/frontend/scripts/blog.mjs index c26c7ad8..bd78af95 100644 --- a/frontend/scripts/blog.mjs +++ b/frontend/scripts/blog.mjs @@ -2,7 +2,8 @@ // Markdown copy at /blog/.md, and the files in content/blog// (its images) served next to it. /blog/ lists // the posts, newest first, and /blog/feed.xml is their Atom feed. // -// Front matter: title, description, date (YYYY-MM-DD) and author, all required; `image`, a PNG or JPG in the post's +// Front matter: title, description, date and author, all required. `date` is when the post was published, with its +// time and timezone (2026-12-04T18:18:16+13:00): posts are sorted by it, and the page shows its date as written; `image`, a PNG or JPG in the post's // folder for its link preview; `draft: true` keeps a post out of the build unless VISUALCI_BLOG_DRAFTS=1 (a dev server). // A published post with a `[TODO` placeholder left in it fails the build. // With no published posts there's no /blog/ at all, so the site never links an empty blog. @@ -12,6 +13,8 @@ import { SITE, root } from './docs-source.mjs' export const blogDir = join(root, 'content/blog') +/** A publish time: date, time and a timezone (Z or an offset). */ +const DATETIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?(?:Z|[+-]\d{2}:\d{2})$/ const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/ /** Paths under /blog/ that can't be posts. */ const RESERVED = new Set(['feed', 'index']) @@ -25,7 +28,7 @@ async function exists(path) { } } -function parsePost(slug, source) { +export function parsePost(slug, source) { const file = `content/blog/${slug}.md` const match = source.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/) if (!match) throw new Error(`${file} has no front matter`) @@ -37,8 +40,9 @@ function parsePost(slug, source) { for (const key of ['title', 'description', 'date', 'author']) { if (!meta[key]) throw new Error(`${file} has no ${key}`) } - if (!/^\d{4}-\d{2}-\d{2}$/.test(meta.date) || Number.isNaN(Date.parse(`${meta.date}T00:00:00Z`))) { - throw new Error(`${file}: date must be YYYY-MM-DD, not ${meta.date}`) + // Two posts on one day are ordered by their times, so a date alone isn't enough. + if (!DATETIME.test(meta.date) || Number.isNaN(Date.parse(meta.date))) { + throw new Error(`${file}: date must be when the post was published, with its time and timezone (2026-12-04T18:18:16+13:00), not ${meta.date}`) } if (meta.image && !/\.(png|jpe?g)$/i.test(meta.image)) throw new Error(`${file}: image must be a PNG or JPG`) // A link or image by relative path (`chart.png`, `img/chart.png`) is a file in the post's folder. @@ -47,7 +51,11 @@ function parsePost(slug, source) { slug, title: meta.title, description: meta.description, + /** The publish time as written, with its timezone. */ date: meta.date, + /** The day it was published, in the timezone it was written in: what the page shows. */ + day: meta.date.slice(0, 10), + time: Date.parse(meta.date), author: meta.author, image: meta.image || null, draft: meta.draft === 'true', @@ -72,7 +80,12 @@ export async function loadPosts({ drafts = false } = {}) { if (!post.draft && post.body.includes('[TODO')) throw new Error(`content/blog/${slug}.md still has a [TODO]: fill it in or keep the post a draft`) if (!post.draft || drafts) posts.push(post) } - return posts.sort((a, b) => b.date.localeCompare(a.date) || a.slug.localeCompare(b.slug)) + return sortPosts(posts) +} + +/** Newest first by publish time; posts published at the same moment by slug, so the order never depends on the file system. */ +export function sortPosts(posts) { + return posts.sort((a, b) => b.time - a.time || a.slug.localeCompare(b.slug)) } /** Copy each post's folder (its images) to /blog//, next to its page. */ @@ -90,20 +103,39 @@ export const postImage = (post) => (post.image ? `${SITE}/blog/${post.slug}/${po const escapeHtml = (s) => s.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"') /** "3 December 2026", from YYYY-MM-DD. */ -export function formatDate(date) { - return new Date(`${date}T00:00:00Z`).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' }) +export function formatDate(day) { + return new Date(`${day}T00:00:00Z`).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' }) } -/** The line under a post's title: its date and author. */ +const dateHtml = (post) => `` + +/** The line under a post's title, beside View as Markdown and Copy page: its date and author (inner HTML). */ export function postMetaHtml(post) { - return `

· ${escapeHtml(post.author)}${post.draft ? ' · Draft' : ''}

\n` + return `${dateHtml(post)} · ${escapeHtml(post.author)}${post.draft ? ' · Draft' : ''}` +} + +/** The post's schema.org BlogPosting, for its page's . */ +export function postJsonLd(post) { + const data = { + '@context': 'https://schema.org', + '@type': 'BlogPosting', + headline: post.title, + description: post.description, + datePublished: post.date, + author: { '@type': 'Person', name: post.author }, + publisher: { '@type': 'Organization', name: 'VisualCI', url: SITE }, + url: `${SITE}${postPath(post)}`, + mainEntityOfPage: `${SITE}${postPath(post)}`, + ...(post.image ? { image: postImage(post) } : {}), + } + return `` } /** /blog/: every post, newest first. */ export function indexHtml(posts) { const items = posts.map( (p) => - `
  • ${escapeHtml(p.title)}

    · ${escapeHtml(p.author)}

    ${escapeHtml(p.description)}

  • `, + `
  • ${escapeHtml(p.title)}

    ${dateHtml(p)} · ${escapeHtml(p.author)}

    ${escapeHtml(p.description)}

  • `, ) return `

    Notes from the people building VisualCI. Follow along with the Atom feed.

    \n
      ${items.join('')}
    \n` } @@ -111,21 +143,21 @@ export function indexHtml(posts) { export function indexMarkdown(posts) { return [ `Notes from the people building VisualCI. Atom feed: ${SITE}/blog/feed.xml`, - posts.map((p) => `- [${p.title}](${SITE}${postMarkdown(p)}) (${p.date}, ${p.author}): ${p.description}`).join('\n'), + posts.map((p) => `- [${p.title}](${SITE}${postMarkdown(p)}) (${p.day}, ${p.author}): ${p.description}`).join('\n'), ].join('\n\n') } /** The Atom feed, with each post's full HTML and absolute URLs (feed readers resolve nothing). */ export function atomFeed(posts, htmlBySlug) { const absolute = (html) => html.replace(/(href|src)="\/(?!\/)/g, `$1="${SITE}/`) - const updated = `${posts[0].date}T00:00:00Z` + const updated = posts[0].date const entries = posts.map( (p) => ` ${escapeHtml(p.title)} ${SITE}${postPath(p)} - ${p.date}T00:00:00Z - ${p.date}T00:00:00Z + ${p.date} + ${p.date} ${escapeHtml(p.author)} ${escapeHtml(p.description)} ${escapeHtml(absolute(htmlBySlug.get(p.slug)))} diff --git a/frontend/scripts/prerender.mjs b/frontend/scripts/prerender.mjs index 35fb04d8..975291d6 100644 --- a/frontend/scripts/prerender.mjs +++ b/frontend/scripts/prerender.mjs @@ -13,7 +13,7 @@ import { pathToFileURL } from 'node:url' import { Marked } from 'marked' import { SITE, absoluteLinks, pageSlugs, parsePage, readPage, root } from './docs-source.mjs' import { buildHosts, hostsMeta } from './hosts.mjs' -import { atomFeed, copyPostFiles, indexHtml, indexMarkdown, loadPosts, postImage, postMarkdown, postMetaHtml, postPath } from './blog.mjs' +import { atomFeed, copyPostFiles, indexHtml, indexMarkdown, loadPosts, postImage, postJsonLd, postMarkdown, postMetaHtml, postPath } from './blog.mjs' const dist = join(root, 'dist') @@ -131,10 +131,10 @@ for (const slug of await standaloneSlugs(join(root, 'content/pages'))) { } /** Write a page outside the docs: //index.html in the docs' design, and its Markdown copy. `ogImage` replaces * the site's link-preview image, and `head` is added to the page's (the blog's feed link). */ -async function writeStandalone({ slug, title, description, html: body, copy, ogImage = null, head = '' }) { +async function writeStandalone({ slug, title, description, html: body, copy, ogImage = null, head = '', meta }) { const markdown = standaloneMarkdown(slug) const path = standalonePath(slug) - const data = { slug, title, description, html: body, nav: [], markdown } + const data = { slug, title, description, html: body, nav: [], markdown, ...(meta ? { meta } : {}) } const json = JSON.stringify(data).replace(/', renderDoc(data), 'docs.html') @@ -314,10 +314,11 @@ if (posts.length) { slug: `blog/${post.slug}`, title: post.title, description: post.description, - html: postMetaHtml(post) + body, - copy: `${post.date}, ${post.author}\n\n${absoluteLinks(post.body)}`, + html: body, + meta: postMetaHtml(post), + copy: `${post.day}, ${post.author}\n\n${absoluteLinks(post.body)}`, ogImage: postImage(post), - head: feedLink, + head: `${feedLink}\n ${postJsonLd(post)}`, }) } await writeStandalone({ @@ -372,7 +373,7 @@ ${ Notes from the people building VisualCI, newest first. Markdown copies (all of them: ${SITE}/blog/index.md; Atom feed: ${SITE}/blog/feed.xml): -${posts.map((p) => `- [${p.title}](${SITE}${postMarkdown(p)}) (${p.date}): ${p.description}`).join('\n')} +${posts.map((p) => `- [${p.title}](${SITE}${postMarkdown(p)}) (${p.day}): ${p.description}`).join('\n')} ` : '' diff --git a/frontend/src/__tests__/blog.test.ts b/frontend/src/__tests__/blog.test.ts new file mode 100644 index 00000000..3cf5ffee --- /dev/null +++ b/frontend/src/__tests__/blog.test.ts @@ -0,0 +1,40 @@ +// @vitest-environment node +import { describe, expect, it } from 'vitest' +import { atomFeed, loadPosts, parsePost, postJsonLd, postMetaHtml, sortPosts } from '../../scripts/blog.mjs' + +const post = (slug: string, date: string) => + parsePost(slug, `---\ntitle: ${slug}\ndescription: A post.\ndate: ${date}\nauthor: Nathan Broadbent\n---\n\nBody.\n`) + +describe('blog', () => { + it('needs a publish time with a timezone, not just a date', () => { + expect(() => post('a', '2026-12-04')).toThrow(/time and timezone/) + expect(() => post('a', '2026-12-04T18:18:16')).toThrow(/time and timezone/) + expect(post('a', '2026-12-04T18:18:16+13:00').time).toBe(Date.parse('2026-12-04T05:18:16Z')) + expect(post('a', '2026-12-04T05:18:16Z').day).toBe('2026-12-04') + }) + + it('sorts by publish time across timezones, then by slug', () => { + const posts = [ + post('a-early', '2026-12-04T03:49:04+13:00'), + post('z-late', '2026-12-04T18:18:16+13:00'), + post('b-utc', '2026-12-04T05:00:00Z'), // 18:00 in New Zealand: between the two + post('a-same', '2026-12-04T05:00:00Z'), + ] + expect(sortPosts(posts).map((p) => p.slug)).toEqual(['z-late', 'a-same', 'b-utc', 'a-early']) + }) + + it('shows the day as written and puts the full time in