Page variables, render hooks, and goldmark.linkContext

Thanks everyone.
Based on your advice (and bep’s advice from 2019), I was able to create two distinct variables ($external and $internal) and style them differently.
Probably a cleaner way to do it, but this works just fine for me.

{{if strings.HasPrefix .Destination "http" }}
{{ $external := .Destination }}

<a href="{{ $external | safeURL }}"{{with .Title}}{{.}}{{end}}>
{{ .Text | safeHTML }}</a>

{{end}}


{{ if not (strings.HasPrefix .Destination "http") }}
{{ $internal := urls.Parse .Destination}}
{{- if $internal.Path -}}
{{ $fragment := "" }}
{{- with $internal.Fragment }}{{ $fragment = printf "#%s" . }}{{ end -}}
{{- with .Page.GetPage $internal.Path }}{{ $internal = printf "%s%s" .RelPermalink $fragment }}
{{ end }}
{{ end -}}


<div class="tooltip">
<a href="{{ $internal | safeURL }}"{{with .Title}}{{.}}{{end}}>
{{ .Text | safeHTML }}</a>
<div class="right bottom">
<div class="tooltip-title">{{ with .Page.GetPage .Destination}}{{.Title}}{{end}}</div>
<div class="tooltip-excerpt">
{{with .Page.GetPage .Destination}}
{{ with .Params.featured_image }}
<figure><img class="title-image" src="{{ index . 0 }}" alt=""></figure>{{ end }}
{{ end }}
{{with .Page.GetPage .Destination}}{{.Summary}}{{end}}
</div>
</div>
</div>
{{- end -}}
1 Like