|
| 1 | +import { mkdir, writeFile } from 'node:fs/promises'; |
| 2 | +import { resolve, dirname } from 'node:path'; |
| 3 | + |
| 4 | +const SOURCE_URL = |
| 5 | + 'https://raw.githubusercontent.com/ethersphere/awesome-swarm/refs/heads/master/README.md'; |
| 6 | + |
| 7 | +// We will generate the actual page file (single route, no imports) |
| 8 | +const OUT_PATH = resolve(process.cwd(), 'src/pages/awesome-swarm.mdx'); |
| 9 | + |
| 10 | +// Matches the line like: [.. DeepWiki ..](...) - ... |
| 11 | +const deepWikiLine = /^\[[^\]]*DeepWiki[^\]]*\]\([^)]+\)\s*-\s*.*$/im; |
| 12 | + |
| 13 | +async function main() { |
| 14 | + const res = await fetch(SOURCE_URL); |
| 15 | + if (!res.ok) throw new Error(`Fetch failed: ${res.status} ${res.statusText}`); |
| 16 | + |
| 17 | + let md = (await res.text()).replace(/\r\n/g, '\n'); |
| 18 | + |
| 19 | + // Optionally strip upstream H1 to avoid duplicate title |
| 20 | + // md = md.replace(/^# .*\n+/, ''); |
| 21 | + |
| 22 | + // Build the full MDX page. We’ll inject the JSX admonition after the DeepWiki entry if found. |
| 23 | + const header = `--- |
| 24 | +title: Awesome Swarm |
| 25 | +id: awesome-list |
| 26 | +--- |
| 27 | +
|
| 28 | +*Contribute to the Awesome Swarm list on [GitHub](https://github.com/ethersphere/awesome-swarm).* |
| 29 | +
|
| 30 | +import Admonition from '@theme/Admonition'; |
| 31 | +`; |
| 32 | + |
| 33 | + const admonition = ` |
| 34 | +<Admonition type="caution"> |
| 35 | +As with all LLMs, DeepWiki may sometimes be confidently wrong. Make sure to always double check (either by inspecting the code yourself, or confirming with a Bee team core developer) before assuming its answers are correct. |
| 36 | +</Admonition> |
| 37 | +`; |
| 38 | + |
| 39 | + let body; |
| 40 | + if (deepWikiLine.test(md)) { |
| 41 | + body = md.replace(deepWikiLine, (match) => `${match}\n\n${admonition}`); |
| 42 | + } else { |
| 43 | + // Fallback: put admonition near top (after the header) |
| 44 | + body = `${admonition}\n${md}`; |
| 45 | + } |
| 46 | + |
| 47 | + const page = `${header}\n${body}\n`; |
| 48 | + |
| 49 | + await mkdir(dirname(OUT_PATH), { recursive: true }); |
| 50 | + await writeFile(OUT_PATH, page, 'utf8'); |
| 51 | + console.log(`Wrote ${OUT_PATH}`); |
| 52 | +} |
| 53 | + |
| 54 | +main().catch((e) => { |
| 55 | + console.error(e); |
| 56 | + process.exit(1); |
| 57 | +}); |
0 commit comments