mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 10:55:57 +00:00
The bot repo's docs are branded at the source, so the rebrand map only still matched names written on purpose, and rewrote the clawdbot compatibility shim and would rewrite an OpenClaw migration guide's commands and paths into ones that do not exist. It is gone. Source and destination are the argument and this app's content/, not two absolute paths into other checkouts, and a page a fixed nav list leaves out is reported. install/ lists migrate-from-openclaw. Converting today's docs left five pages MDX refuses to parse (an HTML comment, an autolink, a bare `<->`), and a page that does not parse is not rendered. mdxSafe turns each into its MDX form outside code; all 317 pages compile. The converter runs only as a script, so its test can import it. Co-authored-by: Hanzo Dev <[email protected]>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
/**
|
|
* Strip duplicate H1 headings from MDX files.
|
|
* Hanzo Docs renders title from frontmatter, so body H1s are redundant.
|
|
*/
|
|
import { readdir, readFile, writeFile } from 'fs/promises';
|
|
import { join, resolve } from 'path';
|
|
|
|
const DEST = resolve(import.meta.dirname, '../content/docs');
|
|
|
|
async function* walkMdx(dir: string): AsyncGenerator<string> {
|
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
for (const entry of entries) {
|
|
const fullPath = join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
yield* walkMdx(fullPath);
|
|
} else if (entry.name.endsWith('.mdx')) {
|
|
yield fullPath;
|
|
}
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
let fixed = 0;
|
|
for await (const path of walkMdx(DEST)) {
|
|
let content = await readFile(path, 'utf-8');
|
|
|
|
// Match frontmatter
|
|
const fmMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
if (!fmMatch) continue;
|
|
|
|
const fm = fmMatch[1];
|
|
let body = fmMatch[2];
|
|
|
|
// Extract title from frontmatter
|
|
const titleMatch = fm.match(/^title:\s*"(.+)"$/m);
|
|
if (!titleMatch) continue;
|
|
|
|
// Strip first H1 if it matches or exists
|
|
const h1Match = body.match(/^\s*#\s+(.+)\n+/);
|
|
if (h1Match) {
|
|
body = body.replace(/^\s*#\s+.+\n+/, '\n');
|
|
const newContent = `---\n${fm}\n---\n${body}`;
|
|
await writeFile(path, newContent, 'utf-8');
|
|
fixed++;
|
|
}
|
|
}
|
|
console.log(`Stripped H1 from ${fixed} files`);
|
|
}
|
|
|
|
main().catch(console.error);
|