Felix Jen
Felix Jen

Reputation: 154

Hugo or Grunt Handle Automatically Numbering Footnotes

I'm running a static site on Hugo, with some posts containing over 100+ footnotes [legal blog posts]. If I want to edit and add a footnote in the middle of the passage, right now, I have to renumber every single footnote.

Is there a Hugo [or Grunt] extension that allows me to assign "placeholders" for footnotes, and have them automatically change into numbers and place them in the right order upon build?

For example, I want to be able to write something like:

The quick brown fox[^foxes] jumped over the lazy dog[^dogs].
[^dogs]: Here is some dog info.
[^foxes]: Here is some fox info.

and have it automatically turned into

The quick brown fox[^1] jumped over the lazy dog[^2].
[^1]: Here is some fox info.
[^2]: Here is some dog info.

when I build the site. Note how it reordered the footnotes to match the order of appearance within the text, and also changed them to numbers.

Normally, I run hugo; grunt to build the site and it's hosted on Netlify.

Upvotes: 0

Views: 142

Answers (1)

runar
runar

Reputation: 2857

If you use Blackfriday as the Markdown rendering engine (Goldmark replaced Blackfriday as the default rendering engine in Hugo release 0.60.0), then you can write your post like this:

Lorem ipsum[^foo] dolor sit amet[^bar], consectetur adipiscing elit[^3].

[^bar]: second footnote
[^3]: third footnote
[^foo]: first footnote

And it will turn into this:

Lorem ipsum[1] dolor sit amet[2], consectetur adipiscing elit[3].

 1. first footnote ↑
 2. second footnote ↑
 3. third footnote ↑

Notice that you can use names instead of numbers when referencing footnotes, and that they will be displayed in the order of which they appear in the text, not in the order of the definitions.

Upvotes: 1

Related Questions