MANUAL SORTING
This commit is contained in:
parent
9f972233d6
commit
d7f6a4206b
1 changed files with 4 additions and 15 deletions
19
index.js
19
index.js
|
@ -34,25 +34,14 @@ app.listen(PORT, () => {
|
|||
|
||||
function pageUpdate() {
|
||||
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 = ""
|
||||
|
||||
postsArray = Object.keys(posts).sort().reverse()
|
||||
|
||||
for (var i = 0; i < postsArray.length; i++) {
|
||||
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
|
||||
}
|
||||
|
@ -68,14 +57,14 @@ watcher
|
|||
.on('unlink', pageUpdate)
|
||||
|
||||
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)
|
||||
|
||||
var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString()
|
||||
|
||||
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)
|
||||
})
|
Loading…
Reference in a new issue