const path = require('path'), fs = require('fs') var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'))) var highlightedWords = config.highlightedWords 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) 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) } } } 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()