Commit d690bfd8 authored by Sylvester Keil's avatar Sylvester Keil

add 'cited' option to bibliography tag

the cited option will limit the bibilography to those entries
which have been previously cited on the same page using the
cite tag.

see #10
parent 29380d62
......@@ -9,12 +9,25 @@ module Jekyll
@config = Scholar.defaults.dup
@bibtex_file, @query = arguments.strip.split(/\s*filter:\s*/)
if @bibtex_file == 'cited'
@bibtex_file = nil
@cited = true
end
end
def render(context)
set_context_to context
references = entries.map do |entry|
references = entries
if @cited
references = cited_references.map do |key|
references.detect { |e| e.key == key }
end
end
references.map! do |entry|
reference = CiteProc.process entry.to_citeproc, :style => config['style'],
:locale => config['locale'], :format => 'html'
......
......@@ -3,23 +3,27 @@ module Jekyll
class CiteTag < Liquid::Tag
include Scholar::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
context['cited'] ||= []
context['cited'] << key
cite key
end
end
end
end
......
......@@ -6,7 +6,7 @@ module Jekyll
# #site readers
module Utilities
attr_reader :bibtex_file, :config, :site, :query
attr_reader :bibtex_file, :config, :site, :query, :context
def bibtex_options
@bibtex_options ||= { :filter => :latex }
......@@ -108,8 +108,12 @@ module Jekyll
content_tag :a, content || href, attributes.merge(:href => href)
end
def cited_references
context && context['cited'] || []
end
def set_context_to(context)
@site = context.registers[:site]
@context, @site, = context, context.registers[:site]
config.merge!(site.config['scholar'] || {})
end
......
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