class Jekyll::CiteUrlTag

{% cite_url X %} which generates URL for the article

Public Class Methods

new(tag_name, text, tokens) click to toggle source
Calls superclass method
# File _plugins/jekyll-scholar.rb, line 71
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 76
def render(context)
  page = context.registers[:page]
  site = context.registers[:site]
  Gtn::Scholar.load_bib(site)

  # Mark this page as having citations
  page['cited'] = true

  return "@#{@text}" if page['citation_target'] == 'R'

  # Which page is rendering this tag?
  source_page = page['path']

  # Citation Frequency
  site.config['citation_count'] = Hash.new(0) if !site.config.key?('citation_count')
  site.config['citation_count'][@text] += 1

  # If the overall cache is nil, create it
  site.config['citation_cache'] = {} if site.config['citation_cache'].nil?
  # If the individual page in the chace is nil, create it.
  site.config['citation_cache'][source_page] = [] if site.config['citation_cache'][source_page].nil?

  # Push it to our cache.
  site.config['citation_cache'][source_page].push(@text)

  begin
    doi = site.config['cached_citeproc'].items[@text].doi
    url = site.config['cached_citeproc'].items[@text].url
    if !doi.nil?
      "https://doi.org/#{doi}"
    elsif !url.nil?
      url
    end
    res = url
  rescue StandardError => e
    Jekyll.logger.warn "[GTN/scholar] Could not render #{@text} from #{source_page} (#{e})"
    res = %(<span>https://example.com/ERROR+INVALID+CITATION+#{@text}</span>)
  end
  res
end