Skip to content
Browse files

Initial import

  • Loading branch information...
0 parents commit b7be2769594edd68a3bbe181bbb7ce33d8352bf9 @anarchivist anarchivist committed Feb 26, 2012
Showing with 141 additions and 0 deletions.
  1. +23 −0 LICENSE
  2. +71 −0 README.md
  3. +47 −0 citation.rb
23 LICENSE
@@ -0,0 +1,23 @@
+(The MIT License)
+
+Copyright (c) 2010 Pablo de Oliveira Castro
+Copyright (c) 2011 Sylvester Keil
+Copyright (c) 2012 Archome Collective
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the 'Software'), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
71 README.md
@@ -0,0 +1,71 @@
+jekyll-citation
+===============
+
+This is a plugin for [Jekyll](https://github.com/mojombo/jekyll) and [Octopress](http://octopress.org) that is designed to render citations encoded in [BibTeX](http://bibtex.org/) as part of posts and pages.
+
+This plugin is based on Pablo Oliveira's [bibjekyll](https://github.com/pablooliveira/bibjekyll) plugin and Sylvester Keil's [jekyll-scholar](https://github.com/inukshuk/jekyll-scholar) gem, but uses neither.
+
+Setup
+-----
+
+* Install the `citeproc-ruby` and `bibtex-ruby` gems.
+
+* Copy `citation.rb` to your `_plugins/` directory (or `plugins/` for Octopress)
+
+* Add the following lines to your `_config.yml` file for Jekyll:
+
+ # BibTeX Citation plugin
+ citation:
+ citation_style: apa
+ citation_locale: en
+
+* Optionally, you can use other citation styles encoded in the [Citation Style Language (CSL)](http://citationstyles.org/). The entire CSL 1.0 Style Repository is available on Github at [citation-style-language/styles](https://github.com/citation-style-language/styles). For example, if you wanted to use the Chicago Manual of Style "author-date" format, you would save [this file](https://github.com/citation-style-language/styles/raw/master/chicago-author-date.csl) locally to `_plugins` and change your `_config.yml` to read:
+
+ # BibTex Citation plugin
+ citation:
+ citation_style: _plugins/chicago-author-date.csl
+ citation_locale: en
+
+Usage
+-----
+
+This plugin parses BibTeX entries that are enclosed in a special Liquid block:
+
+ {% bibtex %}
+ ....
+ {% endbibtex %}
+
+For example:
+
+ ---
+ layout: post
+ title: "Test"
+ date: 2012-02-26 17:27
+ comments: true
+ ---
+
+ This is an example citation of Brothman's 1991 article.
+
+ {% bibtex %}
+ @article{brothman1991orders,
+ title={Orders of value: probing the theoretical terms of Archival Practice},
+ author={Brothman, B.},
+ journal={Archivaria},
+ volume={32},
+ number={1},
+ year={1991}
+ }
+ {% endbibtex %}
+
+As a result you would get the following output (dependent on the templates you use, of course):
+
+ <h1>Test</h1>
+
+ <p>This is an example citation of Brothman's 1991 article.</p>
+
+ <p><p>Brothman, B. (1991). Orders of value: probing the theoretical terms of Archival Practice. <i>Archivaria</i>, <i>32</i>(1).</p>
+
+License
+-------
+
+This plugin is released under the MIT License, the same license as Jekyll.
47 citation.rb
@@ -0,0 +1,47 @@
+require 'bibtex'
+require 'citeproc'
+
+module Jekyll
+
+ class BibtexBlock < Liquid::Block
+
+ def initialize(tag_name, text, tokens)
+ super
+ end
+
+ # Bibtex code may use {{ }} markups which interfere with liquid.
+ # Therefore, we override parse to completely ignore the content
+ # of the {% bibtex %} blocks.
+ def parse(tokens)
+ @nodelist ||= []
+ @nodelist.clear
+ while token = tokens.shift
+ if token =~ IsTag and token =~ FullToken and block_delimiter == $1
+ end_tag
+ return
+ else
+ @nodelist << token
+ end
+ end
+ assert_missing_delimitation!
+ end
+
+ def render(context)
+ # get the content of the {% bibtex %} block
+ content = super.join
+ @config = context.registers[:site].config['citation'] || {}
+ @config['citation_style'] ||= 'apa'
+ @config['citation_locale'] ||= 'en'
+ out = BibTeX.parse(content, :include => [:meta_content]).map do |b|
+ if b.respond_to?(:to_citeproc)
+ CiteProc.process b.to_citeproc, :style => @config['citation_style'], :locale => @config['citation_locale'], :format => 'html'
+ else
+ b.is_a?(BibTeX::MetaContent) ? b.to_s : ''
+ end
+ end
+ out
+ end
+ end
+end
+
+Liquid::Template.register_tag('bibtex', Jekyll::BibtexBlock)

0 comments on commit b7be276

Please sign in to comment.
Something went wrong with that request. Please try again.