A link to the site showed a URL and a blank square. It now carries a title, a description, a canonical URL, an icon and a full set of OpenGraph and Twitter tags, so a page nobody has opened yet arrives as something you can look at. Two of those tags have to be ABSOLUTE and it is not a style question: a scraper fetching the page has no base to resolve `/cover.png` against and drops it silently. `build-site.ts` now copies the images into the output as well, because an `og:image` pointing at this host has to have the file ON this host — a card that 404s shows nothing, and nothing about the page itself looks wrong while it happens. The cover is a real 1200x630 render rather than a crop of a square one, which took a change to the renderer worth having anyway. `newFrame` and `frameCamera` both took a width and a height already; only `renderOne` was insisting they be equal. And with a non-square frame the old camera fit showed its flaw: it fitted the bounding SPHERE, which is one number and wrong for anything not roughly round. The kit scene is wide and flat, so its sphere is far taller than the scene is, and fitting that into the vertical field left the models in a band across the middle with empty air above and below — most of a 1.91:1 card. It now fits the BOX, iteratively, because perspective is not linear in distance: place the camera, project the eight corners, move by how far the worst one lands past the edge. Two passes is inside a pixel. That change improves every render, not just the card: on the contact sheet every model is visibly larger in its cell and nothing crops. `check-docs` now watches `viewer.html` too. Its description quotes the model count and the triangle total, which is the same sentence that went stale three times in the READMEs before that check existed — and a stale number in a card is worse than one in a README, because nobody reading the card can see the kit to know it is wrong. The description says "37" rather than "thirty-seven" for exactly that reason: a word is not a number the check can find. Also repointing the npm README's two images from `raw.githubusercontent.com` to the live site. They were pointing into a private repository and would have 404'd on npmjs.com; now they do not depend on the repository being readable at all.
126 lines
5.3 KiB
TypeScript
126 lines
5.3 KiB
TypeScript
/**
|
|
* Checks that the documentation still describes the kit that actually exists.
|
|
*
|
|
* This is here because the same thing went wrong three times. `REFERENCE.md`
|
|
* said "four items" when there were twenty-three, which is what `catalog-table`
|
|
* was written to fix — but that only regenerates the TABLE, and the prose
|
|
* around it kept its own copies of the numbers. On the day the oak was added
|
|
* the reference still claimed 27 models, 15,425 triangles and eleven material
|
|
* slots, all three of them wrong, in a document 751 lines long whose whole
|
|
* value is that a reader can trust it.
|
|
*
|
|
* A document with confident wrong numbers in it is worse than no document, so
|
|
* the numbers are checked the way the geometry is: against the models
|
|
* themselves, in CI, where being wrong fails rather than waits to be noticed.
|
|
*
|
|
* bun scripts/check-docs.ts
|
|
*/
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
import { Mesh } from 'three/webgpu'
|
|
|
|
import { MODEL_META } from '../my-registry/meta.ts'
|
|
import { CATALOG } from '@/catalog.ts'
|
|
|
|
const failures: string[] = []
|
|
|
|
function expect(label: string, ok: boolean, detail = ''): void {
|
|
if (ok) {
|
|
console.log(` PASS ${label}`)
|
|
} else {
|
|
console.log(` FAIL ${label}${detail ? ` — ${detail}` : ''}`)
|
|
failures.push(label)
|
|
}
|
|
}
|
|
|
|
// --- what the kit actually is ------------------------------------------------
|
|
const ids = Object.keys(CATALOG).filter((id) => MODEL_META[id] !== undefined && id !== 'pressure-gauge')
|
|
const slots = new Set<string>()
|
|
let triangles = 0
|
|
for (const id of ids) {
|
|
const built = CATALOG[id]!.build()
|
|
built.root.traverse((object) => {
|
|
if (!(object instanceof Mesh)) return
|
|
const index = object.geometry.getIndex()
|
|
triangles += (index ? index.count : object.geometry.getAttribute('position').count) / 3
|
|
})
|
|
built.dispose()
|
|
for (const slot of MODEL_META[id]!.materialSlots) slots.add(slot)
|
|
}
|
|
|
|
const models = ids.length
|
|
console.log(`kit: ${models} models · ${triangles} triangles · ${slots.size} material slots\n`)
|
|
|
|
/** Digits, however the document happens to group them: 31404, 31,404, 31 404. */
|
|
function hasNumber(text: string, value: number): boolean {
|
|
const digits = String(value)
|
|
const spaced = digits.replace(/\B(?=(\d{3})+(?!\d))/g, '[ , ]?')
|
|
return new RegExp(spaced).test(text)
|
|
}
|
|
|
|
const WORDS = [
|
|
'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine',
|
|
'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen',
|
|
'seventeen', 'eighteen', 'nineteen', 'twenty',
|
|
]
|
|
|
|
/**
|
|
* `viewer.html` is in this list because it is the published page.
|
|
*
|
|
* Its meta description is what a search result and a shared link show, and it
|
|
* quotes the model count and the triangle total — which is the same sentence
|
|
* that went stale three times in the READMEs before this check existed. A
|
|
* number in a card is worse than a number in a README: nobody reading the card
|
|
* can see the kit to know it is wrong.
|
|
*
|
|
* It carries no table, so the every-model-listed rule does not apply to it,
|
|
* any more than it does to the root README.
|
|
*/
|
|
const CARRIES_A_TABLE = new Set(['REFERENCE.md', 'my-registry/README.md'])
|
|
|
|
for (const file of ['README.md', 'REFERENCE.md', 'my-registry/README.md', 'viewer.html']) {
|
|
const text = readFileSync(file, 'utf8')
|
|
console.log(file)
|
|
|
|
expect(`${file}: model count`, hasNumber(text, models), `expected ${models}`)
|
|
expect(`${file}: triangle total`, hasNumber(text, triangles), `expected ${triangles}`)
|
|
|
|
// Every model has to appear by id, or the document is describing a smaller
|
|
// kit than the one it ships with. The registry README and the reference each
|
|
// carry a generated table; the root README does not, so it is exempt.
|
|
if (CARRIES_A_TABLE.has(file)) {
|
|
const missing = ids.filter((id) => !text.includes(`\`${id}\``))
|
|
expect(`${file}: every model listed`, missing.length === 0, missing.join(', '))
|
|
}
|
|
|
|
// A slot count written as a word ("thirteen slots") is the one number in
|
|
// these documents that cannot be grepped as a digit, and it was wrong.
|
|
//
|
|
// Looked up as a NUMBER WORD rather than as any word. The first version took
|
|
// whatever word preceded "slots", matched the ordinary phrase "material
|
|
// slots" several paragraphs earlier, found that "material" is not a number,
|
|
// and quietly checked nothing at all — a check that passes by not running is
|
|
// worse than no check, because it reads as evidence.
|
|
const written = text.match(new RegExp(`\\b(${WORDS.join('|')}) (?:material )?slots\\b`, 'i'))
|
|
expect(
|
|
`${file}: slot count in words`,
|
|
written === null || WORDS.indexOf(written[1]!.toLowerCase()) === slots.size,
|
|
written ? `says "${written[1]}", kit has ${slots.size}` : '',
|
|
)
|
|
|
|
// Any model named in prose but not in the kit at all: a rename that got
|
|
// half-applied leaves exactly this trace.
|
|
const named = [...text.matchAll(/`([a-z]+-[a-z-]+)`/g)].map((m) => m[1]!)
|
|
const ghosts = [...new Set(named)].filter(
|
|
(name) => /^(wooden|iron|oak|straw|hay|linen|log|pitch|leather|glass|coin|cart|bronze|tavern|trestle|wicker|round|forge|stone|post|hand)-/.test(name)
|
|
&& !ids.includes(name),
|
|
)
|
|
expect(`${file}: no models that do not exist`, ghosts.length === 0, ghosts.join(', '))
|
|
console.log('')
|
|
}
|
|
|
|
if (failures.length > 0) {
|
|
console.log(`${failures.length} documentation check(s) FAILED.`)
|
|
process.exit(1)
|
|
}
|
|
console.log('Documentation matches the kit.')
|