summaryrefslogtreecommitdiff
path: root/tools/news.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/news.js')
-rw-r--r--tools/news.js56
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.");
+ });
+
+});