Show random post

How can we show a random post on the website?

Jekyll is all static, so it cannot generate a random anything on its own, other than once when it builds.

You could probably output your posts into a json file, and then read that in with JS and have JS pick one randomly and display it. I’m not very good with JS so maybe there would be an easier way than that.

I found this which may be of use for you… Not needed it myself so not used it but might be just what you are after?

https://thornelabs.net/2014/01/19/display-random-jekyll-posts-during-each-page-load-or-refresh-using-javascript.html

1 Like

If you want a random post as a starting page, I would do this:

  1. Create a javascript array with all posts urls
  2. Have javascript pick a random item
  3. Redirect to that item

If you want to show just an image, title and short description, I would do:

  1. Create a javascript array with all posts (image url, title and description)
  2. Have javascript pick a random item
  3. Show them on the screen

A live example of this method is this website: http://springtijarchitecten.nl/, source: https://github.com/jhvanderschee/springtijarchitecten, and this website: https://www.usecue.com, source: https://github.com/jhvanderschee/usecuewebsite.