今日はhttp://bitcoin.org/clients.htmlの Jekyll で簡単なことをしようとしました。
ビットコイン ソフトウェアのリストがあり、そのページが頻繁に再生成されます。露出が均等になるように、クライアントの順序がランダム化されるとよいでしょう。
{% random page.clients %}
{% for client in page.clients %}
...
私はそれが簡単だと確信しています:
class Random < Liquid::Tag
def initialize(tag_name, collection_name, tokens)
@collection_name = collection_name.to_s
super
end
def render(context)
collection = context[@collection_name]
collection = collection.sort_by{rand}
context[@collection_name] = collection
super
end
end
Liquid::Template.register_tag('random', Random)
うまくいかないのはなぜですか?まったく変化が見られません。
page.clients に正しく割り当てていないと思います。
context[:foo] = collection
{% random page.clients %}
{% for client in page.clients %}
...
次に、空白のページを取得します。しかし、@collection_name を印刷すると、「page.clients」が表示されます...
何か案は?
ありがとう