Files
hugo-book/layouts/_partials/docs/links/portable-link.html
2025-09-21 22:29:59 +02:00

29 lines
965 B
HTML

{{- $destination := .Destination -}}
{{- $url := urls.Parse .Destination -}}
{{- $isRemote := $url.IsAbs -}}
{{- $isFragment := strings.HasPrefix .Destination "#" -}}
{{- if and (not $isRemote) (not $isFragment) -}}
{{- $path := strings.TrimPrefix "./" $url.Path -}}
{{- $path = strings.TrimSuffix ".md" $path -}}
{{- $path = strings.TrimSuffix "/_index" $path -}}
{{- with (.Page.GetPage $path) -}}
{{- $destination = .RelPermalink -}}
{{- else with (.Page.Resources.Get $path) -}}
{{- $destination = .RelPermalink -}}
{{- else with (resources.Get $path) -}}
{{- $destination = .RelPermalink -}}
{{- else -}}
{{- warnf "Reference '%s' not found in '%s'" .Destination .Page.Permalink -}}
{{- end -}}
{{- with $url.RawQuery -}}
{{- $destination = print $destination "?" . -}}
{{- end -}}
{{- with $url.Fragment -}}
{{- $destination = print $destination "#" . -}}
{{- end -}}
{{- end -}}
{{- return $destination -}}