How can I generate list of references used in each post?

Hi guys.
In my articles, I use more external references. I would like to automatically generate a list of all external references used in articles. Example:


This is an article with many external references. Please visit “this site” (1) and
“this site” (2) and also this “awesome site” (3)

References:

(1): site1.com
(2): site2.com
(3): awesome-site.com


Is it a way how to print list of external references in the end of each article automatically? Thanks.

Do you mean like footnotes?

Scroll down a little bit to footnotes here for example: https://gohugo.io/content-management/formats/#blackfriday-extensions

Yes, thanks @pointyfar , It is similar to what I need. But black friday generate return link with label: [return]. Do you know how can I customize this text? I need it to translate to my language.

No sorry, I don’t. Perhaps someone else can chime in :slight_smile:

look at

footnoteAnchorPrefix (“”)
    Prefix for footnote anchors.

footnoteReturnLinkContents (“”)
    Text to display for footnote return links.

play with this :slight_smile:

3 Likes

You can solve this with 2 shortcodes

put this in note.html in your shortcode directory (in ONE line!)

{{ $id := .Get 0 }}{{ $val := .Get 1}}{{ .Page.Scratch.SetInMap "footnotes" $id $val }}({{ $id }})

put this in footnotes.html in your shortcode directory

{{ $hdr := .Get 0 }}
{{ $list := .Page.Scratch.Get "footnotes"}}
{{ $hdr }}:<br/>
{{ range  $key, $value := $list }}
	{{ $key}}: {{$value}}<br/>
{{end}}
{{ .Page.Scratch.Delete "footnotes" }}

in your content file:

   This is an article with many external references. 
   Please visit “this site” {{< note "1" "site1.com" >}} and  
   “this site” {{< note "2" "site2.com" >}} and also 
   this “awesome site” {{< note "3" "awesome-site.com" >}}

   {{< footnotes "References" >}}

Result:

This is an article with many external references. Please visit “this site” (1) and “this site” (2) and also this “awesome site” (3)

    References:
    1: site1.com
    2: site2.com
    3: awesome-site.com

This is simple, put it to your needs

3 Likes

@ju52 thanks a lot. I have not known about Scratch :+1:

Please mark it as solved - if it is