vanilla-hugo/layouts/partials/geturl.html
Danila Fedorin ec7b58c8ec Avoid passing in .Site-variables to geturl.html
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-06-09 18:14:53 -07:00

16 lines
665 B
HTML

{{- $siteSourceUrl := site.Params.siteSourceUrl -}}
{{- $submoduleLinks := site.Data.submodules -}}
{{- $scratch := .scratch -}}
{{- $scratch.Set "bestLength" -1 -}}
{{- $scratch.Set "bestUrl" (printf "%s/code/%s" $siteSourceUrl .path) -}}
{{- $scratch.Set "bestPath" "" -}}
{{- $filePath := .path -}}
{{- range $path, $url := $submoduleLinks -}}
{{- $bestLength := $scratch.Get "bestLength" -}}
{{- if and (le $bestLength (len $path)) (hasPrefix $filePath $path) -}}
{{- $scratch.Set "bestLength" (len $path) -}}
{{- $scratch.Set "bestPath" $path -}}
{{- $scratch.Set "bestUrl" (printf "%s%s" $url (strings.TrimPrefix $path $filePath)) -}}
{{- end -}}
{{- end -}}