diff --git a/themes/vanilla/layouts/shortcodes/codelines.html b/themes/vanilla/layouts/shortcodes/codelines.html index 8e16d5c..a09bbe9 100644 --- a/themes/vanilla/layouts/shortcodes/codelines.html +++ b/themes/vanilla/layouts/shortcodes/codelines.html @@ -1,18 +1,32 @@ -{{ $s := (readFile (printf "code/%s" (.Get 1))) }} -{{ $t := split $s "\n" }} +{{ $source := (readFile (printf "code/%s" (.Get 1))) }} +{{ $allLines := split $source "\n" }} {{ if not (eq (int (.Get 2)) 1) }} -{{ .Scratch.Set "u" (after (sub (int (.Get 2)) 1) $t) }} +{{ .Scratch.Set "remLines" (after (sub (int (.Get 2)) 1) $allLines) }} {{ else }} -{{ .Scratch.Set "u" $t }} +{{ .Scratch.Set "remLines" $allLines }} {{ end }} -{{ $v := first (add (sub (int (.Get 3)) (int (.Get 2))) 1) (.Scratch.Get "u") }} +{{ $lines := first (add (sub (int (.Get 3)) (int (.Get 2))) 1) (.Scratch.Get "remLines") }} + {{ if (.Get 4) }} {{ .Scratch.Set "opts" (printf ",%s" (.Get 4)) }} {{ else }} {{ .Scratch.Set "opts" "" }} {{ end }} + +{{ .Scratch.Set "bestLength" -1 }} +{{ .Scratch.Set "bestUrl" (printf "https://dev.danilafe.com/Web-Projects/blog-static/src/branch/master/code/%s" (.Get 1)) }} +{{ $filePath := (.Get 1) }} +{{ $scratch := .Scratch }} +{{ range $module, $props := .Site.Params.submoduleLinks }} +{{ $path := index $props "path" }} +{{ $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)) }} +{{ end }} +{{ end }}