Use Hugo's partial-returning where possible

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
2026-05-18 21:15:19 -07:00
parent 2032e1cdc2
commit 19550ef1b2
12 changed files with 46 additions and 55 deletions

View File

@@ -1,8 +1,7 @@
{{- $scratch := newScratch -}}
{{- partial "geturl.html" (dict "scratch" $scratch "path" (.Get 1)) -}}
{{- $url := partial "geturl.html" (dict "path" (.Get 1)) -}}
{{- $groupconfig := dict
"url" ($scratch.Get "bestUrl")
"basePath" ($scratch.Get "bestPath")
"url" $url.url
"basePath" $url.basePath
"path" (.Get 1)
"comment" ", entire file"
"code" (readFile (printf "code/%s" (.Get 1)))

View File

@@ -35,17 +35,17 @@
{{- $joinedLines = delimit $lines "\n" -}}
{{- end -}}
{{- partial "geturl.html" (dict "scratch" $scratch "path" (.Get 1) "lines" (slice (.Get 2) (.Get 3))) -}}
{{- partial "linerangestr.html" (dict "scratch" $scratch "from" (.Get 2) "to" (.Get 3)) -}}
{{- $url := partial "geturl.html" (dict "path" (.Get 1) "lines" (slice (.Get 2) (.Get 3))) -}}
{{- $comment := partial "linerangestr.html" (dict "from" (.Get 2) "to" (.Get 3)) -}}
{{- with ($scratch.Get "hidden") -}}
<details><summary>{{- . | markdownify -}}</summary>
{{- end -}}
{{- $groupconfig := dict
"url" ($scratch.Get "bestUrl")
"basePath" ($scratch.Get "bestPath")
"url" $url.url
"basePath" $url.basePath
"path" (.Get 1)
"comment" ($scratch.Get "comment")
"comment" $comment
"code" $joinedLines
"firstLine" (int (.Get 2))
"lastLine" (int (.Get 3))

View File

@@ -1,3 +1,2 @@
{{- $scratch := newScratch -}}
{{- partial "geturl.html" (dict "scratch" $scratch "path" (.Get 0)) -}}
{{- $scratch.Get "bestUrl" -}}
{{- $url := partial "geturl.html" (dict "path" (.Get 0)) -}}
{{- $url.url -}}

View File

@@ -5,7 +5,6 @@
{{- $line := .Get 4 -}}
{{- $lines := split (trim .Inner "\n") "\n" -}}
{{- $scratch := newScratch -}}
{{- $url := printf "https://github.com/%s/blob/%s/%s#L%d" $repo $commit $file $line -}}
{{- partial "linerangestr.html" (dict "scratch" $scratch "from" 0 "to" $line) -}}
{{- partial "highlightgroup.html" (dict "url" $url "path" $file "comment" ($scratch.Get "comment") "code" (trim .Inner "\n") "language" $lang) -}}
{{- $comment := partial "linerangestr.html" (dict "from" 0 "to" $line) -}}
{{- partial "highlightgroup.html" (dict "url" $url "path" $file "comment" $comment "code" (trim .Inner "\n") "language" $lang) -}}

View File

@@ -1,8 +1,7 @@
{{- $scratch := newScratch -}}
{{- partial "geturl.html" (dict "scratch" $scratch "path" (.Get 0) "siteSourceUrl" .Site.Params.siteSourceUrl "submoduleLinks" hugo.Data.submodules) -}}
{{- $url := partial "geturl.html" (dict "path" (.Get 0)) -}}
{{- $groupconfig := dict
"url" ($scratch.Get "bestUrl")
"basePath" ($scratch.Get "bestPath")
"url" $url.url
"basePath" $url.basePath
"path" (.Get 0)
"comment" ", entire file"
"content" (safeHTML (printf "<pre><code>%s</code></pre>" (htmlEscape (readFile (printf "code/%s" (.Get 0))))))