diff options
author | Helianthella <git@gumi.ca> | 2020-12-22 00:06:42 -0500 |
---|---|---|
committer | Helianthella <git@gumi.ca> | 2020-12-22 00:06:47 -0500 |
commit | b90bbeab7c1435518224496821ff3449476c458d (patch) | |
tree | e543aefb386a69bbe4b5d9fc73ebfb4c73c9361f /tools | |
parent | f9c051e61da67b93ed3c9aba3d77bced80e1503e (diff) | |
download | website-b90bbeab7c1435518224496821ff3449476c458d.tar.gz website-b90bbeab7c1435518224496821ff3449476c458d.tar.bz2 website-b90bbeab7c1435518224496821ff3449476c458d.tar.xz website-b90bbeab7c1435518224496821ff3449476c458d.zip |
upgrade to Vue 3, switch to yarn
implies a slight refactor
Diffstat (limited to 'tools')
-rw-r--r-- | tools/news.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/news.js b/tools/news.js new file mode 100644 index 0000000..9e89a50 --- /dev/null +++ b/tools/news.js @@ -0,0 +1,56 @@ +/** + * fetches the full news file and generates a json file with the first entry + * and another with the full archive + */ + +const https = require("https"); +const fs = require("fs"); + +const source = "https://themanaworld.github.io/tmwa-server-data/news.json"; + +console.info("Acquiring news from static site..."); + +https.get(source, res => { + let file = ""; + + res.on("data", chunk => file += chunk); + + res.on("end", () => { + const news = JSON.parse(file); + const first = []; + + console.info(`Received ${news.length} news entries; splitting...`); + + if (news.length > 0) { + first.push(news[0]); + + let data = new Uint8Array(Buffer.from(JSON.stringify(first))); + fs.writeFileSync("src/assets/news.json", data, { + encoding: "utf-8", + flag: "w+", + }); + + data = new Uint8Array(Buffer.from(file)); + fs.writeFileSync("src/assets/news-full.json", data, { + encoding: "utf-8", + flag: "w+", + }); + } else { + console.info("Creating dummy news files..."); + + let data = new Uint8Array(Buffer.from("[]")); + fs.writeFileSync("src/assets/news.json", data, { + encoding: "utf-8", + flag: "w+", + }); + + fs.writeFileSync("src/assets/news-full.json", data, { + encoding: "utf-8", + flag: "w+", + }); + } + + console.info("Success."); + }); + +}); |