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


#1

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.


#2

Do you mean like footnotes?

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


#3

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.


#4

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


#5

look at

footnoteAnchorPrefix (“”)
    Prefix for footnote anchors.

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

play with this :slight_smile:


#6

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


#7

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


#8

Please mark it as solved - if it is