""refactor"" basically everything

This commit is contained in:
Enstrayed
2024-09-22 14:04:15 -07:00
parent 2e527a8539
commit 5f1181476d
14 changed files with 78 additions and 90 deletions

View File

@@ -1,31 +1,31 @@
const { app, globalConfig, fs, globalVersion } = require("../index.js") // Get globals from index
import { app, globalConfig, fs, globalVersion } from "../index.js" // Get globals from index
var timeSinceLastQuery = Date.now()-10000
var cachedResult = ""
app.get("/static/*", (rreq,rres) => {
rres.sendFile(globalConfig.frontpage.frontpageDir+"/static/"+rreq.url.replace("/static/",""))
rres.sendFile(globalConfig.frontpage.directory+"static/"+rreq.url.replace("/static/",""))
})
app.get("/posts/*", (rreq,rres) => {
rres.sendFile(globalConfig.frontpage.frontpageDir+"/posts/"+rreq.url.replace("/posts/",""))
rres.sendFile(globalConfig.frontpage.directory+"posts/"+rreq.url.replace("/posts/",""))
})
app.get("/", (rreq, rres) => {
if (Date.now() < timeSinceLastQuery+10000) {
rres.send(cachedResult)
} else {
let indexFile = fs.readFileSync(globalConfig.frontpage.frontpageDir+"/index.html","utf-8")
let indexFile = fs.readFileSync(globalConfig.frontpage.directory+"index.html","utf-8")
cachedResult = indexFile.replace("<!--SSR_BLOGPOSTS-->",parseFiles()).replace("<!--SSR_APIVERSION-->",`<sup>API Version ${globalVersion}</sup>`)
rres.send(cachedResult)
}
})
function parseFiles() {
let files = fs.readdirSync(globalConfig.frontpage.frontpageDir+"/posts/")
let files = fs.readdirSync(globalConfig.frontpage.directory+"posts/")
let result = ""
for (x in files) {
for (let x in files) {
if (files[x].endsWith(".html") === false) { break } // If file/dir is not .html then ignore
let date = files[x].split("-")[0]
@@ -41,4 +41,4 @@ function parseFiles() {
return result
}
module.exports = {app}
export {app}