抱歉,因为我是Ruby的新手,但我正在尝试在我的模板中添加一个液体标签,我可以循环显示五个最受欢迎的标签列表.
出于某种原因,这个插件在我使用它时只输出一个标签.
这是我在mu插件中添加的内容:
module Jekyll
class PopularTags < Liquid::Tag
def initialize(tag_name, text, tokens)
super
end
def render(context)
tags = context.registers[:site].tags
return tags.sort_by { |tag, posts| posts.count }
end
end
end
Liquid::Template.register_tag('popular_tags', Jekyll::PopularTags)
Run Code Online (Sandbox Code Playgroud)
这是我在模板中添加的内容:
{% popular_tags %}
Run Code Online (Sandbox Code Playgroud)