Render-link markup for limited list of rel = follow

Hi, I was looking for a code to setup my render-link.html.

I want the search engine robots to only follow valuable links to increase Domain Ranking. The other links are set as nofollow.

The AI engines helped me do this.

Enjoy


{{ $href := .Destination }}
{{ $followDomains := slice
  "https://www.valuable1.org"
  "https://www.valuable2.com"
}}

{{ $addRelFollow := false }}
{{ range $followDomains }}
  {{ if strings.HasPrefix $href . }}
    {{ $addRelFollow = true }}
  {{ end }}
{{ end }}

<a href="{{ $href | safeURL }}"
  {{- with .Title}} title="{{ . }}"{{ end -}}
  {{ if $addRelFollow }} target="_blank" rel="external"
  {{- else if strings.HasPrefix $href "http" }} target="_blank" rel="external nofollow noopener"{{ end -}}
  >{{ .Text | safeHTML }}</a>
1 Like

it’s a good idea. :slightly_smiling_face:

One suggestion would be to keep the list of valuable domains in such a way that you can edit it as you would edit content.

Fixed code (wrapping links in <p>) starting with official shortcode.

{{- $u := urls.Parse .Destination -}}
{{- $href := $u.String -}}
{{ $followDomains := slice
  "https://www.domain1.org"
  "https://www.domain2.com"
}}
{{- $addRelFollow := false -}}
{{- range $followDomains -}}
  {{- if strings.HasPrefix $href . -}}
    {{- $addRelFollow = true -}}
  {{- end -}}
{{- end -}}
{{- if strings.HasPrefix $u.String "#" -}}
  {{- $href = printf "%s#%s" .PageInner.RelPermalink $u.Fragment -}}
{{- else if and $href (not $u.IsAbs) -}}
  {{- $path := strings.TrimPrefix "./" $u.Path -}}
  {{- with or
    ($.PageInner.GetPage $path)
    ($.PageInner.Resources.Get $path)
    (resources.Get $path)
  -}}
    {{- $href = .RelPermalink -}}
    {{- with $u.RawQuery -}}
      {{- $href = printf "%s?%s" $href . -}}
    {{- end -}}
    {{- with $u.Fragment -}}
      {{- $href = printf "%s#%s" $href . -}}
    {{- end -}}
  {{- end -}}
{{- end -}}
<a href="{{ $href }}"
  {{- with .Title }} title="{{ . }}" {{- end -}}
  {{- if $addRelFollow }} target="_blank" rel="external" {{- else if strings.HasPrefix $href "http" }} target="_blank" rel="external nofollow noopener"{{ end -}}
  >{{ .Text }}</a>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.