MANUAL SORTING

This commit is contained in:
Bingus_Violet 2024-01-05 16:09:09 -06:00
parent 9f972233d6
commit d7f6a4206b

View file

@ -34,25 +34,14 @@ app.listen(PORT, () => {
function pageUpdate() { function pageUpdate() {
var postsArray = fs.readdirSync(postsPath) var postsArray = fs.readdirSync(postsPath)
var posts = {}
for (let index = 0; index < postsArray.length; index++) {
const item = postsArray[index];
const absPath = path.join(postsPath, item)
const birthtime = fs.statSync(absPath).mtime
posts[birthtime] = {"post": item.substring(0, item.length - 3), "date": birthtime}
}
var html = "" var html = ""
postsArray = Object.keys(posts).sort().reverse()
for (var i = 0; i < postsArray.length; i++) { for (var i = 0; i < postsArray.length; i++) {
var addedHTML = "" var addedHTML = ""
var post = posts[postsArray[i]] var post = postsArray[i]
addedHTML += `<h2><a href="./post/${post.post}">${post.post}</h2></a>` addedHTML += `<h2><a href="./post/${post}">${post.substring(4, post.length - 3)}</h2></a>`
html += addedHTML html += addedHTML
} }
@ -68,14 +57,14 @@ watcher
.on('unlink', pageUpdate) .on('unlink', pageUpdate)
app.get('/post/:post*', (req, res) => { app.get('/post/:post*', (req, res) => {
var post = fs.readFileSync(path.join(postsPath, req.params.post + '.md')).toString() var post = fs.readFileSync(path.join(postsPath, req.params.post)).toString()
post = mkthtml.makeHtml(post) post = mkthtml.makeHtml(post)
var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString() var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString()
html = html.replace('{POST}', post) html = html.replace('{POST}', post)
html = html.replace('{POST_TITLE}', req.params.post) html = html.replace('{POST_TITLE}', req.params.post.substring(3, req.params.post.length - 3))
res.send(html) res.send(html)
}) })