{{ $link := .Destination }} {{ $isRemote := strings.HasPrefix $link "http" }} {{ if not $isRemote }} {{ $url := urls.Parse .Destination }} {{ $path := replace $url.Path "README" "" }} {{ $path = replace $path ".md" "" }} {{ $url = urls.Parse $path }} {{ if or ($url.Path) (eq .Destination "README.md") }} {{ $fragment := "" }} {{ with $url.Fragment }} {{ $fragment = printf "#%s" . }} {{ end }} {{ $link = $url.Path }} {{ with .Page.GetPage $url.Path }} {{ $link = printf "%s%s" .RelPermalink $fragment }} {{ end }} {{ end }} {{ end }} {{ .Text | safeHTML }}