Skip to content

Commit 2ac862d

Browse files
committed
docs: put back the words that page descriptions were missing
Descriptions are generated from each page's first paragraph, and inline code spans were dropped rather than unwrapped - so the sentences survived and the nouns did not: "is the low-level database query interface. It re-exports ; most ..." "This guide covers managing Bun's lockfile () in your Stacks ..." The first lost `@stacksjs/query-builder` and `bun-query-builder`, which is why it begins with "is" and re-exports nothing at all. The second lost `bun.lock` and kept the brackets around the hole. Both are search-result and social-preview text, so they were the version of the page most people saw first. Rebuilt from the paragraphs they were taken from, with the code unwrapped instead of removed. `docs/basics/routing.md` was the third of these and was fixed in e679e1b, where the description had been two lines of TypeScript. `docs-frontmatter-intact.test.ts` checks only signatures that cannot occur in real prose: a literal `\n`, a space before a semicolon, and a space before empty parentheses. Two likelier-looking rules were tried and rejected - "starts with a lowercase verb" flags 61 perfectly good descriptions ("The Coupons module in the Commerce package ..."), and bare `()` flags a legitimate `validateSkill()`. `docs/marketing/product-hunt.md` has no frontmatter at all. Left alone: it is an internal launch-kit document, the only file in `docs/marketing/`, and not in the site nav.
1 parent 4841177 commit 2ac862d

3 files changed

Lines changed: 75 additions & 2 deletions

File tree

docs/bootcamp/how-to/bun-lock.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Bun Lockfile Management
3-
description: "This guide covers managing Bun's lockfile () in your Stacks application, including best practices for version control, troubleshooting, and team collaborat..."
3+
description: "This guide covers managing Bun's lockfile (bun.lock) in your Stacks application, including best practices for version control, troubleshooting, and team collaboration."
44
---
55
# Bun Lockfile Management
66

docs/packages/query-builder.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Query Builder
3-
description: "is the low-level database query interface. It re-exports ; most application code should use models and reach for the query builder when a query does not be..."
3+
description: "@stacksjs/query-builder is the low-level database query interface. It re-exports bun-query-builder; most application code should use models and reach for the query builder when a query does not belong on a model."
44
---
55
# Query Builder
66

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* No page description is missing the code that was in it.
3+
*
4+
* Descriptions are generated from each page's first paragraph, and inline code
5+
* spans were DROPPED rather than unwrapped. The sentences survived; the nouns
6+
* did not:
7+
*
8+
* "is the low-level database query interface. It re-exports ; most ..."
9+
* "This guide covers managing Bun's lockfile () in your Stacks ..."
10+
*
11+
* The first lost `@stacksjs/query-builder` and `bun-query-builder` - so it
12+
* begins with "is" and re-exports nothing. The second lost `bun.lock`, leaving
13+
* empty parentheses. `docs/basics/routing.md` went further and had two lines of
14+
* TypeScript in its description, complete with a literal `\n`.
15+
*
16+
* Only signatures that cannot occur in real prose are checked. "Starts with a
17+
* lowercase verb" looked promising and matched 61 perfectly good descriptions
18+
* ("The Coupons module in the Commerce package ..."), and bare `()` matches a
19+
* legitimate `validateSkill()`. What is left: a literal `\n`, a space before a
20+
* semicolon, and a space before empty parentheses.
21+
*/
22+
import { describe, expect, it } from 'bun:test'
23+
import { readdirSync, readFileSync, statSync } from 'node:fs'
24+
import { join } from 'node:path'
25+
26+
const root = new URL('../../../../../', import.meta.url).pathname
27+
28+
function markdownFiles(dir: string, found: string[] = []): string[] {
29+
for (const entry of readdirSync(dir)) {
30+
if (entry.startsWith('.'))
31+
continue
32+
33+
const full = join(dir, entry)
34+
if (statSync(full).isDirectory())
35+
markdownFiles(full, found)
36+
else if (entry.endsWith('.md'))
37+
found.push(full)
38+
}
39+
40+
return found
41+
}
42+
43+
/** A page's `description:`, or null when it has no frontmatter. */
44+
function description(file: string): string | null {
45+
const lines = readFileSync(file, 'utf-8').split('\n')
46+
if (lines[0]?.trim() !== '---')
47+
return null
48+
49+
const close = lines.findIndex((line, index) => index > 0 && line.trim() === '---')
50+
if (close < 0)
51+
return null
52+
53+
return lines.slice(1, close).find(line => line.startsWith('description:'))?.slice('description:'.length).trim() ?? null
54+
}
55+
56+
describe('documentation frontmatter', () => {
57+
it('has no description with its code spans eaten', () => {
58+
const damaged: string[] = []
59+
60+
for (const file of markdownFiles(join(root, 'docs'))) {
61+
const text = description(file)
62+
if (!text)
63+
continue
64+
65+
// A literal backslash-n means a multi-line snippet was flattened in.
66+
// ` ;` and ` ()` are what is left where a code span used to be.
67+
if (/\\n/.test(text) || /\s;/.test(text) || /\s\(\s*\)/.test(text))
68+
damaged.push(`${file.replace(root, '')}: ${text.slice(0, 60)}`)
69+
}
70+
71+
expect(damaged.sort()).toEqual([])
72+
})
73+
})

0 commit comments

Comments
 (0)