Skip to content

Commit 2f811fc

Browse files
committed
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
1 parent bd46bd1 commit 2f811fc

10 files changed

Lines changed: 150 additions & 38 deletions

File tree

‎frontend/content/blog/laravel-rust-rewrite.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: How we rewrote VisualCI in Laravel Rust
33
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.
4-
date: 2026-12-03
4+
date: 2026-12-03T21:51:22+13:00
55
author: Nathan Broadbent
66
draft: false
77
---

‎frontend/content/blog/laravel-rust-starter-kit.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: A Laravel Rust starter kit for a production SaaS
33
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.
4-
date: 2026-12-04
4+
date: 2026-12-04T03:49:04+13:00
55
author: Nathan Broadbent
66
draft: false
77
---

‎frontend/content/blog/weasyprint-case-study.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Case study: a WeasyPrint crash that shipped in four releases"
33
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.
4-
date: 2026-12-04
4+
date: 2026-12-04T18:18:16+13:00
55
author: Nathan Broadbent
66
image: linebreak-p23.png
77
draft: false

‎frontend/scripts/blog.d.mts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Types for src/__tests__/blog.test.ts.
2+
export type Post = {
3+
slug: string
4+
title: string
5+
description: string
6+
date: string
7+
day: string
8+
time: number
9+
author: string
10+
image: string | null
11+
draft: boolean
12+
body: string
13+
}
14+
export function parsePost(slug: string, source: string): Post
15+
export function loadPosts(options?: { drafts?: boolean }): Promise<Post[]>
16+
export function sortPosts(posts: Post[]): Post[]
17+
export function postMetaHtml(post: Post): string
18+
export function postJsonLd(post: Post): string
19+
export function atomFeed(posts: Post[], htmlBySlug: Map<string, string>): string

‎frontend/scripts/blog.mjs‎

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Markdown copy at /blog/<slug>.md, and the files in content/blog/<slug>/ (its images) served next to it. /blog/ lists
33
// the posts, newest first, and /blog/feed.xml is their Atom feed.
44
//
5-
// Front matter: title, description, date (YYYY-MM-DD) and author, all required; `image`, a PNG or JPG in the post's
5+
// Front matter: title, description, date and author, all required. `date` is when the post was published, with its
6+
// 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
67
// folder for its link preview; `draft: true` keeps a post out of the build unless VISUALCI_BLOG_DRAFTS=1 (a dev server).
78
// A published post with a `[TODO` placeholder left in it fails the build.
89
// 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'
1213

1314
export const blogDir = join(root, 'content/blog')
1415

16+
/** A publish time: date, time and a timezone (Z or an offset). */
17+
const DATETIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?(?:Z|[+-]\d{2}:\d{2})$/
1518
const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
1619
/** Paths under /blog/ that can't be posts. */
1720
const RESERVED = new Set(['feed', 'index'])
@@ -25,7 +28,7 @@ async function exists(path) {
2528
}
2629
}
2730

