From ec7b58c8ece30b3994a7d0884344dd1e3dd37ed3 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sun, 9 Jun 2024 18:14:53 -0700 Subject: [PATCH] Avoid passing in .Site-variables to geturl.html Signed-off-by: Danila Fedorin --- layouts/partials/geturl.html | 6 ++++-- layouts/shortcodes/codeblock.html | 2 +- layouts/shortcodes/codelines.html | 2 +- layouts/shortcodes/codeurl.html | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/layouts/partials/geturl.html b/layouts/partials/geturl.html index 393aa10..75cb30e 100644 --- a/layouts/partials/geturl.html +++ b/layouts/partials/geturl.html @@ -1,9 +1,11 @@ +{{- $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 "bestUrl" (printf "%s/code/%s" $siteSourceUrl .path) -}} {{- $scratch.Set "bestPath" "" -}} {{- $filePath := .path -}} -{{- range $path, $url := .submoduleLinks -}} +{{- range $path, $url := $submoduleLinks -}} {{- $bestLength := $scratch.Get "bestLength" -}} {{- if and (le $bestLength (len $path)) (hasPrefix $filePath $path) -}} {{- $scratch.Set "bestLength" (len $path) -}} diff --git a/layouts/shortcodes/codeblock.html b/layouts/shortcodes/codeblock.html index 6261a6b..9f0ae45 100644 --- a/layouts/shortcodes/codeblock.html +++ b/layouts/shortcodes/codeblock.html @@ -1,4 +1,4 @@ -{{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 1) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" .Site.Data.submodules) }} +{{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 1)) }} {{- $groupconfig := dict "url" (.Scratch.Get "bestUrl") "basePath" (.Scratch.Get "bestPath") diff --git a/layouts/shortcodes/codelines.html b/layouts/shortcodes/codelines.html index e71ad42..7a032e2 100644 --- a/layouts/shortcodes/codelines.html +++ b/layouts/shortcodes/codelines.html @@ -17,7 +17,7 @@ {{- .Scratch.Set "hidden" (.Get 5) -}} {{- end -}} -{{- partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 1) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" .Site.Data.submodules) -}} +{{- partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 1)) -}} {{- partial "linerangestr.html" (dict "scratch" .Scratch "from" (.Get 2) "to" (.Get 3)) -}} {{- with (.Scratch.Get "hidden") -}} diff --git a/layouts/shortcodes/codeurl.html b/layouts/shortcodes/codeurl.html index 43e7c8f..6854324 100644 --- a/layouts/shortcodes/codeurl.html +++ b/layouts/shortcodes/codeurl.html @@ -1,2 +1,2 @@ -{{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 0) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" .Site.Data.submodules) }} +{{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 0)) }} {{- .Scratch.Get "bestUrl" -}}