const path = require('path'), fs = require('fs') var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'))) var highlightedWords = config.highlightedWords var quotes = config.quotes var titles = config.titles var commitCount = "300+" function makeStars() { var html = "" for (let index = 0; index < 35; index++) { html += `
` } html += "" return html } 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) } html = html.replaceAll("{BG_EFFECT}", makeStars()) html = html.replaceAll("{COMMIT_COUNT}", commitCount) html = html.replaceAll("{RANDOM_QUOTE}", quotes[Math.floor(Math.random() * quotes.length)]) html = html.replaceAll("{QUOTE_COUNT}", quotes.length) html = html.replaceAll("{RANDOM_TITLE}", titles[Math.floor(Math.random() * titles.length)]) 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') if (fs.existsSync(filePath)) { 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) } } else { res.status(404).send(`

404

Uh oh... I think your lost? There's nothing here :P

`) } } } async function updateCommits() { var codebergResponse = await (await fetch(`https://codeberg.org/Bingus_Violet/Violets-Purgatory/src/branch/${process.env.BRANCH || "origin"}`)).text() var commits = codebergResponse.substring(0, codebergResponse.indexOf("Commits")) commits = commits.substring(commits.lastIndexOf("") + 3, commits.lastIndexOf("")) commitCount = commits } updateCommits()