diff --git a/liberals/directoryparsing.js b/liberals/directoryparsing.js new file mode 100644 index 0000000..b325a40 --- /dev/null +++ b/liberals/directoryparsing.js @@ -0,0 +1,49 @@ +import { fs } from "../index.js" + +function parsePosts() { + let files = fs.readdirSync(process.cwd()+"/website/posts") + let result = "" + + for (let x in files) { + if (files[x].endsWith(".html") === false && files[x].endsWith(".md") === false ) { break } // If file/dir is not .html or .md then ignore + + let date = files[x].split("-")[0] + if (date < 10000000 || date > 99999999) { break } // If date does not fit ISO8601 format then ignore + + date = date.replace(/.{2}/g,"$&-").replace("-","").slice(0,-1) // Insert a dash every 2 characters, remove the first dash, remove the last character + + let name = files[x].slice(9).replace(/-/g," ").replace(".html","").replace(".md","") // Strip Date, replace seperator with space & remove file extension + + result = `
  • ${date} ${name}
  • `+result + } + + return result +} + +function parseKbas() { + let files = fs.readdirSync(process.cwd()+"/website/helpdesk/kbas") + let pages = {} + let result = "" + + for (let x in files) { + if (files[x].endsWith(".html") === false && files[x].endsWith(".md") === false ) { break } // If file/dir is not .html or .md then ignore + + if (!Array.isArray(pages[files[x].split("-")[0]])) { // check if category array does not exist + pages[files[x].split("-")[0]] = [] // create it + } + + pages[files[x].split("-")[0]].push(files[x]) + } + + for (let y in pages) { + result += `

    ${y}

    ` + for (let z in pages[y]) { + result += `${pages[y][z].split("-")[1].split(".")[0].replace(/_/g," ")}` + } + result += `
    ` + } + + return result +} + +export { parseKbas, parsePosts} \ No newline at end of file diff --git a/routes/frontpage.js b/routes/frontpage.js index 8606908..221b937 100644 --- a/routes/frontpage.js +++ b/routes/frontpage.js @@ -1,7 +1,5 @@ import { app, globalConfig, fs, globalVersion } from "../index.js" // Get globals from index -import { execSync } from 'child_process' -import { checkToken } from "../liberals/auth.js" -import { logRequest } from "../liberals/logging.js" +import { parsePosts } from "../liberals/directoryparsing.js" import { marked } from "marked" var timeSinceLastQuery = Date.now()-10000 @@ -12,7 +10,7 @@ app.get("/", (rreq, rres) => { rres.send(cachedResult) } else { let indexFile = fs.readFileSync(process.cwd()+"/website/templates/newindextemplate.html","utf-8") - cachedResult = indexFile.replace("",parseFiles()).replace("",`API Version ${globalVersion}`) + cachedResult = indexFile.replace("",parsePosts()).replace("",`API Version ${globalVersion}`) rres.send(cachedResult) } }) @@ -43,24 +41,4 @@ app.get("/posts/*", (rreq,rres) => { }) -function parseFiles() { - let files = fs.readdirSync(process.cwd()+"/website/posts") - let result = "" - - for (let x in files) { - if (files[x].endsWith(".html") === false && files[x].endsWith(".md") === false ) { break } // If file/dir is not .html or .md then ignore - - let date = files[x].split("-")[0] - if (date < 10000000 || date > 99999999) { break } // If date does not fit ISO8601 format then ignore - - date = date.replace(/.{2}/g,"$&-").replace("-","").slice(0,-1) // Insert a dash every 2 characters, remove the first dash, remove the last character - - let name = files[x].slice(9).replace(/-/g," ").replace(".html","").replace(".md","") // Strip Date, replace seperator with space & remove file extension - - result = `
  • ${date} ${name}
  • `+result - } - - return result -} - export {app} \ No newline at end of file diff --git a/routes/helpdesk.js b/routes/helpdesk.js index 2d893de..04c5d76 100644 --- a/routes/helpdesk.js +++ b/routes/helpdesk.js @@ -1,4 +1,5 @@ import { app, fs } from "../index.js" +import { parseKbas } from "../liberals/directoryparsing.js" import { marked } from "marked" app.get("/helpdesk", (rreq, rres) => { @@ -6,7 +7,11 @@ app.get("/helpdesk", (rreq, rres) => { }) app.get("/helpdesk/articles", (rreq, rres) => { - rres.send("miau") + let file = fs.readFileSync(process.cwd() + "/website/helpdesk/templates/article.html", "utf-8") + file = file.replace("", `https://enstrayed.com${rreq.url}`) + file = file.replaceAll("", "Knowledgebase") + file = file.replace("", parseKbas()) + rres.send(file) }) app.get("/helpdesk/articles/*", (rreq, rres) => { diff --git a/website/helpdesk/templates/article.html b/website/helpdesk/templates/article.html index 4f7cdac..92e0006 100644 --- a/website/helpdesk/templates/article.html +++ b/website/helpdesk/templates/article.html @@ -20,6 +20,7 @@
    + Return to Knowledgebase