2024-02-08 12:30:38 -06:00
|
|
|
const path = require('path'),
|
2024-02-08 17:30:52 -06:00
|
|
|
fs = require('fs')
|
2024-02-08 12:30:38 -06:00
|
|
|
|
|
|
|
var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')))
|
|
|
|
var highlightedWords = config.highlightedWords
|
|
|
|
|
2024-02-08 17:28:17 -06:00
|
|
|
var commitCount = "300+"
|
|
|
|
|
2024-02-08 16:03:40 -06:00
|
|
|
function makeStars() {
|
|
|
|
var html = ""
|
|
|
|
|
2024-02-08 17:25:10 -06:00
|
|
|
for (let index = 0; index < 35; index++) {
|
|
|
|
html += `<div class="rainDrop"></div>`
|
2024-02-08 16:03:40 -06:00
|
|
|
}
|
|
|
|
html += "<style>"
|
2024-02-08 17:25:10 -06:00
|
|
|
for (let index = 0; index < 35; index++) {
|
2024-02-08 16:03:40 -06:00
|
|
|
html += `
|
2024-02-08 17:25:10 -06:00
|
|
|
.rainDrop:nth-of-type(${index + 1}) {
|
|
|
|
animation: rainAnim${index} 1s linear;
|
2024-02-08 16:03:40 -06:00
|
|
|
animation-iteration-count: infinite;
|
2024-02-08 17:25:10 -06:00
|
|
|
animation-delay: ${Math.random() * 15}s;
|
2024-02-08 16:03:40 -06:00
|
|
|
}
|
|
|
|
`
|
|
|
|
var rando = Math.random() * 100
|
2024-02-08 17:25:10 -06:00
|
|
|
html += `@keyframes rainAnim${index} {
|
2024-02-08 16:03:40 -06:00
|
|
|
0% {
|
|
|
|
top: -10vh;
|
|
|
|
right: ${rando}vw;
|
|
|
|
visibility: visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
100% {
|
|
|
|
top: 110vh;
|
2024-02-08 17:25:10 -06:00
|
|
|
right: calc(${rando}vw);
|
2024-02-08 16:03:40 -06:00
|
|
|
}
|
|
|
|
}`
|
2024-02-08 17:30:52 -06:00
|
|
|
|
2024-02-08 16:03:40 -06:00
|
|
|
}
|
|
|
|
html += "</style>"
|
|
|
|
|
|
|
|
return html
|
|
|
|
}
|
|
|
|
|
2024-02-08 12:30:38 -06:00
|
|
|
function converter(html) {
|
|
|
|
var highTable = Object.keys(highlightedWords)
|
|
|
|
for (let index = 0; index < highTable.length; index++) {
|
|
|
|
var term = highTable[index];
|
|
|
|
var replacement = `<span style="color: ${highlightedWords[term]}">${term}</span>`
|
|
|
|
html = html.replaceAll(term, replacement)
|
|
|
|
}
|
|
|
|
|
2024-02-08 16:03:40 -06:00
|
|
|
html = html.replaceAll("{BG_EFFECT}", makeStars())
|
|
|
|
|
2024-02-08 17:28:17 -06:00
|
|
|
html = html.replaceAll("{COMMIT_COUNT}", commitCount)
|
|
|
|
|
2024-02-08 12:30:38 -06:00
|
|
|
return html
|
|
|
|
}
|
|
|
|
|
2024-02-08 17:30:52 -06:00
|
|
|
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(`
|
|
|
|
<link rel="stylesheet" href="/style.css">
|
|
|
|
<h1>404</h1>
|
|
|
|
<p>Uh oh... I think your lost? There's nothing here :P</p>
|
|
|
|
`)
|
|
|
|
}
|
2024-02-08 12:30:38 -06:00
|
|
|
}
|
|
|
|
}
|
2024-02-08 17:28:17 -06:00
|
|
|
|
|
|
|
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("<b>") + 3, commits.lastIndexOf("</b>"))
|
|
|
|
commitCount = commits
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCommits()
|