Skip to content

Commit 9dbd833

Browse files
authored
Merge pull request #1378 from scroll-tech/research-blog
feat(blog): add research-blog.data.json
2 parents 91496a0 + b1c930a commit 9dbd833

28 files changed

+31
-7027
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ next-env.d.ts
4242

4343
.turbo
4444

45-
/src/app/blog/data.json
45+
/src/app/blog/[blogId]/data.json
46+
/src/assets/blog/main.data.json
47+
/src/assets/blog/research.data.json
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1-
import fs from "fs"
1+
import fs from "node:fs"
22
import fetch from "node-fetch"
3+
import path from "node:path"
4+
5+
import { fileURLToPath } from "url"
6+
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
8+
9+
const blogAssetsDir = path.join(__dirname, "..", "src", "assets", "blog")
10+
11+
if (!fs.existsSync(blogAssetsDir)) {
12+
fs.mkdirSync(blogAssetsDir, { recursive: true })
13+
}
314

415
const isMainnet = process.env.NEXT_PUBLIC_SCROLL_ENVIRONMENT === "Mainnet"
5-
const POSTS_URL = `https://blog.scroll.cat/api/posts/${isMainnet ? "published" : "preview"}/data.json`
16+
17+
function buildPostURL(hostType) {
18+
return `https://blog.scroll.cat/api/posts/${isMainnet ? "published" : "preview"}/${hostType}/data.json`
19+
}
620

721
async function fetchPosts() {
8-
await fetch(POSTS_URL, { headers: { Origin: "https://scroll.io" } })
9-
.then(res => res.json())
10-
.then(json => fs.writeFileSync("./src/app/blog/[blogId]/data.json", JSON.stringify(json, null, 2)))
22+
await Promise.all([
23+
fetch(buildPostURL("scroll.io"))
24+
.then(res => res.json())
25+
.then(json => fs.writeFileSync("./src/assets/blog/main.data.json", JSON.stringify(json, null, 2))),
26+
fetch(buildPostURL("research.scroll.io"))
27+
.then(res => res.json())
28+
.then(json => fs.writeFileSync("./src/assets/blog/research.data.json", JSON.stringify(json, null, 2))),
29+
])
1130
}
1231

1332
fetchPosts()

0 commit comments

Comments
 (0)