npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eleventy-plugin-footnotes

v0.11.0

Published

11ty plugin to render accessible footnotes

Downloads

360

Readme

eleventy-plugin-footnotes

This is an 11ty plugin to render accessible footnotes using Liquid.

Notes:

  • This plugin makes no styling consideration whatsoever. Refer to the FAQ for more information about styling.
  • Check out my own site’s repository for a real life usage of this plugin.

Installation

Install the dependency from npm:

npm install eleventy-plugin-footnotes

Update your 11ty configuration:

const footnotes = require('eleventy-plugin-footnotes')

module.exports = eleventyConfig => {
  eleventyConfig.addPlugin(footnotes, { /* … */ })
}

The plugin can be somewhat configured. Refer to the customisation section for a complete look at the settings.

Usage

  1. Wrap a text section with the footnoteref Liquid tag while making sure to pass it an id as first argument, and the footnote content as a second argument. See example.

  2. Render the footnotes section at the bottom of the article layout (or where you feel like) using the {% footnotes %} shortcode.

Example

Something about {% footnoteref "css-counters" "CSS counters are, in essence, variables maintained by CSS whose values may be incremented by CSS rules to track how many times they’re used." %}CSS counters{% endfootnoteref %} that deserves a footnote explaining
what they are.

Note that footnotes accept HTML, so you can inject any markup you want in there. If you would like to use Markdown (or any other filters of your choice), you could extract the footnote in a variable before:

{% assign css_counters_footnote = "[CSS counters](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Lists_and_Counters/Using_CSS_counters) are, in essence, variables maintained by CSS whose values may be incremented by CSS rules to track how many times they’re used." | markdown | replace: "<p>", "" | replace: "</p>", "" %}

Something about {% footnoteref "css-counters" css_counters_footnote %}CSS counters{% endfootnoteref %} that deserves a footnote explaining
what they are.

Note that if the footnote content (2nd argument) is omitted entirely (willingly or by mistake), the footnote reference will not be rendered as an anchor at all since there is nothing to link to.

Customisation

  • title: The title option is the content of the title of the footnotes section. This title can be visually hidden if desired but it should not be removed or emptied.

  • titleId: The titleId option is the id set to the title of the footnotes section. It is also referred in the aria-describedby attribute of every footnote reference.

  • backLinkLabel: The backLinkLabel option is a function resolving the aria-label of the back link of every footnote. It is important it differs from back link to back link.

  • baseClass: The baseClass option is used as the base class for all the other BEM classes (<base>__ref, <base>, <base>__title, <base>__list, <base>__list-item, <base>__back-link).

  • classes: Custom class names map for each element rendered by the plugin, in case you want to apply some additional utility classes. Note that if you specify baseClass, these class names will be applied in addition to the BEMish class names rather than overriding them. The following keys can be used in this map:

    • container: class name for the footnotes footer that renders the title and all of the footnotes.
    • title: class name for the title that appears above the footnotes list.
    • ref: class name for the anchor that takes you to the footnote.
    • list: class name for the list that renders the footnotes themselves.
    • listItem: class name for the list items.
    • backLink: class name for the back-link that appears at the end of each footnote.

These are the default options:

{
  baseClass: 'Footnotes',
  title: 'Footnotes',
  titleId: 'footnotes-label',
  backLinkLabel: (footnote, index) => 'Back to reference ' + index + 1,
  classes: {},
}

FAQ

Why are footnotes not rendered?

Make sure you have included the footnotes shortcode somewhere in your page, usually at the bottom of your content section.

{% footnotes %}

Why is a specific footnote not rendered?

If a reference does not pass the footnote content as second argument (or passes a falsy value), the footnote will be discarded entirely and the reference will not be wrapped with an anchor tag.

Additionally, a log like this one will be output during compilation:

[eleventy-plugin-footnotes] Warning: Footnote reference with id ‘css-counters’ has no given description (missing or falsy second argument); footnote omitted entirely.

Why are numbers not displayed?

Unlike other footnoting systems, this one uses properly labeled anchors as references instead of numbers (e.g. [1]). This is better for accessibility since links can be tabbed through or listed devoid of their surrounding context, and therefore should be self-explanatory.

To still render a sup number after every reference, you can use CSS counters. Initialise a counter on your content container (or body), and increment it at every reference. Use a pseudo-element to render the number.

body { counter-reset: footnotes }

[role="doc-noteref"]::after {
  counter-increment: footnotes;
  content: '[' counter(footnotes) ']'
}

Refer to this article on accessible footnotes or this stylesheet for a more comprehensive styling solution.