diff --git a/.gitignore b/.gitignore
index e01c8f5..5f48730 100644
--- a/.gitignore
+++ b/.gitignore
@@ -131,6 +131,4 @@ dist
.pnp.*
# Violet's Purgatory
-static/index.html
-static/cached
-static/style.css
\ No newline at end of file
+static/cached
\ No newline at end of file
diff --git a/config.json b/config.json
index ce184ad..c8a756e 100644
--- a/config.json
+++ b/config.json
@@ -62,6 +62,7 @@
"highlightedWords": {
"birds": "yellow",
"Pissing": "yellow",
- "Starwalker": "yellow"
+ "Starwalker": "yellow",
+ "word highlighting": "yellow"
}
}
\ No newline at end of file
diff --git a/index.js b/index.js
index bcb0e2a..40e83dc 100644
--- a/index.js
+++ b/index.js
@@ -2,7 +2,8 @@ const express = require('express'),
path = require('path'),
fs = require('fs'),
WebSocket = require('ws'),
- minify = require('minify-html')
+ minify = require('minify-html'),
+ pageUpdater = require('./pageUpdater.js')
var app = express()
@@ -98,287 +99,7 @@ function gameTimeFormatter(seconds) {
}
-async function pageUpdate() {
-
- var genStart = Date.now()
-
- var statuses = {
- "online": {
- "text": "Online",
- "color": "rgb(100, 255, 100)"
- },
- "dnd": {
- "text": "DND",
- "color": "rgb(255, 100, 100)"
- },
- "idle": {
- "text": "Idle",
- "color": "rgb(255, 255, 75)"
- },
- "offline": {
- "text": "",
- "color": "rgb(255, 255, 255)"
- }
- }
-
- var html = fs.readFileSync(mainpage).toString()
-
- var addedHTML = ""
-
- if (lanyardData) {
- var statusData = statuses[lanyardData.discord_status]
-
- addedHTML += `
"
- if (status.emoji) {
- if (status.emoji.id) {
- addedHTML += ` `
- } else {
- addedHTML += status.emoji.name
- }
- }
- if (status.state) {
- addedHTML += `"`
- // addedHTML += (status.state || "")
- var splitStatus = status.state.split(' ')
-
- for (let index = 0; index < splitStatus.length; index++) {
- const text = splitStatus[index];
- if (highlight[text]) {
- addedHTML += `${text} `
- } else {
- addedHTML += text
- }
- addedHTML += ' '
- }
- addedHTML = addedHTML.trim()
- addedHTML += `" `
- }
- addedHTML += ` - ${lanyardData.discord_user.display_name} ${new Date(Date.now()).getFullYear()}
`
- }
- }
-
- html = html.replace("{LANYARD_QUOTE}", addedHTML)
-
- addedHTML = ""
-
- var debounce = false
-
- if (lanyardData && lanyardData.activities.length > 0) {
- for (let index = 0; index < lanyardData.activities.length; index++) {
- const activity = lanyardData.activities[index];
-
- var found = false
- for (let index = 0; index < lanyardData.activities.length; index++) {
- const act = lanyardData.activities[index]
- if (act.name == activity.name) {
- if (Object.keys(act).length > Object.keys(activity).length) {
- found = true
- }
- }
- }
- if (found) {
- continue
- }
-
- if (!debounce && activity.type != 4) {
- addedHTML += ``
- debounce = true
- }
-
-
- function get_img(activity, size = "large_image") {
- if (cachedImages[get_img_url(activity, size)]) {
- var fn = cachedImages[get_img_url(activity, size)]
- var fp = path.join(staticpath, 'cached', fn)
- } else {
- return 'imgs/notFound.png'
- }
-
- return '/cached/' + fn
- }
-
- function songStats() {
- var html = ``
-
- if (activity.assets && activity.assets.large_text != activity.details) {
- html += `
-
Album: ${activity.assets.large_text || " "}
-
Artist: ${activity.state || " "}
- `
- } else {
- html += `
Artist: ${activity.state || " "}`
- }
-
- return html
- }
- if (activity.type == 2) {
- var timeLeft = Math.round((activity.timestamps.end - Date.now()) / 1000)
- var currentPercent = (Date.now() - activity.timestamps.start) / (activity.timestamps.end - activity.timestamps.start) * 100
- addedHTML += `
-
-
-
- Listening to ${activity.name}
- Song: ${activity.details || " "}
- ${songStats()}
-
-
- ${timeFormatter((activity.timestamps.end - activity.timestamps.start) / 1000)}
-
-
-
-
- `
- } else if (activity.type == 0) {
- var time = activity.created_at
- if (activity.timestamps) {
- time = activity.timestamps.start
- }
- if (!activity.assets) {
- activity.assets = { "large_text": " ", "small_text": " " }
- }
-
- function smch() {
- if (get_img_url(activity, "small_image")) {
- return `
`
- }
- return ""
- }
-
-
- addedHTML += `
-
-
- ${smch()}
-
- Playing ${activity.name}
- ${(activity.details || activity.assets.large_text || " ")}
- ${(activity.state || activity.assets.small_text || " ")}
- ${gameTimeFormatter((Date.now() - time) / 1000)}
-
-
-
- `
- } else if (activity.type != 4) {
- var time = activity.created_at
- if (activity.timestamps) {
- time = activity.timestamps.start
- }
- if (!activity.assets) {
- activity.assets = { "large_text": " ", "small_text": " " }
- }
-
- addedHTML += `
-
-
-
- ${activity.name}
- ${(activity.details || activity.assets.large_text || " ")}
- ${(activity.state || activity.assets.small_text || " ")}
- ${gameTimeFormatter((Date.now() - time) / 1000)}
-
-
-
- `
- }
- }
- }
-
- if (addedHTML) {
- addedHTML += "
"
- }
-
- html = html.replace("{LANYARD_FULL}", addedHTML)
-
- addedHTML = ""
-
- var socialsHTML = fs.readFileSync(path.join(__dirname, 'static/socials/index.html')).toString()
- // socialsHTML = socialsHTML.substring(0, socialsHTML.lastIndexOf(""))
- addedHTML += "") + 6)
-
- html = html.replace("{SOCIALS}", addedHTML)
-
- var now = new Date()
-
- currentMonth = now.getMonth() + 1
-
- if ([11, 12].includes(currentMonth)) { // The Below HTML is copy and pasted from that one site :>
- html = html.replace("{SEASONAL_EFFECT}", fs.readFileSync(path.join(__dirname, 'static/snow.html')))
- } else {
- html = html.replace("{SEASONAL_EFFECT}", "")
- }
-
- var quote = randomQuotes[Math.floor(Math.random() * randomQuotes.length)]
-
- var splitQuote = quote.split(' ')
-
- var finalQuote = ''
-
- for (let index = 0; index < splitQuote.length; index++) {
- const text = splitQuote[index];
- if (highlight[text]) {
- finalQuote += `
${text} `
- } else {
- finalQuote += text
- }
- finalQuote += ' '
- }
-
- quote = finalQuote.trim()
-
- quote = quote.replace("{QUOTE_COUNT}", randomQuotes.length)
-
- html = html.replace("{RANDOM_QUOTE}", quote)
-
- if (process.env.BRANCH == "dev") {
- html = html.replace("{OPPOSITE_URL}", "www")
- html = html.replace("{OPPOSITE_BRANCH}", "Main")
- } else {
- html = html.replace("{OPPOSITE_URL}", "beta")
- html = html.replace("{OPPOSITE_BRANCH}", "Beta")
- }
-
- html = html.replace("{COMMIT_COUNT}", commitCount)
-
- html = html.replace("{UPTIME}", gameTimeFormatter((Date.now() - uptime) / 1000))
- html = html.replace("{LAST_LANYARD}", gameTimeFormatter((Date.now() - lastLanyardUpdate) / 1000) + ' ago')
- html = html.replace("{QUOTE_COUNT}", randomQuotes.length)
- html = html.replace("{CACHED_IMAGES}", fs.readdirSync(path.join(staticpath, 'cached')).length)
-
- html = html.replace("{GENERATION_TIME}", Math.ceil(Date.now() - genStart).toString() + 'ms')
-
- //fs.writeFileSync(path.join(__dirname, 'static/index.html'), html)
- return html
-}
-
+app.use(pageUpdater.middleWare)
// Lanyard Stuffs
@@ -447,12 +168,11 @@ function socketeer() {
socketeer()
-app.get('/', async (req, res) => {
- var html = await (pageUpdate())
- res.send(minify.minify(html).toString('utf-8'))
-})
-
-app.use(express.static(staticpath))
+// app.get('/index.html', async (req, res) => {
+// console.log(req.params[0])
+// var html = await (pageUpdate(req.params[0]))
+// res.send(minify.minify(html))
+// })
app.use((req, res, next) => {
res.status(404).send(`
diff --git a/pageUpdater.js b/pageUpdater.js
new file mode 100644
index 0000000..2ab544f
--- /dev/null
+++ b/pageUpdater.js
@@ -0,0 +1,34 @@
+const path = require('path'),
+fs = require('fs')
+
+var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')))
+var highlightedWords = config.highlightedWords
+
+function converter(html) {
+ var highTable = Object.keys(highlightedWords)
+ for (let index = 0; index < highTable.length; index++) {
+ var term = highTable[index];
+ var replacement = `
${term} `
+ html = html.replaceAll(term, replacement)
+ }
+
+ return html
+}
+
+module.exports = { middleWare: function(req, res, next) {
+
+ var filePath = req.baseUrl + req.path
+ if (filePath.trim() == "/") {
+ filePath = "/index.html"
+ }
+ filePath = path.join(__dirname, 'static', filePath || 'index.html')
+ var data = fs.readFileSync(filePath).toString()
+ if (req.path.includes("style.css")) {
+ res.setHeader("Content-Type", "text/css")
+ res.send(data)
+ } else {
+ data = converter(data)
+ res.send(data)
+ }
+}
+}
\ No newline at end of file
diff --git a/resources/mainPage.html b/resources/mainPage.html
deleted file mode 100644
index adfc9e0..0000000
--- a/resources/mainPage.html
+++ /dev/null
@@ -1,100 +0,0 @@
-
-
-
-
-
-
-
-
-
-
Violet's Purgatory
-
-
-
-
-
-
-
-
-
-
-
-
-
Welcome to Violet's Purgatory
-
{RANDOM_QUOTE}
-
{COMMIT_COUNT} Commits
-
-
-
Violet
-
-
-
-
-
-
-
- Fun fact: This website uses no Javascript! Everything dynamic (E.G. The
- discord status) is done
- server-side, so enjoy :D
-
-
Check out the source code on Codeberg
- {LANYARD_FULL}
-
-
Announcement!
-
Soon enough, I will begin work on a complete rewrite for Violet's Purgatory. This rework will be done in hopes of:
-
-
- Spicing up the website's visuals
- Optimizing the site
- Making the codebase more readable
- Reducing the amount of code
- Making the site more easily scalable
-
-
- The codeberg repository for this site was made 6 months ago, not counting all the contributions I had done before then. Thats alot of time, and i've learnt so much since then! This was even my first project to do Dynamic HTML!
- It has been an absolutely wonderful journey, but as per usual, its about time we do some reworking!
- I may still keep this version of the website up for archival sake (And, worst comes to worst, I'll still have it on archive.org)
- This rewrite will take time, so from now on, updates to Violet's Purgatory will be slow or nonexistant.
- And if you're curious, you can always check the beta branch to see how progress is going!
- Thank you for your time and encouragement, It's been a fun year on violets-purgatory.dev :)
-
-
P.S.: As my final gift, CSS is now minified!!! woohoo!!!
-
- {SOCIALS}
-
-
Silly Stats:
-
Just some funny stats for the site :3
-
- Uptime: {UPTIME}
- Last Lanyard Update: {LAST_LANYARD}
- Quotes: {QUOTE_COUNT}
- Images Cached: {CACHED_IMAGES}
- Page Generation Time: {GENERATION_TIME}
-
-
- {SEASONAL_EFFECT}
-
-
-
-
\ No newline at end of file
diff --git a/static/extras/discord/index.html b/static/extras/discord/index.html
deleted file mode 100644
index f161b29..0000000
--- a/static/extras/discord/index.html
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Discord Status - Violet's Purgatory
-
-
-
-
Home
-
-
Sorry! This page requires javascript... The rest of this site doesn't, though!
-
Discord Status (W.I.P)
-
This is a more fleshed out version of the main discord status on my site, issue being, it requires Javascript. So, I choose not to use it, though it coulda been cool...
-
I still am tempted to add something like it to the main page, and just make it compatible without javascript, but I worry that'd upset people.
-
-
-
Violet
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/static/extras/discord/index.js b/static/extras/discord/index.js
deleted file mode 100644
index 7053ede..0000000
--- a/static/extras/discord/index.js
+++ /dev/null
@@ -1,74 +0,0 @@
-var lanyard = new WebSocket('wss://api.lanyard.rest/socket')
-
-var statuses = {
- "online": {
- "text": "Online",
- "color": "rgb(100, 255, 100)"
- },
- "dnd": {
- "text": "DND",
- "color": "rgb(255, 100, 100)"
- },
- "idle": {
- "text": "Idle",
- "color": "rgb(255, 255, 75)"
- },
- "offline": {
- "text": "Offline",
- "color": "rgb(125, 125, 125)"
- }
-}
-
-function beat(dur) {
- lanyard.send(JSON.stringify({
- op: 3
- }))
- setTimeout(() => {
- beat(dur)
- }, dur);
-}
-
-lanyard.addEventListener("message", (res) => {
- var data = JSON.parse(res.data)
- if (data.op == 1) {
- beat(data.d.heartbeat_interval)
- lanyard.send(JSON.stringify({
- op: 2,
- d: {
- subscribe_to_id: "534132311781015564"
- }
- }))
- } else if (data.op == 0) {
- var lanyardData = data.d
- // $("*").text(JSON.stringify(lanyardData))
-
-
- var statusData = statuses[lanyardData.discord_status]
-
- $("#discStatus").text(statusData.text)
- $("#discStatus").css("color", statusData.color)
- $(".pfp").css("border-color", statusData.color)
-
- if (lanyardData) {
- $("#discQuote").html("")
- for (let index = 0; index < lanyardData.activities.length; index++) {
- const activity = lanyardData.activities[index];
- var status = lanyardData.activities[0]
- var addedHTML = ""
- addedHTML += "
"
-
- if (activity.type == 4) {
- if (status.emoji) {
- if (status.emoji.id) {
- addedHTML += `
`
- } else {
- addedHTML += status.emoji.name
- }
- }
- addedHTML += `
"${lanyardData.activities[0].state}" - ${lanyardData.discord_user.display_name} ${new Date(Date.now()).getFullYear()}`
- $("#discQuote").html(addedHTML)
- }
- }
- }
- }
-})
\ No newline at end of file
diff --git a/static/extras/index.html b/static/extras/index.html
deleted file mode 100644
index 5c01a60..0000000
--- a/static/extras/index.html
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Extras - Violet's Purgatory
-
-
Extras
-
Just some fun things that really don't have use on the main page but exist anyway!
-
-
-
Home
-
-