Render-link.html help need

I have a default nofollow setup in the posts. Dofollow only my own domain link, and the domain in the front matter dofollow tag.
My existing front matter:
dofollow: domain-allow.com

The code below can only work for one domain; how could I change the render-link.html to allow nofollow multiple domains?

New front matter:
dofollow: ["domain-allow1.com", "domain-allow2.com", "domain-allow3.com"]

My existing render-link.html

<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }} {{ if (or (in (.Destination) "mydomain.com") (in (.Destination) .Page.Params.dofollow))  }} target="_blank" rel="noopener" {{ else if strings.HasPrefix .Destination "http" }} target="_blank" rel='noopener nofollow' {{ else }} target="_blank" rel="noopener" {{ end }} >{{ .Text | safeHTML }}</a>

Is render-link.html a partial? How do you call it from the templates?

You could do something like

{{ $do := false }}
{{ $destination := .Destination }}
{{ $dofollow := .Page.Params.dofollow }}
{{ range $dofollow }}{{ if (in ($destination) .) }}{{ $do = true }}{{ end }}{{ end }}

{{ if (or (in (.Destination) "mydomain.com") $do  )  }} 
...

Sorry for the late reply, it’s working perfectly well!

my front matter:
dofollow: [“mydomain.com”, “domain-allow1.com”,“domain-allow2.com”]
my final code:

{{ $do := false }}
{{ $destination := .Destination }}
{{ $dofollow := .Page.Params.dofollow }}
{{ range $dofollow }}
{{ if (in ($destination) .) }}{{ $do = true }}{{ end }}
{{ end }}

{{ if ($do) }}
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }} target="_blank" rel=“noopener” rel=‘noopener’>{{ .Text | safeHTML }}
{{ else }}
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }} target="_blank" rel=“noopener nofollow” rel=‘noopener’>{{ .Text | safeHTML }}
{{ end }}

1 Like

render-link.html is a hugo render hook, more detail information here:

1 Like

Interesting, thanks!