28-
function parsePost(slug, source) {
31+
export function parsePost(slug, source) {
2932
const file = `content/blog/${slug}.md`
3033
const match = source.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/)
3134
if (!match) throw new Error(`${file} has no front matter`)
@@ -37,8 +40,9 @@ function parsePost(slug, source) {
3740
for (const key of ['title', 'description', 'date', 'author']) {
3841
if (!meta[key]) throw new Error(`${file} has no ${key}`)
3942
}
40-
if (!/^\d{4}-\d{2}-\d{2}$/.test(meta.date) || Number.isNaN(Date.parse(`${meta.date}T00:00:00Z`))) {
41-
throw new Error(`${file}: date must be YYYY-MM-DD, not ${meta.date}`)
43+
// Two posts on one day are ordered by their times, so a date alone isn't enough.
44+
if (!DATETIME.test(meta.date) || Number.isNaN(Date.parse(meta.date))) {
45+
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}`)
4246
}
4347
if (meta.image && !/\.(png|jpe?g)$/i.test(meta.image)) throw new Error(`${file}: image must be a PNG or JPG`)
4448
// 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) {
4751
slug,
4852
title: meta.title,
4953
description: meta.description,
54+
/** The publish time as written, with its timezone. */
5055
date: meta.date,
56+
/** The day it was published, in the timezone it was written in: what the page shows. */
57+
day: meta.date.slice(0, 10),
58+
time: Date.parse(meta.date),
5159
author: meta.author,
5260
image: meta.image || null,
5361
draft: meta.draft === 'true',
@@ -72,7 +80,12 @@ export async function loadPosts({ drafts = false } = {}) {
7280
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`)
7381
if (!post.draft || drafts) posts.push(post)
7482
}
75-
return posts.sort((a, b) => b.date.localeCompare(a.date) || a.slug.localeCompare(b.slug))
83+
return sortPosts(posts)
84+
}
85+
86+
/** Newest first by publish time; posts published at the same moment by slug, so the order never depends on the file system. */
87+
export function sortPosts(posts) {
88+
return posts.sort((a, b) => b.time - a.time || a.slug.localeCompare(b.slug))
7689
}
7790

