|
1 | | -import fs from "fs" |
| 1 | +import fs from "node:fs" |
2 | 2 | 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 | +} |
3 | 14 |
|
4 | 15 | 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 | +} |
6 | 20 |
|
7 | 21 | 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 | + ]) |
11 | 30 | } |
12 | 31 |
|
13 | 32 | fetchPosts() |
0 commit comments