forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
README
nav links + script to update the table of contents
1 parent
998c4ca
commit 1776316
Showing
2 changed files
with
114 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Regenerate the Table of Contents in the README by reading through nav.ts | ||
// | ||
// To run this: | ||
// | ||
// bun ./scripts/nav2readme.ts | ||
// | ||
// | ||
import nav from "../docs/nav"; | ||
|
||
function getMarkdown() { | ||
let md = ""; | ||
|
||
for (const item of nav.items) { | ||
if (item.type === "divider") { | ||
md += "\n" + `- ${item.title}` + "\n"; | ||
} else { | ||
md += ` - [${item.title}](https://bun.sh/docs/${item.slug})` + "\n"; | ||
} | ||
} | ||
|
||
return md; | ||
} | ||
|
||
const text = await Bun.file(Bun.fileURLToPath(import.meta.resolve("../README.md"))).text(); | ||
const startI = text.indexOf("## Quick links\n"); | ||
if (startI === -1) { | ||
throw new Error("Could not find ## Quick links in README"); | ||
} | ||
const start = startI + "## Quick links\n".length; | ||
|
||
const contributing = text.indexOf("## Contributing\n", start); | ||
|
||
if (contributing === -1) { | ||
throw new Error("Could not find ## Contributing in README"); | ||
} | ||
|
||
const combined = | ||
[text.slice(0, start), getMarkdown(), text.slice(contributing)].map(text => text.trim()).join("\n\n") + "\n"; | ||
|
||
await Bun.write(Bun.fileURLToPath(import.meta.resolve("../README.md")), combined); |