7891
/** Copy each post's folder (its images) to /blog/<slug>/, next to its page. */
@@ -90,42 +103,61 @@ export const postImage = (post) => (post.image ? `${SITE}/blog/${post.slug}/${po
90103
const escapeHtml = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
91104

92105
/** "3 December 2026", from YYYY-MM-DD. */
93-
export function formatDate(date) {
94-
return new Date(`${date}T00:00:00Z`).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' })
106+
export function formatDate(day) {
107+
return new Date(`${day}T00:00:00Z`).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' })
95108
}
96109

97-
/** The line under a post's title: its date and author. */
110+
const dateHtml = (post) => `<time datetime="${post.date}">${formatDate(post.day)}</time>`
111+
112+
/** The line under a post's title, beside View as Markdown and Copy page: its date and author (inner HTML). */
98113
export function postMetaHtml(post) {
99-
return `<p class="blog-meta"><time datetime="${post.date}">${formatDate(post.date)}</time> · ${escapeHtml(post.author)}${post.draft ? ' · <strong>Draft</strong>' : ''}</p>\n`
114+
return `${dateHtml(post)} · ${escapeHtml(post.author)}${post.draft ? ' · <strong>Draft</strong>' : ''}`
115+
}
116+
117+
/** The post's schema.org BlogPosting, for its page's <head>. */
118+
export function postJsonLd(post) {
119+
const data = {
120+
'@context': 'https://schema.org',
121+
'@type': 'BlogPosting',
122+
headline: post.title,
123+
description: post.description,
124+
datePublished: post.date,
125+
author: { '@type': 'Person', name: post.author },
126+
publisher: { '@type': 'Organization', name: 'VisualCI', url: SITE },
127+
url: `${SITE}${postPath(post)}`,
128+
mainEntityOfPage: `${SITE}${postPath(post)}`,
129+
...(post.image ? { image: postImage(post) } : {}),
130+
}
131+
return `<script type="application/ld+json">${JSON.stringify(data).replace(/</g, '\\u003c')}</script>`
100132
}
101133

102134
/** /blog/: every post, newest first. */
103135
export function indexHtml(posts) {
104136
const items = posts.map(
105137
(p) =>
106-
`<li class="blog-item"><a class="blog-item-title" href="${postPath(p)}">${escapeHtml(p.title)}</a><p class="blog-meta"><time datetime="${p.date}">${formatDate(p.date)}</time> · ${escapeHtml(p.author)}</p><p class="blog-item-description">${escapeHtml(p.description)}</p></li>`,
138+
`<li class="blog-item"><a class="blog-item-title" href="${postPath(p)}">${escapeHtml(p.title)}</a><p class="blog-meta">${dateHtml(p)} · ${escapeHtml(p.author)}</p><p class="blog-item-description">${escapeHtml(p.description)}</p></li>`,
107139
)
108140
return `<p>Notes from the people building VisualCI. Follow along with the <a href="/blog/feed.xml">Atom feed</a>.</p>\n<ul class="blog-list">${items.join('')}</ul>\n`
109141
}
110142

111143
export function indexMarkdown(posts) {
112144
return [
113145
`Notes from the people building VisualCI. Atom feed: ${SITE}/blog/feed.xml`,
114-
posts.map((p) => `- [${p.title}](${SITE}${postMarkdown(p)}) (${p.date}, ${p.author}): ${p.description}`).join('\n'),
146+
posts.map((p) => `- [${p.title}](${SITE}${postMarkdown(p)}) (${p.day}, ${p.author}): ${p.description}`).join('\n'),
115147
].join('\n\n')
116148
}
117149

118150
/** The Atom feed, with each post's full HTML and absolute URLs (feed readers resolve nothing). */
119151
export function atomFeed(posts, htmlBySlug) {
120152
const absolute = (html) => html.replace(/(href|src)="\/(?!\/)/g, `$1="${SITE}/`)
121-
const updated = `${posts[0].date}T00:00:00Z`
153+
const updated = posts[0].date
122154
const entries = posts.map(
123155
(p) => ` <entry>
124156
<title>${escapeHtml(p.title)}</title>
125157
<link rel="alternate" type="text/html" href="${SITE}${postPath(p)}"/>
126158
<id>${SITE}${postPath(p)}</id>
127-
<published>${p.date}T00:00:00Z</published>
128-
<updated>${p.date}T00:00:00Z</updated>
159+
<published>${p.date}</published>
160+
<updated>${p.date}</updated>
129161
<author><name>${escapeHtml(p.author)}</name></author>
130162
<summary>${escapeHtml(p.description)}</summary>
131163
<content type="html">${escapeHtml(absolute(htmlBySlug.get(p.slug)))}</content>

‎frontend/scripts/prerender.mjs‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { pathToFileURL } from 'node:url'
1313
import { Marked } from 'marked'
1414
import { SITE, absoluteLinks, pageSlugs, parsePage, readPage, root } from './docs-source.mjs'
1515
import { buildHosts, hostsMeta } from './hosts.mjs'
16-
import { atomFeed, copyPostFiles, indexHtml, indexMarkdown, loadPosts, postImage, postMarkdown, postMetaHtml, postPath } from './blog.mjs'
16+
import { atomFeed, copyPostFiles, indexHtml, indexMarkdown, loadPosts, postImage, postJsonLd, postMarkdown, postMetaHtml, postPath } from './blog.mjs'
1717

1818
const dist = join(root, 'dist')
1919

@@ -131,10 +131,10 @@ for (const slug of await standaloneSlugs(join(root, 'content/pages'))) {
131131
}
132132
/** Write a page outside the docs: /<path>/index.html in the docs' design, and its Markdown copy. `ogImage` replaces
133133
* the site's link-preview image, and `head` is added to the page's <head> (the blog's feed link). */
134-
async function writeStandalone({ slug, title, description, html: body, copy, ogImage = null, head = '' }) {
134+
async function writeStandalone({ slug, title, description, html: body, copy, ogImage = null, head = '', meta }) {
135135
const markdown = standaloneMarkdown(slug)
136136
const path = standalonePath(slug)
137-
const data = { slug, title, description, html: body, nav: [], markdown }
137+
const data = { slug, title, description, html: body, nav: [], markdown, ...(meta ? { meta } : {}) }
138138
const json = JSON.stringify(data).replace(/</g, '\\u003c')
139139
let html = template
140140
html = fill(html, '<!--docs-->', renderDoc(data), 'docs.html')
@@ -314,10 +314,11 @@ if (posts.length) {
314314
slug: `blog/${post.slug}`,
315315
title: post.title,
316316
description: post.description,
317-
html: postMetaHtml(post) + body,
318-
copy: `${post.date}, ${post.author}\n\n${absoluteLinks(post.body)}`,
317+
html: body,
318+
meta: postMetaHtml(post),
319+
copy: `${post.day}, ${post.author}\n\n${absoluteLinks(post.body)}`,
319320
ogImage: postImage(post),
320-
head: feedLink,
321+
head: `${feedLink}\n ${postJsonLd(post)}`,
321322
})
322323
}
323324
await writeStandalone({
@@ -372,7 +373,7 @@ ${
372373
373374
Notes from the people building VisualCI, newest first. Markdown copies (all of them: ${SITE}/blog/index.md; Atom feed: ${SITE}/blog/feed.xml):
374375
375-
${posts.map((p) => `- [${p.title}](${SITE}${postMarkdown(p)}) (${p.date}): ${p.description}`).join('\n')}
376+
${posts.map((p) => `- [${p.title}](${SITE}${postMarkdown(p)}) (${p.day}): ${p.description}`).join('\n')}
376377
377378
`
378379
: ''
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// @vitest-environment node
2+
import { describe, expect, it } from 'vitest'
3+
import { atomFeed, loadPosts, parsePost, postJsonLd, postMetaHtml, sortPosts } from '../../scripts/blog.mjs'
4+
5+
const post = (slug: string, date: string) =>
6+
parsePost(slug, `---\ntitle: ${slug}\ndescription: A post.\ndate: ${date}\nauthor: Nathan Broadbent\n---\n\nBody.\n`)
7+
8+
describe('blog', () => {
9+
it('needs a publish time with a timezone, not just a date', () => {
10+
expect(() => post('a', '2026-12-04')).toThrow(/time and timezone/)
11+
expect(() => post('a', '2026-12-04T18:18:16')).toThrow(/time and timezone/)
12+
expect(post('a', '2026-12-04T18:18:16+13:00').time).toBe(Date.parse('2026-12-04T05:18:16Z'))
13+
expect(post('a', '2026-12-04T05:18:16Z').day).toBe('2026-12-04')
14+
})
15+
16+
it('sorts by publish time across timezones, then by slug', () => {
17+
const posts = [
18+
post('a-early', '2026-12-04T03:49:04+13:00'),
19+
post('z-late', '2026-12-04T18:18:16+13:00'),
20+
post('b-utc', '2026-12-04T05:00:00Z'), // 18:00 in New Zealand: between the two
21+
post('a-same', '2026-12-04T05:00:00Z'),
22+
]
23+
expect(sortPosts(posts).map((p) => p.slug)).toEqual(['z-late', 'a-same', 'b-utc', 'a-early'])
24+
})
25+
26+
it('shows the day as written and puts the full time in <time>, the feed and JSON-LD', () => {
27+
const p = post('a', '2026-12-04T03:49:04+13:00')
28+
expect(postMetaHtml(p)).toContain('<time datetime="2026-12-04T03:49:04+13:00">4 December 2026</time>')
29+
expect(postJsonLd(p)).toContain('"datePublished":"2026-12-04T03:49:04+13:00"')
30+
const feed = atomFeed([p], new Map([['a', '<p>Body.</p>']]))
31+
expect(feed).toContain('<published>2026-12-04T03:49:04+13:00</published>')
32+
expect(feed).toContain('<updated>2026-12-04T03:49:04+13:00</updated>')
33+
})
34+
35+
it('lists the WeasyPrint case study before the starter kit published earlier that day', async () => {
36+
const slugs = (await loadPosts()).map((p) => p.slug)
37+
expect(slugs.indexOf('weasyprint-case-study')).toBeLessThan(slugs.indexOf('laravel-rust-starter-kit'))
38+
expect(slugs.indexOf('laravel-rust-starter-kit')).toBeLessThan(slugs.indexOf('laravel-rust-rewrite'))
39+
})
40+
})

‎frontend/src/pages/DocsPage.tsx‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export type DocsPageData = {
1818
nav: DocsNavSection[]
1919
/** The page's Markdown copy, when it isn't the docs' `/docs/<slug>.md`. */
2020
markdown?: string
21+
/** A blog post's date and author (HTML from scripts/blog.mjs), on the row under the title beside the buttons. */
22+
meta?: string
2123
}
2224

2325
function Sidebar({ nav, slug }: { nav: DocsNavSection[]; slug: string }) {
@@ -108,15 +110,18 @@ export function DocsPage({ page }: { page: DocsPageData }) {
108110
)}
109111
<main className="docs-main">
110112
<article className="docs-content">
111-
<div className="docs-head">
113+
<header className="docs-head">
112114
<h1>{page.title}</h1>
113-
<div className="docs-actions">
114-
<a className="btn btn-sm" href={markdown}>
115-
<FileTextIcon size={15} aria-hidden /> View as Markdown
116-
</a>
117-
<CopyPage href={markdown} />
115+
<div className="docs-head-row">
116+
{page.meta && <p className="blog-meta" dangerouslySetInnerHTML={{ __html: page.meta }} />}
117+
<div className="docs-actions">
118+
<a className="btn btn-sm" href={markdown}>
119+
<FileTextIcon size={15} aria-hidden /> View as Markdown
120+
</a>
121+
<CopyPage href={markdown} />
122+
</div>
118123
</div>
119-
</div>
124+
</header>
120125
<div dangerouslySetInnerHTML={{ __html: page.html }} />
121126
</article>
122127
</main>

‎frontend/src/styles.css‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4041,25 +4041,37 @@ svg.regions-dim {
40414041
max-width: 72ch;
40424042
}
40434043

4044-
/* The page title on the left, View as Markdown and Copy page on the right, on one row (stacked on phones). */
4044+
/* The page title on a row of its own; under it a blog post's date and author on the left, and View as Markdown and
4045+
Copy page on the right. On a phone the buttons wrap below the date and author. */
40454046
.docs-head {
40464047
display: flex;
4047-
align-items: center;
4048-
justify-content: space-between;
4049-
gap: var(--space-4);
4048+
flex-direction: column;
4049+
gap: var(--space-3);
40504050
margin-bottom: var(--space-8);
40514051
}
40524052

4053+
.docs-head-row {
4054+
display: flex;
4055+
flex-wrap: wrap;
4056+
align-items: center;
4057+
gap: var(--space-2) var(--space-4);
4058+
min-width: 0;
4059+
}
4060+
4061+
.docs-content .docs-head-row .blog-meta {
4062+
margin: 0;
4063+
}
4064+
40534065
.docs-actions {
40544066
display: flex;
40554067
flex: none;
40564068
gap: var(--space-2);
4069+
margin-left: auto;
40574070
}
40584071

40594072
@media (max-width: 640px) {
4060-
.docs-head {
4061-
flex-direction: column;
4062-
align-items: flex-start;
4073+
.docs-actions {
4074+
margin-left: 0;
40634075
}
40644076
}
40654077

‎scripts/screenshots/pages.mjs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export function pages() {
2020
return [
2121
['landing', '/', false, ALL],
2222
['docs/index', '/docs/', false, ALL],
23+
// The blog's list (newest first: the order Nathan checks) and a post, whose header the docs pages share.
24+
['blog/index', '/blog/', false, ALL],
25+
['blog/post', '/blog/weasyprint-case-study/', false, ALL],
2326
['app/orgs', '/', true, ALL],
2427
['app/org', '/acme', true, ALL],
2528
['app/project/builds', '/acme/web', true, ALL],

0 commit comments

Comments
 (0)