项目作者: gabysbrain

项目描述 :
citations for middleman using bibtex
高级语言: Ruby
项目地址: git://github.com/gabysbrain/middleman-citation.git
创建时间: 2014-08-22T09:46:50Z
项目社区:https://github.com/gabysbrain/middleman-citation

开源协议:MIT License

下载


Middleman-citation

Codeship Status for gabysbrain/middleman-citation

This is an extension for the Middleman static
site generator that adds functions you can use in your templates for
formating citations from BibTeX.

An example of a Middleman template using this plugin is available at
https://github.com/gabysbrain/website/blob/master/source/cv.html.slim.

Installation

Add this line to your Gemfile:

  1. gem 'middleman-citation'

And then execute:

  1. $ bundle install

Or install it yourself as:

  1. $ gem install middleman-citation

Configuration

In your config.rb file for your site add:

  1. require 'middleman-citation'
  2. activate :citation do |opts|
  3. opts.bibtex = '/path/to/your.bib' # path to a bibtex file
  4. opts.style = 'ieee' # style from citeproc-styles
  5. opts.format = 'html' # output format
  6. end

Usage

This adds the following helper methods you can use in your Middleman
templates.

  • citations_search(search_term, author): Search the BibTeX file for all
    citations matching a search term (such as '@article') and by the given
    author. The author argument can be ommitted to match all authors and
    a search_term of nil will match all items in the bibliography.

  • citation(key): Given a BibTeX citation key as returned from
    citations_search, return a formatted string the citation according to
    how the style and format options were set.

For extra control on the output, one can use:

  • citation_entry(key): Return the unformatted entry (a hash)
    corresponding to the BibTeX citation key.

  • citation_formatted(entry): Format an unformatted entry.

In fact the citation method is implemented using these:

  1. def citation(key)
  2. entry = citation_entry(key)
  3. citation_formatted(entry)
  4. end

The point is that one can interrogate the unformatted entry to
add extra formatting: The following code adds a DOI link if the
entry matching the key has a URL field containing the DOI.

  1. entry = citation_entry(key)
  2. entry_html = citation_formatted(entry)
  3. if doi_url = entry.fetch('URL', false) then
  4. doi_link = "(%s)" % link_to('doi', doi_url)
  5. end
  6. [entry_html, doi_link].compact.join(' ')

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request