{{/* this is used to replace the keywords in content with links

reference:
- https://discourse.gohugo.io/t/replace-function-when-applied-to-content-displays-html-tags-instead-of-rendering-them/37717
- https://gohugo.io/templates/data-templates/
- https://github.com/gohugoio/hugo/issues/1150
*/}}

{{ $Content := .Content }}

{{ $url := "static/csv/keywords-links.csv" }}
{{ $sep := "," }}

{{/* start - range the CSV keywords */}}
{{ range $i, $r := getCSV $sep $url }}

{{ $keyword := index $r 0 }}
{{ $link := index $r 1 }}

{{/* reference:
https://discourse.gohugo.io/t/hugo-templating-quotes-within-quotes/11661/4
https://gohugo.io/templates/rss/#reference-your-rss-feed-in-head
*/}}
{{- $newWithLink := printf `<a href="%s">%s</a>` $link $keyword -}}

{{- if (strings.Contains $Content $keyword) -}}
{{ $Content = replace $Content $keyword $newWithLink }}
{{ end }}

{{/* end - range the CSV keywords */}}
{{ end }}

{{ $Content | safeHTML }}