I would like to have a set of links
<li>
<h2>Random Articles</h2>
<ul>
<li><a href="#">Old article 1</a></li>
<li><a href="#">Old article 1</a></li>
<li><a href="#">Old article 1</a></li>
</ul>
</li>
But I want to generate the links from a random selection of my posts. I'm using jekyll and liquid to generate the site. I must use built in parts of jekyll as I'm hosting on github. I'm not really sure where to start on this. Google searches on the topic are fruitless.
This is choosing a random quote from a JSON file in _data but the principle should work with your posts as well:
{% assign random = site.time | date: "%s%N" | modulo: site.data.inspirational-quotes.size %}
<blockquote>“{{ site.data.inspirational-quotes[random].quote }}” <cite>{{ site.data.inspirational-quotes[random].person }}</cite></blockquote>
I found this article to be useful to generating numbers using Liquid, it is not straight forward, nonetheless, it is the most elegant way to generate a random number with min/max.
The following example is for a number between 65 & 80.
{% assign min = 65 %}
{% assign max = 80 %}
{% assign diff = max | minus: min %}
{% assign randomNumber = "now" | date: "%N" | modulo: diff | plus: min %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With