Skip to content
Discussion options

You must be logged in to vote

You could do this in getStaticProps for your pages/index.js file.

In the example, the posts are sorted by date:

  return allPostsData.sort((a, b) => {
    if (a.date < b.date) {
      return 1
    } else {
      return -1
    }
  })

and instead of returning all of them, just return the most recent 2 using .slice(0,2):

  return allPostsData.sort((a, b) => {
    if (a.date < b.date) {
      return 1
    } else {
      return -1
    }
  }).slice(0,2)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by timmohlin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants