Giter VIP home page Giter VIP logo

eleventy-plugin-citeproc's Introduction

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.

eleventy-plugin-citeproc's People

Contributors

myllaume avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

eleventy-plugin-citeproc's Issues

Custom bibliography length

For this content, we get three paragraphs of bibliography.

Lorem [@jeanneret2005, 12 ; @ledeuff2014, 10] ipsum dolor est si amet [@goody1977, 12]

Need to add argument to bibliography filter as below to set up a maximum limit of bibliography length.

<footer>
        {{ content | bibliography({ maxLength: 2 }) | safe }}
</footer>

Custom bibliography <div> class name

We get csl-entry class by default :

<div class="csl-entry">...</div>

Need to add argument to bibliography filter as below to custom the class name of <div>.

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

render

<footer>
        <div class="custom">...</div>
</footer>

File does not exist

Is this plugin compatible with Eleventy v2? I'm getting File /path/to/style.csl does not exist even though the file is exactly where the plugin is complaining that it isn't. Full trace here:

[11ty] Eleventy CLI Fatal Error: (more in DEBUG output)
[11ty] 1. Error processing a plugin (via EleventyPluginError)
[11ty] 2. File /full/path/to/repository/assets/biblio/chicago-note-bibliography.csl does not exists. (via Error)
[11ty]
[11ty] Original error stack trace: Error: File /full/path/to/repository/assets/biblio/chicago-note-bibliography.csl does not exists.
[11ty]     at module.exports (/full/path/to/repository/node_modules/eleventy-plugin-citeproc/src/csl.js:33:19)
[11ty]     at module.exports (/full/path/to/repository/node_modules/eleventy-plugin-citeproc/index.js:12:17)
[11ty]     at UserConfig._executePlugin (/full/path/to/repository/node_modules/@11ty/eleventy/src/UserConfig.js:386:7)
[11ty]     at TemplateConfig.processPlugins (/full/path/to/repository/node_modules/@11ty/eleventy/src/TemplateConfig.js:254:25)
[11ty]     at TemplateConfig.mergeConfig (/full/path/to/repository/node_modules/@11ty/eleventy/src/TemplateConfig.js:367:10)
[11ty]     at TemplateConfig.getConfig (/full/path/to/repository/node_modules/@11ty/eleventy/src/TemplateConfig.js:159:26)
[11ty]     at new Eleventy (/full/path/to/repository/node_modules/@11ty/eleventy/src/Eleventy.js:109:39)
[11ty]     at Object.<anonymous> (/full/path/to/repository/node_modules/@11ty/eleventy/cmd.js:60:16)
[11ty]     at Module._compile (node:internal/modules/cjs/loader:1378:14)
[11ty]     at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
(node:28529) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

The style is freshly downloaded from the CSL/styles repository with no modifications, by the way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.