Jekyll,液体,随机数 [英] Jekyll, Liquid, Random numbers

查看:88
本文介绍了Jekyll,液体,随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一组链接

<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>

但是我想从随机选择的帖子中生成链接.我正在使用jekyll和液体来生成该网站.我在github上托管时,必须使用jekyll的内置部分.我不太确定从哪里开始. Google在该主题上的搜索是徒劳的.

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.

推荐答案

我也有类似的愿望,并开始定义自定义Liquid标签(请参见

I had a similar desire and got down to defining a custom Liquid tag (see http://github.com/mojombo/jekyll/wiki/Plugins) which accessed posts through context.registers and selected ones at random, but note that once Jekyll generates your site, that random selection remains static until the site is regenerated. I would suggest a different option: have Jekyll write those all those post links into an array in JavaScript (included inline in the layout), which is shuffled and the top three links are then displayed on the page. You could even enhance this so that those three links rotate with other ones in the array with a setInterval() call. It's not the most elegant solution, but dynamically generating random content doesn't seem quite inline with the design philosophy of Jekyll anyhow.

这篇关于Jekyll,液体,随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