I like the random page feature of Wikipedia. It allows me to learn about things I would never have learnt otherwise. The random post feature is similar, allowing you to expose your readers to posts they would not look for themselves, but yet are interesting to them.
Randomness in a static website is a problem. When I moved to Jekyll, and then Pelican, as my blogging platform, I wanted to keep using the random post feature I used to use in WordPress. The best solution I found was enrmarc's, which uses the client's browser ability to produce (pseudo-)randomness using JavaScript.
What I didn't like in enrmarc solution was that a list of all posts was included in each and every one of them. This is n² space- (and therefore time- when transmitting the files) complexity. Boo hoo.
My solution is taking this method and making a single file redirecting to a random post. It has support for Jekyll and Pelican; if you want to add another system, just fork this repository, add whatever you need, and send me a pull request ☺
First of all, you might want to know this ability is also provided through a plugin.
If you want to use the non-plugin approach:
- Place
pelican.html
in thetemplates
subdirectory of your theme. - Rename it to something more proper, say
random.html
. - Tell Pelican to use this file by adding
random
toDIRECT_TEMPLATES
in yourpelicanconf.py
; for example:DIRECT_TEMPLATES = ('index', 'categories', 'authors', 'archives', 'random')
. - Now add a link to
YOURSITE/random.html
wherever you want.
- Create a
random
subdirectory under your Jekyll installation. - Place
jekyll.html
in that subdirectory, renaming itindex.html
. - Now add a link to
YOURSITE/random
wherever you want.