Browse Source

Sort posts by date; adjust date so sort is correct

post_vjs2
Levi Olson 6 years ago
parent
commit
14e394a052
2 changed files with 9 additions and 1 deletions
  1. +8
    -0
      app.js
  2. +1
    -1
      posts/something-decent.json

+ 8
- 0
app.js View File

@ -36,6 +36,14 @@ app.get('/posts', (req, res) => {
}
}
}
data.posts.sort(function (a, b) {
var keyA = new Date(a.created_at),
keyB = new Date(b.created_at)
// Compare the 2 dates
if (keyA < keyB) return 1
if (keyA > keyB) return -1
return 0
})
res.render('pages/posts', data)
})

+ 1
- 1
posts/something-decent.json View File

@ -1,7 +1,7 @@
{
"title": "Something Decent - Levi Olson",
"permalink": "/posts/something-decent",
"created_at": "2018-04-27T17:05:19-06:00",
"created_at": "2018-04-27T05:05:19-06:00",
"created_at_short": "2018-04-27",
"post_title": "the start of something... decent",
"active": "posts",

Loading…
Cancel
Save