Draw from 'data/' for submodule links

I didn't know about https://gohugo.io/templates/data-templates/

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
2024-05-16 15:33:44 -07:00
parent e2fb9362f6
commit 77b8d5e65b
5 changed files with 6 additions and 7 deletions

View File

@@ -2,11 +2,10 @@
{{ $scratch.Set "bestLength" -1 }}
{{ $scratch.Set "bestUrl" (printf "%s/code/%s" .siteSourceUrl .path) }}
{{ $filePath := .path }}
{{ range $module, $props := .submoduleLinks }}
{{ $path := index $props "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 "bestUrl" (printf "%s%s" (index $props "url") (strings.TrimPrefix $path $filePath)) }}
{{ $scratch.Set "bestUrl" (printf "%s%s" $url (strings.TrimPrefix $path $filePath)) }}
{{ end }}
{{ end }}