diff --git a/api.js b/api.js index ab08787..8605a92 100644 --- a/api.js +++ b/api.js @@ -14,6 +14,9 @@ module.exports = { "connected": false, "lastLanyardUpdate": Date.now(), + "blogConnected": false, + "blogPosts": undefined, + "events": events, "spins": 0, @@ -69,4 +72,54 @@ function socketeer() { }) } -socketeer() \ No newline at end of file +socketeer() + +function blogSocket() { + var blog = new WebSocket('https://blog.violets-purgatory.dev') + + blog.on("error", (error) => { + console.log(error) + }) + + blog.on("close", () => { + console.log("Connection Closed. Attempting Reconnect in 30 seconds.") + module.exports.blogConnected = false + setTimeout(() => { + blogSocket() + }, 30000); + }) + + function ping(dur) { + blog.send(JSON.stringify({ + type: "ping" + })) + setTimeout(() => { + ping(dur) + if (Date.now() - lastPong > 120000) { + blog.close() + console.log("Max duration since last pong exceeded- Closing socket.") + } + }, dur); + } + + blog.addEventListener("message", async (res) => { + var data = JSON.parse(res.data) + if (data.type == "init") { + console.log("Connected to Blog Websocket!") + module.exports.blogConnected = true + ping(30000) + lastPong = Date.now() + events.emit("blogConnect") + } else if (data.type == "ping") { + lastPong = Date.now() + } else if (data.type == "allPosts") { + console.log("Recieved posts!") + module.exports.blogPosts = data.data + events.emit("blogUpdate") + } else { + console.log(data) + } + }) +} + +blogSocket() \ No newline at end of file diff --git a/assets/fonts/encode-sans-expanded-v11-latin-regular.woff2 b/assets/fonts/encode-sans-expanded-v11-latin-regular.woff2 new file mode 100644 index 0000000..dbdfceb Binary files /dev/null and b/assets/fonts/encode-sans-expanded-v11-latin-regular.woff2 differ diff --git a/assets/fonts/source-code-pro-v23-latin-regular.woff2 b/assets/fonts/source-code-pro-v23-latin-regular.woff2 new file mode 100644 index 0000000..b62bc79 Binary files /dev/null and b/assets/fonts/source-code-pro-v23-latin-regular.woff2 differ diff --git a/assets/html/blog.html b/assets/html/blog.html new file mode 100644 index 0000000..cf0f2e6 --- /dev/null +++ b/assets/html/blog.html @@ -0,0 +1,31 @@ + + + + + + + + + + + + + {BLOG_TITLE} - Violet's Purgatory + + + + + + + + + + + {TOPBAR} +

{BLOG_TITLE}

+
+ {BLOG_POST} +
+ + + \ No newline at end of file diff --git a/blog.js b/blog.js new file mode 100644 index 0000000..1170630 --- /dev/null +++ b/blog.js @@ -0,0 +1,36 @@ +const api = require("./api.js"), +app = require("./expressHandler.js").app, +showdown = require("showdown"), +pageUpdater = require("./pageUpdater.js"), +fs = require("fs"), +path = require("path") +mkhtml = new showdown.Converter() + +mkhtml.setFlavor("github") + +app.use((req, res, next) => { + if (req.path.includes("blog") && api.blogPosts) { + var postName = decodeURIComponent(req.path.substring(6, req.path.length - 1)) + for (var i = 0; i < api.blogPosts.length; i++) { + var post = api.blogPosts[i] + + if (post.folder == postName || post.folder == decodeURIComponent(post.title)) { + var mkdwn = post.data + var html = mkhtml.makeHtml(mkdwn) + + html = fs.readFileSync(path.join(__dirname, "assets/html/blog.html")).toString().replace("{BLOG_POST}", html) + + html = pageUpdater.converter(html, false) + + html = html.replaceAll("{BLOG_TITLE}", post.title) + html = html.replaceAll("{BLOG_DESC}", post.desc) + + res.send(html) + return + } + } + next() + } else { + next() + } +}) \ No newline at end of file diff --git a/constants.json b/constants.json index 1e25c94..02da0b6 100644 --- a/constants.json +++ b/constants.json @@ -142,10 +142,29 @@ "enby", - "Slay the Spire" + "Slay the Spire", + + "Liberapay", + + "Golden Wind" ], "color": "yellow" }, + { + "words": [ + "brain" + ], + "color": "pink", + "caseInsensitive": true + }, + { + "words": [ + "Jojo's Bizarre Adventure", + "Jojo" + ], + "caseInsensitive": true, + "color": "rgb(170, 80, 225)" + }, { "words": [ "Teto Tuesday", @@ -183,6 +202,7 @@ "words": [ "Forgejo", "HTML", + ".html", "Shortcat", "Valve", "Spooky", @@ -235,21 +255,26 @@ }, { "words": [ - "Codeberg" + "Codeberg", + + "TrueNAS" ], "color": "rgb(0, 255, 255)" }, { "words": [ - "Code" + "Code", + "Codium" ], "color": "rgb(150, 175, 255)" }, { "words": [ - "Codium" + ".md", + "Markdown", + "markdown" ], - "color": "rgb(150, 175, 255)" + "color": "rgb(150, 200, 255)" }, { "words": [ @@ -321,12 +346,6 @@ "color": "rgb(150, 220, 255)", "caseInsensitive": true }, - { - "words": [ - "Liberapay" - ], - "color": "yellow" - }, { "words": [ "Roblox" diff --git a/index.js b/index.js index f18948c..a68365e 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,8 @@ const fs = require("fs") require("./fileHandler.js") require('./expressHandler.js') +require("./pageUpdater.js") +require("./blog.js") // require("./imageEmbedder.js") process.on('uncaughtException', (err, origin) => { diff --git a/overcomplicatedStatuses.js b/overcomplicatedStatuses.js index 0c9786d..a7a4705 100644 --- a/overcomplicatedStatuses.js +++ b/overcomplicatedStatuses.js @@ -95,7 +95,7 @@ module.exports = { var currentPercent = (Date.now() - activity.timestamps.start) / (activity.timestamps.end - activity.timestamps.start) * 100 return `
- ${timeFormatter((Date.now() - activity.timestamps.start))}/${timeFormatter((activity.timestamps.end - activity.timestamps.start))} + ${timeFormatter((Date.now() - activity.timestamps.start))}/${timeFormatter((activity.timestamps.end - activity.timestamps.start))}