Commit e0d24080 authored by rmrf's avatar rmrf Committed by Hiren Patel

customize cite

parent d6160849
......@@ -3,3 +3,4 @@ require 'jekyll/scholar/extras/extra_utils'
require 'jekyll/scholar/extras/bibliography_hdp'
require 'jekyll/scholar/extras/bibliography_bytype'
require 'jekyll/scholar/extras/details_hdp'
require 'jekyll/scholar/tags/cite_details'
module Jekyll
class ScholarExtras
module Utilities
attr_reader :bibtex_file, :config, :site
def bibtex_options
@bibtex_options ||= { :filter => :latex }
end
@bibtex_options ||= { :filter => :latex }
end
def bibtex_path
@bibtex_path ||= extend_path(bibtex_file)
end
def bibliography
@bibliography ||= BibTeX.open(bibtex_path, bibtex_options)
end
def get_entries(and_list)
b = bibliography['@*']
and_list.each { |t|
b = bibliography[t] & b
}
puts b.length
unless config['sort_by'] == 'none'
b.sort_by! { |e| e[config['sort_by']].to_s }
b.reverse! if config['order'] =~ /^(desc|reverse)/i
end
b
end
b
end
def public_journal_entries
def public_journal_entries
bart = bibliography['@article']
bpub = bibliography['@*[public!=no]']
b = bart & bpub
......@@ -40,27 +40,61 @@ module Jekyll
puts bart.length
puts bpub.length
puts b.length
unless config['sort_by'] == 'none'
b.sort_by! { |e| e[config['sort_by']].to_s }
b.reverse! if config['order'] =~ /^(desc|reverse)/i
end
b
end
b
end
def public_entries
b = bibliography['@*[public!=no]']
unless config['sort_by'] == 'none'
b.sort_by! { |e| e[config['sort_by']].to_s }
b.reverse! if config['order'] =~ /^(desc|reverse)/i
end
b
end
b
end
def details_file_for(entry)
name = entry.key.to_s.dup
name.gsub!(/[:\s]+/, '_')
[name, 'html'].join('.')
end
def details_link_for(entry, base = base_url)
[base, details_path, details_file_for(entry)].join('/')
end
def base_url
@base_url ||= site.config['baseurl'] || site.config['base_url'] || nil
end
def details_path
config['details_dir']
end
def cite(key)
entry = bibliography[key]
if bibliography.key?(key)
citation = CiteProc.process entry.to_citeproc, :style => config['style'],
:locale => config['locale'], :format => 'html', :mode => :citation
link_to "##{entry.key}", citation.join
else
"(missing reference)"
end
end
end
end
end
module Jekyll
class Scholar
class CiteTagDetails < Liquid::Tag
include Scholar::Utilities
include ScholarExtras::Utilities
attr_reader :key, :pages
def initialize(tag_name, arguments, tokens)
super
@config = Scholar.defaults.dup
@key = arguments.strip.split(/\s+/)[0]
end
def render(context)
set_context_to context
cite_details key
end
end
end
end
Liquid::Template.register_tag('cite_details', Jekyll::Scholar::CiteTagDetails)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment