2024-06-09 18:14:53 -07:00
|
|
|
{{- $siteSourceUrl := site.Params.siteSourceUrl -}}
|
2026-05-18 21:05:45 -07:00
|
|
|
{{- $submoduleLinks := hugo.Data.submodules -}}
|
|
|
|
|
{{- $hostData := hugo.Data.hosts -}}
|
2024-06-09 18:50:00 -07:00
|
|
|
{{- $lines := .lines -}}
|
2026-05-18 21:15:19 -07:00
|
|
|
{{- $bestLength := -1 -}}
|
|
|
|
|
{{- $bestUrl := printf "%s/code/%s" $siteSourceUrl .path -}}
|
|
|
|
|
{{- $bestPath := "" -}}
|
2024-05-21 21:42:35 -07:00
|
|
|
{{- $filePath := .path -}}
|
2024-06-09 18:14:53 -07:00
|
|
|
{{- range $path, $url := $submoduleLinks -}}
|
2024-06-09 18:50:00 -07:00
|
|
|
{{- if and (le $bestLength (len $path)) (hasPrefix $filePath $path) -}}
|
2026-05-18 21:15:19 -07:00
|
|
|
{{- $bestLength = len $path -}}
|
|
|
|
|
{{- $bestPath = $path -}}
|
|
|
|
|
{{- $bestUrl = printf "%s%s" $url (strings.TrimPrefix $path $filePath) -}}
|
2024-06-09 18:50:00 -07:00
|
|
|
{{- end -}}
|
2024-05-21 21:42:35 -07:00
|
|
|
{{- end -}}
|
2024-06-09 18:50:00 -07:00
|
|
|
{{- if .lines -}}
|
|
|
|
|
{{- /* If the user provided a line range, see if we can tack it on to the end of the link. */ -}}
|
|
|
|
|
{{- range $host, $data := $hostData -}}
|
2026-05-18 21:15:19 -07:00
|
|
|
{{- if hasPrefix $bestUrl $host -}}
|
2024-06-09 18:50:00 -07:00
|
|
|
{{- with $data.linesSuffix -}}
|
2026-05-18 21:15:19 -07:00
|
|
|
{{- $bestUrl = add $bestUrl (printf . (index $lines 0) (index $lines 1)) -}}
|
2024-06-09 18:50:00 -07:00
|
|
|
{{- end -}}
|
|
|
|
|
{{- end -}}
|
|
|
|
|
{{- end -}}
|
2024-05-21 21:42:35 -07:00
|
|
|
{{- end -}}
|
2026-05-18 21:15:19 -07:00
|
|
|
{{- return (dict "url" $bestUrl "basePath" $bestPath) -}}
|