Class: Jekyll::Documents::LatestDocumentsTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::Documents::LatestDocumentsTag
- Defined in:
- lib/jekyll/documents/tags/latest_documents.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ LatestDocumentsTag
constructor
A new instance of LatestDocumentsTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ LatestDocumentsTag
Returns a new instance of LatestDocumentsTag.
6 7 8 9 |
# File 'lib/jekyll/documents/tags/latest_documents.rb', line 6 def initialize(tag_name, markup, tokens) super @args = parse_args(markup) end |
Instance Method Details
#render(context) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jekyll/documents/tags/latest_documents.rb', line 13 def render(context) site = context.registers[:site] cfg = Configuration.read(site) count = (@args["count"] || cfg["latest_default_count"] || 5).to_i category = @args["category"] docs = site.collections["documents"]&.docs || [] docs = docs.select { |doc| doc.data["category"] == category } if category docs = docs.sort_by { |doc| doc.data["date"] || Time.at(0) }.reverse.first(count) out = +"<ul class=\"latest-documents\">\n" docs.each do |doc| data = doc.data title = escape_html(data["title"]) url = escape_html(doc.url) date = (data["date"] || Time.at(0)).strftime("%Y-%m-%d") out << %(<li><a href="#{url}">#{title}</a> <small>(#{date})</small></li>\n) end out << "</ul>\n" out end |