GLM 5.2 Benchmark: Tidy & Bugfix #35

Open
pfych wants to merge 6 commits from cleanup/site-build-audit into master
Owner

Testing GLM 5.2 by having it attempt to tidy and clean the custom SSG.

Testing GLM 5.2 by having it attempt to tidy and clean the custom SSG.
pfych self-assigned this 2026-06-26 04:58:11 +00:00
thisCyclesHash (8-char SHA of Date.now()) was computed in config.ts
and imported by create-script-path.ts and styles.ts but never read
by either. The cache-busting intent it implied was never wired up —
scripts and styles are still emitted as bare paths.

Delete the computation and both dead imports.
The site had two independent frontmatter parsers that disagreed:

- create-post-object.ts split on '---' and required >=3 parts (threw
  'Missing metadata' otherwise), then parsed each line by splitting on
  the first ':' via regex — which silently truncated any value
  containing a colon.
- marked.ts had a preprocess hook that split on '---' again, swallowed
  the frontmatter, and rejoined the rest. This corrupted posts that
  contained '---' inside fenced code blocks (e.g. jsx-clientside.md,
  which documents a markdown example), and logged a spurious
  'Unexpected split length' warning whenever mdToHtml was called on
  synthesized content with no frontmatter (buildAll's index page).

Replace both with a single parseFrontmatter() in utils/frontmatter.ts
that:
  - respects fenced code blocks when locating delimiters
  - accepts '--- ' (trailing whitespace) delimiters
  - splits each entry on the first colon only, preserving colons in
    values
  - returns null with no closing delimiter, so callers decide

create-post-object now passes the parsed body (not the raw file
content) to renderTemplate, and marked.ts's preprocess hook is gone.

Also drop two pre-existing unused-parameter warnings ('info' in the
highlight callback, 'title' in the link renderer) surfaced in the
file this commit touches.
index.ts ran 'await build()' at module top level. watch.ts imports
{ build } from './index' and then calls 'await build()' itself, so
every 'pnpm dev' start built the whole site twice — once as an import
side effect, once explicitly.

Gate the auto-build behind a main-module check (realpathSync of
argv[1] vs import.meta.url, tolerating a missing argv[1] so 'node -e'
imports don't crash). The guard fires only when index.ts is the entry
point; watch.ts's own build() call is now the single build on dev.
Three issues in rss.xml generation:

- <link></link> was invalid Atom. Atom's <link> is an empty
  element with an href attribute (<link href="..."/>), not text
  content — the feed-level link already used the correct form, so the
  per-entry link was an inconsistency. Readers that ignored the entry
  link now get a usable href.

- latestPostUpdated[0] threw synchronously when posts was empty or all
  hidden, taking down the whole buildPosts Promise.all. Guard with a
  fallback to Date.now() so an empty feed still emits valid XML.

- Title escaping only handled & and left <, >, ", ' raw, producing
  invalid XML for any title containing those characters. Add a small
  escapeXml helper and apply it to titles, URLs (in <id>, <link> href,
  xml:base), and emoji. Body content stays in CDATA as before.

Also switch the per-entry .md→.html replacement to a anchored regex
(/\.md$/) so filenames containing 'md' elsewhere aren't mangled.
Replace ad-hoc string manipulation with node:path primitives:

- create-post-object.ts: basename() instead of path.split(separators).pop(),
  and relative(cwd, dirname(path)) instead of
  path.replace(cwd+'/','').replace(fileName,''). The old replace chain
  mangled relativeFolder when the filename appeared earlier in the path
  (e.g. posts/posts/foo.md). Folder is '' for root-level posts and
  'sub/dir/' otherwise, matching the previous trailing-slash contract
  that all.ts/rss.ts rely on.

- all.ts, posts.ts: switch .replace('md','html') and .replace('.md','')
  to a single anchored /\.md$/ -> '.html' regex. The un-anchored string
  replace corrupted filenames containing 'md' before the extension
  (e.g. cmd.md -> chtml.md). rss.ts already used the anchored form.

Output is byte-identical to the previous commit apart from the build
timestamp.
@ -17,1 +19,3 @@
await build();
// Only run when invoked directly (e.g. `node build/index.ts`), not when
// imported by watch.ts — otherwise every `dev` start builds twice.
const entryPath = process.argv[1];
Author
Owner

This feels really gross - is it overkill?

This feels really gross - is it overkill?
@ -0,0 +4,4 @@
}
/**
* Parse YAML-ish frontmatter delimited by `---` lines.
Author
Owner

Remove all these gross LLM-esque comments 🤮

Remove all these gross LLM-esque comments 🤮
@ -33,4 +32,2 @@
marked.use({
hooks: {
preprocess(content: string): string {
Author
Owner

It seems dangerous to completely remove this? Why was it originally here?

It seems dangerous to completely remove this? Why was it originally here?
Author
Owner

It was lmao. Commit e678a36188 reverts this

It was lmao. Commit e678a36188 reverts this
pfych marked this conversation as resolved
Author
Owner

Overall needs a formatting pass - code is quite cramped

Overall needs a formatting pass - code is quite cramped
In the previous commit I removed marked.ts's preprocess hook and relied
on create-post-object.ts to strip frontmatter before calling mdToHtml.
That works for current callers, but it leaves mdToHtml brittle: if any
future caller passes a raw post file, the frontmatter is rendered as a
visible horizontal rule + heading.

Put the safety net back, but implement it with the shared
parseFrontmatter() utility instead of the old split('---') hack. This
means:

- raw post content still has frontmatter stripped before markdown parsing
- content with no frontmatter passes through unchanged (no spurious
  'Unexpected split length' warning)
- '---' inside fenced code blocks is no longer mistaken for a delimiter

Output remains byte-identical to the previous commit apart from the
build timestamp.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin cleanup/site-build-audit:cleanup/site-build-audit
git switch cleanup/site-build-audit

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff cleanup/site-build-audit
git switch cleanup/site-build-audit
git rebase master
git switch master
git merge --ff-only cleanup/site-build-audit
git switch cleanup/site-build-audit
git rebase master
git switch master
git merge --no-ff cleanup/site-build-audit
git switch master
git merge --squash cleanup/site-build-audit
git switch master
git merge --ff-only cleanup/site-build-audit
git switch master
git merge cleanup/site-build-audit
git push origin master
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pfych/static!35
No description provided.