class Jekyll::BibTag

{% bibliography %} which generates the bibliography

Public Class Methods

new(tag_name, text, tokens) click to toggle source
Calls superclass method
# File _plugins/jekyll-scholar.rb, line 120
def initialize(tag_name, text, tokens)
  super
  @text = text.strip
end

Public Instance Methods

render(context) click to toggle source
# File _plugins/jekyll-scholar.rb, line 125
def render(context)
  site = context.registers[:site]
  Gtn::Scholar.load_bib(site)
  # Which page is rendering this tag?
  source_page = context.registers[:page]['path']
  global_bib = site.config['cached_global_bib']
  # citeproc = site.config['cached_citeproc']
  # We have our page's citations
  citations = site.config['citation_cache'][source_page] || []
  # For each of these citation IDs, we need to get the formatted version + pull out
  # year, month for sorting.
  unique_citations = citations.each_with_object(Hash.new(0)) do |b, a|
    a[b] += 1
  end.keys
  # Remove nil citations
  unique_citations = unique_citations.reject { |c| global_bib[c].nil? }
  # And now sort them by date + names
  sorted_citations = unique_citations.sort do |a, b|
    global_bib[a].date.to_s + global_bib[a].names.join(' ') <=>
      global_bib[b].date.to_s + global_bib[b].names.join(' ')
  end

  out = '<ol class="bibliography">'
  out += sorted_citations.map do |c|
    r = Gtn::Scholar.render_citation(c)
    %(<li id="#{c}">#{r}</li>)
  end.join("\n")
  out += '</ol>'
  out
end