vanilla-hugo/layouts/partials/geturl.html
Danila Fedorin b1334455ea Track the best path for a submodule that was added
For Agda, this is a proxy for 'root directory' of a project

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-21 20:59:08 -07:00

13 lines
506 B
HTML

{{ $scratch := .scratch }}
{{ $scratch.Set "bestLength" -1 }}
{{ $scratch.Set "bestUrl" (printf "%s/code/%s" .siteSourceUrl .path) }}
{{ $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 }}