From 3c6270f83de7b2660c4dcb4fa8f909611decaec4 Mon Sep 17 00:00:00 2001 From: Bingus_Violet Date: Tue, 30 Jan 2024 19:07:57 -0600 Subject: [PATCH] New System --- index.js | 60 ++++++++++++++++++++--------------------- resources/mainPage.html | 9 +++++-- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index 1c1fbdf..6422cda 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ var dataPath = path.join(__dirname, 'data') var postsPath = path.join(dataPath, 'posts') var staticPath = path.join(__dirname, 'static') -var watcher = chokidar.watch(postsPath) +var watcher = chokidar.watch(dataPath) var app = express() @@ -33,16 +33,23 @@ app.listen(PORT, () => { }) function pageUpdate() { - var postsArray = fs.readdirSync(postsPath).reverse() + var data = JSON.parse(fs.readFileSync(path.join(dataPath, 'data.json'))) + var postsArray = data.posts var html = "" for (var i = 0; i < postsArray.length; i++) { var addedHTML = "" var post = postsArray[i] - post = post.substring(post.indexOf("]") + 2, post.length - 3) + - addedHTML += `

${post}

` + addedHTML += + `
+ +

${post.name}

+

Path: /post/${post.path}

+
+
` html += addedHTML } @@ -53,42 +60,35 @@ function pageUpdate() { } watcher - .on('add', pageUpdate) .on('change', pageUpdate) - .on('unlink', pageUpdate) app.get('/post/:post*', (req, res) => { var postName = req.params.post - var postsArray = fs.readdirSync(postsPath).reverse() - var postsDict = {} + var data = JSON.parse(fs.readFileSync(path.join(dataPath, 'data.json'))) + var postsArray = data.posts for (let index = 0; index < postsArray.length; index++) { const post = postsArray[index]; - postsDict[post.substring(post.indexOf("]") + 2, post.length - 3).split(' ').join('_')] = post + + if (post.path == postName) { + postContent = mkthtml.makeHtml(fs.readFileSync(path.join(postsPath, post.path)).toString()) + + var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString() + + html = html.replace('{POST}', postContent) + html = html.replace('{POST_TITLE}', post.name) + + res.send(html) + return + } } - console.log(postsDict, postName) - - if (!postsDict[postName]) { - var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString() - html = html.replace("{POST_TITLE}", "Not found!") - html = html.replace("{POST}", "

Couldn't find this post... Maybe try clearing your cache? Violet's Limbo is currently going through alot of backend changes, so expect things to break!

") - res.send(html) - - return - } - - postName = postsDict[postName] - - var post = fs.readFileSync(path.join(postsPath, postName)).toString() - - post = mkthtml.makeHtml(post) - var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString() - - html = html.replace('{POST}', post) - html = html.replace('{POST_TITLE}', postName.substring(postName.indexOf("]") + 2, postName.length - 3)) - + html = html.replace("{POST_TITLE}", "Not found!") + html = html.replace("{POST}", "

Couldn't find this post... Maybe try clearing your cache? Violet's Limbo is currently going through alot of backend changes, so expect things to break!

") res.send(html) + + return + }) \ No newline at end of file diff --git a/resources/mainPage.html b/resources/mainPage.html index 42f0e6a..8f5459a 100644 --- a/resources/mainPage.html +++ b/resources/mainPage.html @@ -10,7 +10,12 @@

Home

Violet's Limbo

-

Posts:

- {POSTS} +
+

Violet's Limbo is just a bunch of random blogs I decided to post, because why not :>

+

Currently its very early in development, and is going through a large rewrite :P

+

Enjoy my bad opinions!


+

Posts:

+ {POSTS} +
\ No newline at end of file