Skip to content

Commit 9ccb877

Browse files
committed
prebuild script to eliminate client side fetching
1 parent 4a686a8 commit 9ccb877

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ build
55
public
66
resources
77
# Local Netlify folder
8-
.netlify
8+
.netlify
9+
# Generated content
10+
/src/pages/awesome-swarm.mdx

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"docusaurus": "docusaurus",
77
"start": "docusaurus start",
8+
"prebuild": "node scripts/fetch-awesome-swarm.mjs",
89
"build": "docusaurus build",
910
"swizzle": "docusaurus swizzle",
1011
"deploy": "docusaurus deploy",

scripts/fetch-awesome-swarm.mjs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
});

src/pages/awesome-list.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)