Skip to content

Use citeproc.js in Eleventy, to process citations and generate bibliographies for your Eleventy projects.

Notifications You must be signed in to change notification settings

Myllaume/eleventy-plugin-citeproc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eleventy-plugin-citeproc

Use citeproc.js in Eleventy, to process citations and generate bibliographies for your Eleventy projects.

Bibliographic data and styles use the Citation Style Language (CSL) standard. The insertion of citations in files uses the Pandoc citation syntax.

Features

Process citations and generate bibliographies with filters :

Sample text

On writing as a technology of the intellect [@Goody1977, 12].

See how to write citations at Pandoc manual.

Code

Liquid, Nunjucks

<main>
    {{ content | references | safe }}
</main>

<footer>
    {{ content | bibliography | safe }}
</footer>

11ty.js

module.exports = function(content) {
    return `<main>${this.references(content)}</main><footer>${this.bibliography(content)}</footer>`;
};

Result

<main>
    On writing as a technology of the intellect (Goody 1977, p. 12).
</main>

<footer>
    <div class="csl-entry">GOODY, Jack, 1977. <i>The Domestication of the Savage Mind</i>. Cambridge : Cambridge University Press. ISBN 978-0-521-21726-2. </div>
</footer>

Installation

Download

Requires Eleventy 1.0.0 or newer & NodeJs 15 or newer.

npm i eleventy-plugin-citeproc

Configuration

Global options

You need three files to get citations and bibliographies :

  • Bibliographic data : .json file, containing metadata describing bibliographic references (example further down). Dowloaded from your Zotero public group?
  • Bibliographic style : .csl file, containing formatting rules for citations and bibliographies. Dowloaded from Zotero CSL styles directory.
  • Bibliographic localization : .xml file, containing localized bibliographic terms (e.g. publisher, issue…) in the language of your choice. Dowloaded from CSL project repository
const path = require('path');

const eleventyCiteproc = require("eleventy-plugin-citeproc");

module.exports = function (eleventyConfig) {
    eleventyConfig.addPlugin(eleventyCiteproc, {
        bibliographicStylePath: path.join(__dirname, 'iso690-author-date-fr-no-abstract.csl'),
        bibliographicLocalizationPath: path.join(__dirname, 'locales-en-GB.xml'),
        bibliographicDataPath: path.join(__dirname, 'bib-data.json')
    });

    return {
        dir: {
            input: "views",
            output: "dist"
        }
    };
};

Bibliographic data file

The string on id property (goody1977 on below exemple) is the key you need to write on your content.

[
    {
        "id": "goody1977",
        "author": [
            {
                "family": "Goody",
                "given": "Jack"
            }
        ],
        "event-place": "Cambridge",
        "ISBN": "978-0-521-21726-2",
        "issued": {
            "date-parts": [
                [
                    1977
                ]
            ]
        },
        "language": "en",
        "number-of-pages": "179",
        "publisher": "Cambridge University Press",
        "publisher-place": "Cambridge",
        "title": "The Domestication of the Savage Mind",
        "type": "book"
    }
]

Local options

Custom bibliography entries class name

Liquid, Nunjucks

<footer>
    {{ content | bibliography({ className: 'custom' }) | safe }}
</footer>

11ty.js

module.exports = function(content) {
    return `<main>${this.bibliography(content, { className: 'custom' })}</main>`;
};

Output

<main>
    <div class="custom">GOODY, Jack, 1977...</div>
</main>

Test

npm i
npm test

See directories /test and /utils. Add /utils/**.11ty.js files to check in /test/**.js files content.

Credits

Thanks to Arthur Perret about this documentation.

About

Use citeproc.js in Eleventy, to process citations and generate bibliographies for your Eleventy projects.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published