From 2d646b851ee3af3d5a2250d37ab70396a450e09a Mon Sep 17 00:00:00 2001 From: Alex Gil Date: Thu, 21 Jan 2016 10:18:42 -0500 Subject: [PATCH] added method for link target, with a new tag and documentation --- README.md | 6 ++++++ lib/jekyll/scholar/utilities.rb | 22 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b40079d..c02231f 100644 --- a/README.md +++ b/README.md @@ -384,6 +384,12 @@ a specific page. As an example, the tag will attempt to read the key `ruby` from file `/home/foo/bar.bib`. It will not fallback to the default BibTeX file. + +#### Citation pointing to another page in your site +In some cases, you might want your citation to link to another page on your cite (ex. a separate works cited page). As a solution, Jekyll-Scholar provides the `--relative` tag. For example, if you wanted the link to point to an ID in a bibliography.html page, you would use: + + {% cite ruby --relative bibliography.html %} + #### Multiple bibliographies within one document (like [multibib.sty](http://www.ctan.org/pkg/multibib)) When you have multiple `{% bibliography %}` sections in one file, diff --git a/lib/jekyll/scholar/utilities.rb b/lib/jekyll/scholar/utilities.rb index eedb46f..b16f8ca 100644 --- a/lib/jekyll/scholar/utilities.rb +++ b/lib/jekyll/scholar/utilities.rb @@ -17,7 +17,11 @@ module Jekyll # #site readers module Utilities - attr_reader :config, :site, :context, :prefix, :text, :offset, :max + #elotroalex edit: added local variable relative + + attr_reader :config, :site, :context, :prefix, :text, :offset, :max, :relative + + def split_arguments(arguments) @@ -52,12 +56,18 @@ module Jekyll opts.on('-q', '--query QUERY') do |query| @query = query - end + end opts.on('-p', '--prefix PREFIX') do |prefix| @prefix = prefix end + # elotroalex edit: added flag for relative url for link_to + + opts.on('-r', '--relative RELATIVE') do |relative| + @relative = relative + end + opts.on('-t', '--text TEXT') do |text| @text = text end @@ -567,6 +577,12 @@ module Jekyll (context['citation_numbers'] ||= {})[key] ||= cited_keys.length end + # #elotroalex edit: Added new method to control href output for cite + + def link_target_for key + "#{relative}##{[prefix, key].compact.join('-')}" + end + def cite(keys) items = keys.map do |key| if bibliography.key?(key) @@ -577,7 +593,7 @@ module Jekyll end end - link_to "##{[prefix, keys[0]].compact.join('-')}", render_citation(items) + link_to link_target_for(keys[0]), render_citation(items) end def cite_details(key, text) -- GitLab