From b1334455ea40e31cc451bc7b63b8b20c20b6f4b8 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 21 May 2024 20:59:08 -0700 Subject: [PATCH] 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 --- layouts/partials/geturl.html | 1 + layouts/shortcodes/codeblock.html | 1 + layouts/shortcodes/codelines.html | 1 + layouts/shortcodes/rawblock.html | 9 ++++++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/layouts/partials/geturl.html b/layouts/partials/geturl.html index fa5e9ff..f501ae9 100644 --- a/layouts/partials/geturl.html +++ b/layouts/partials/geturl.html @@ -6,6 +6,7 @@ {{ $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 }} diff --git a/layouts/shortcodes/codeblock.html b/layouts/shortcodes/codeblock.html index 722b746..2055f0f 100644 --- a/layouts/shortcodes/codeblock.html +++ b/layouts/shortcodes/codeblock.html @@ -1,6 +1,7 @@ {{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 1) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" .Site.Data.submodules) }} {{ $groupconfig := dict "url" (.Scratch.Get "bestUrl") + "basePath" (.Scratch.Get "bestPath") "path" (.Get 1) "comment" ", entire file" "code" (readFile (printf "code/%s" (.Get 1))) diff --git a/layouts/shortcodes/codelines.html b/layouts/shortcodes/codelines.html index 76e27e1..d500d27 100644 --- a/layouts/shortcodes/codelines.html +++ b/layouts/shortcodes/codelines.html @@ -25,6 +25,7 @@ {{ end }} {{ $groupconfig := dict "url" (.Scratch.Get "bestUrl") + "basePath" (.Scratch.Get "bestPath") "path" (.Get 1) "comment" (.Scratch.Get "comment") "code" (delimit $lines "\n") diff --git a/layouts/shortcodes/rawblock.html b/layouts/shortcodes/rawblock.html index b05d97e..18d810f 100644 --- a/layouts/shortcodes/rawblock.html +++ b/layouts/shortcodes/rawblock.html @@ -1,2 +1,9 @@ {{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 0) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" .Site.Data.submodules) }} -{{ partial "group.html" (dict "url" (.Scratch.Get "bestUrl") "path" (.Get 0) "comment" ", entire file" "content" (safeHTML (printf "
%s
" (htmlEscape (readFile (printf "code/%s" (.Get 0))))))) }} +{{ $groupconfig := dict + "url" (.Scratch.Get "bestUrl") + "basePath" (.Scratch.Get "bestPath") + "path" (.Get 0) + "comment" ", entire file" + "content" (safeHTML (printf "
%s
" (htmlEscape (readFile (printf "code/%s" (.Get 0)))))) +}} +{{ partial "group.html" $groupconfig }}