${post.title}
${post.desc}
Path: /${post.folder}/
const path = require('path'),
fs = require('fs'),
minify = require('@node-minify/core'),
uglifyJs = require("@node-minify/uglify-js"),
htmlMinifier = require("minify-html"),
cssMinifier = require("clean-css"),
activityToHTML = require("./overcomplicatedStatuses.js"),
randomThemer = require("./randomThemer.js"),
himalaya = require("himalaya"),
glob = require("glob"),
api = require("./api.js"),
child_process = require("child_process")
var constants = JSON.parse(fs.readFileSync(path.join(__dirname, 'constants.json')))
var highlightedWords = constants.highlightedWords
var quotes = constants.quotes
var titles = constants.titles
var commitCount = "600+"
var uptime = Date.now()
var lastPregen = 0
var pregenFiles = []
var javascriptCache = {}
var testing = process.argv[2] == "test"
var globResult = glob.globSync("**/static/**/*.html", { absolute: true })
for (var i = 0; i < globResult.length; i++) {
var result = globResult[i]
pregenFiles.push({
"absolutePath": result,
"path": result.substring(result.indexOf("static") + 7),
"html": undefined
})
}
(async function () {
globResult = glob.globSync("**/static/**/*.js", { absolute: true })
for (var i = 0; i < globResult.length; i++) {
javascriptCache[globResult[i]] = await minify({
compressor: uglifyJs,
content: fs.readFileSync(globResult[i]).toString()
})
}
})()
function firstToUpper(str) {
return str.charAt(0).toUpperCase() + str.slice(1)
}
function onlyIfExists(string, check) {
if (check) {
return string
} else {
return ""
}
}
function makeHtmlSafe(str="") {
return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
}
function timeFormatter(seconds) {
seconds = Math.ceil(seconds)
var minutes = Math.ceil(seconds / 60)
var hours = Math.floor(minutes / 60)
if (seconds <= 60) {
return 'about ' + seconds + ' seconds'
} else if (minutes < 60) {
return `${minutes} Minutes`
}
return `${hours} hours and ${minutes % 60} minutes`
}
function pathReplacer(html) {
while (html.includes("{PATH_")) {
var pagePath = html.substring(html.indexOf("{PATH_"))
pagePath = pagePath.substring(6, pagePath.indexOf('}'))
var stringIndex = `{PATH_${pagePath}}`
pagePath = pagePath.toLowerCase()
var pageHTML = fs.readFileSync(path.join(__dirname, 'static', pagePath, 'index.html')).toString()
pageHTML = pageHTML.substring(pageHTML.indexOf('
" if (status.emoji) { if (status.emoji.id) { addedHTML += `` } else { addedHTML += status.emoji.name + " " } } addedHTML += makeHtmlSafe(status.text) addedHTML += "
" return addedHTML } return "" }, "SELECTED_VIDEO": () => { if (api.lanyard && api.lanyard.video) { return `I would call it random but I actually select them manually.
Uh oh
" } return html }, "BLOG_POSTS": () => { var addedHTML = "" for (var i in api.blogPosts) { var post = api.blogPosts[i] if (!post.hidden) { addedHTML += `` } } if (!api.blogConnected) { addedHTML += "Not connected to blog server :(
" } else if (addedHTML.length < 10) { addedHTML += "No blog posts found...
wait
huh ???
what???????
how ???????????????
WHY ?!
Violet must've fucked up like. REALLY bad.
We're so cooked
The arguements you inputted are "${arg1}" and "${arg2}". Wow!
` } } var realtimeReplacers = { "API_CONNECTED": api.connected.toString(), "ACTIVITIES": activityToHTML.activitiesToHTML(api.lanyard), "SPINCOUNT": api.spins.toString(), "UPTIME": timeFormatter((Date.now() - uptime) / 1000), "LAST_LANYARD": timeFormatter((Date.now() - api.lastLanyardUpdate) / 1000), "RANDOM_TITLE": titles[Math.floor(Math.random() * titles.length)], "RANDOM_QUOTE": quotes[Math.floor(Math.random() * quotes.length)], "LAST_PREGEN": timeFormatter((Date.now() - lastPregen) / 1000) } if (dynamic) { var replacers = realtimeReplacers } else { var replacers = staticReplacers } html = pathReplacer(html) var rpTable = Object.keys(replacers) for (let index = 0; index < rpTable.length; index++) { const text = rpTable[index]; const braceText = `{${text}}` if (typeof replacers[text] == "function" && replacers[text].length == 0) { replacers[text] = replacers[text]() } while (html.includes(braceText)) { var posOfKeyword = html.indexOf(braceText) var keywordLength = braceText.length var args = undefined if (html.charAt(posOfKeyword + keywordLength) == "(") { args = html.substring(posOfKeyword + keywordLength + 1) keywordLength = args.substring(0, args.indexOf(")")).length + keywordLength + 2 args = args.substring(0, args.indexOf(")")) args = args.split(",").map(item => item.trim()) } var fnString = replacers[text] if (typeof fnString == "function") { fnString = fnString.apply(null, args) } if (dynamic) { fnString = himalaya.stringify(highlighter(himalaya.parse(fnString))) } html = html.substring(0, posOfKeyword) + fnString + html.substring(posOfKeyword + keywordLength) // break } } if (!dynamic) { if (html.includes("")) { var bodyHTML = htmlMinifier.minify(html.substring(html.indexOf("") + 6, html.lastIndexOf(""))) var parsedHTML = himalaya.parse(bodyHTML) } else { var parsedHTML = himalaya.parse(html) } parsedHTML = highlighter(parsedHTML) parsedHTML = himalaya.stringify(parsedHTML) if (html.includes("")) { parsedHTML = "" + parsedHTML + "" html = html.substring(0, html.indexOf("")) + parsedHTML + html.substring(html.indexOf("") + 7) } else { html = parsedHTML } } if (dynamic) { html = html.replaceAll("{LOAD_TIME}", (Date.now() - startTime).toString() + "ms") } return html } module.exports = { getActivities: function () { return htmlMinifier.minify(converter(activityToHTML.activitiesToHTML(api.lanyard))) }, middleWare: async function (req, res, next) { var filePath = (req.baseUrl + req.path).trim() if (!filePath.includes(".")) { if (filePath.charAt(filePath.length - 1) != '/') { res.redirect(filePath + '/') return } filePath = path.join(filePath, '/index.html') } filePath = path.join(__dirname, 'static', filePath || 'index.html') if (fs.existsSync(filePath)) { var data = fs.readFileSync(filePath).toString() res.contentType(path.basename(filePath)) if (filePath.includes(".html")) { for (var i = 0; i < pregenFiles.length; i++) { if (pregenFiles[i].html && pregenFiles[i].absolutePath == filePath) { data = pregenFiles[i].html } } data = converter(data, true) // console.log(data) } if (filePath.includes(".html")) { data = htmlMinifier.minify(data) } else if (filePath.includes(".css")) { data = new cssMinifier().minify(data).styles } else if (filePath.includes(".js")) { data = javascriptCache[filePath] } res.send(data) } else { next() } }, converter: converter } async function updateCommits() { // var commits = gitCommitCount() var commits = child_process.execSync("git rev-list --count HEAD") // var siteResponse = await (await fetch(`https://git.violets-purgatory.dev/bingus_violet/violets-purgatory/src/branch/${process.env.BRANCH || "origin"}`)).text() // var commits = siteResponse.substring(0, siteResponse.indexOf("Commits")) // commits = commits.substring(commits.lastIndexOf("") + 3, commits.lastIndexOf("")) // ^ this works for Forgejo (basically everything i use that isnt Github, E.G. Codeberg) // commits = commits.substring(commits.lastIndexOf(">") + 1) // ^ This works for Github (fuck you Github) commitCount = commits.toString().trim() if (process.env.BRANCH == "dev") { commitCount += " | Beta site" } } updateCommits() // Lanyard Stuffs function pregenerate() { lastPregen = Date.now() for (var i = 0; i < pregenFiles.length; i++) { var startTime = Date.now() pregenFiles[i].html = converter(fs.readFileSync(pregenFiles[i].absolutePath).toString(), false) pregenFiles[i].html = pregenFiles[i].html.replaceAll("{PREGEN_TIME}", Date.now() - startTime) } for (var i = 0; i < pregenFiles.length; i++) { pregenFiles[i].html = pregenFiles[i].html.replaceAll("{PREGEN_TOTAL}", Date.now() - lastPregen) } } pregenerate() api.events.on("lanyardConnect", pregenerate) api.events.on("blogUpdate", pregenerate) api.events.on("lanyardUpdate", async () => { if (!api.lanyard.activityChanged) { pregenerate() } var status = api.lanyard.custom_status if (status.emoji.id) { if (status.emoji.animated) { var emoji = Buffer.from(await (await fetch(`https://cdn.discordapp.com/emojis/${status.emoji.id}.gif?quality=lossless`)).arrayBuffer()) } else { var emoji = Buffer.from(await (await fetch(`https://cdn.discordapp.com/emojis/${status.emoji.id}.png?quality=lossless`)).arrayBuffer()) } fs.writeFileSync(path.join(__dirname, "cached/emojis", status.emoji.id), emoji) } })