References

- 126 words - 1 minute

How to create references like Wikipedia

References

To add a numbered superscript like [1] that links to the corresponding item in an automatically generated reference list:

\{\{< note "some markdown text" >}}

Reference list

To insert an ordered list of items generated from the reference instances in the document:

## References
\{\{< footnotes >}}

Implementation

layouts/shortcodes/note.html

{{ .Page.Scratch.Add "Ord" 1 }} {{ $id := print (.Page.Scratch.Get "Ord") }}{{ $val := .Get 0}}{{ .Page.Scratch.SetInMap "footnotes" $id $val }}<sup title="{{ $val | markdownify }}">[<a href=#ref{{ $id }}>{{ $id }}</a>]</sup>

layouts/shortcodes/footnotes.html

{{ $list := .Page.Scratch.Get "footnotes"}}
<ol class="references">
  {{ $key := 1 }}
  {{ range sort $list }}
  <li id="ref{{ $key }}">{{ . | markdownify }}<br/>
  {{ $key = add $key 1 }}
  {{end}}
</ol>
{{ .Page.Scratch.Delete "footnotes" }}