{{ $url := .Destination }} {{- if (strings.HasPrefix $url "http") -}} {{/* external link, add icon */}} {{- .Text | safeHTML -}} {{- partialCached "icon" "open_in_new" "open_in_new" -}} {{- else if (strings.HasPrefix $url "/") -}} {{ if (strings.HasSuffix (urls.Parse $url).Path ".md") }} {{/* abs path to markdown file, use ref */}} {{ $url = (ref .Page $url) }} {{ end }} {{ .Text | safeHTML }} {{- else -}} {{/* check if the file links to index.md */}} {{- if (strings.FindRE `([^_]|^)index.md` $url 1) -}} {{ .Text | safeHTML }} {{- else -}} {{/* relative link, use ref */}} {{ .Text | safeHTML }} {{- end -}} {{- end -}}