Reduce whitespace in templates and avoid polluting the page scratch

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
Danila Fedorin 2024-06-09 18:36:54 -07:00
parent ec7b58c8ec
commit 4b19da5006
12 changed files with 57 additions and 51 deletions

View File

@ -1,8 +1,9 @@
{{- page.Scratch.Set "highlightGroupAttrs" (printf "data-base-path=\"%s\" data-file-path=\"%v\"" .basePath .path) -}}
{{- $scratch := newScratch -}}
{{- $scratch.Set "highlightGroupAttrs" (printf "data-base-path=\"%s\" data-file-path=\"%v\"" .basePath .path) -}}
{{- if (or .firstLine .lastLine) -}}
{{- page.Scratch.Add "highlightGroupAttrs" (printf " data-first-line=\"%v\" data-last-line=\"%v\"" .firstLine .lastLine) -}}
{{- $scratch.Add "highlightGroupAttrs" (printf " data-first-line=\"%v\" data-last-line=\"%v\"" .firstLine .lastLine) -}}
{{- end -}}
{{- if eq (lower .language) "agda" -}}
{{- page.Scratch.Add "highlightGroupAttrs" " data-agda-block" -}}
{{- $scratch.Add "highlightGroupAttrs" " data-agda-block" -}}
{{- end -}}
{{ partial "group.html" (dict "url" .url "path" .path "comment" .comment "content" (highlight .code .language .opts) "attrs" (page.Scratch.Get "highlightGroupAttrs")) }}
{{ partial "group.html" (dict "url" .url "path" .path "comment" .comment "content" (highlight .code .language .opts) "attrs" ($scratch.Get "highlightGroupAttrs")) }}

View File

@ -1,3 +1,3 @@
<div class="block">
{{ .Inner }}
{{- .Inner -}}
</div>

View File

@ -1,11 +1,12 @@
{{ partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 1)) }}
{{- $scratch := newScratch -}}
{{- partial "geturl.html" (dict "scratch" $scratch "path" (.Get 1)) -}}
{{- $groupconfig := dict
"url" (.Scratch.Get "bestUrl")
"basePath" (.Scratch.Get "bestPath")
"url" ($scratch.Get "bestUrl")
"basePath" ($scratch.Get "bestPath")
"path" (.Get 1)
"comment" ", entire file"
"code" (readFile (printf "code/%s" (.Get 1)))
"language" (.Get 0)
"opts" "linenos=table"
-}}
{{ partial "highlightgroup.html" $groupconfig }}
{{- partial "highlightgroup.html" $groupconfig -}}

View File

@ -1,40 +1,41 @@
{{- $source := (readFile (printf "code/%s" (.Get 1))) -}}
{{- $allLines := split $source "\n" -}}
{{- $scratch := newScratch -}}
{{- if not (eq (int (.Get 2)) 1) -}}
{{- .Scratch.Set "remLines" (after (sub (int (.Get 2)) 1) $allLines) -}}
{{- $scratch.Set "remLines" (after (sub (int (.Get 2)) 1) $allLines) -}}
{{- else -}}
{{- .Scratch.Set "remLines" $allLines -}}
{{- $scratch.Set "remLines" $allLines -}}
{{- end -}}
{{- $lines := first (add (sub (int (.Get 3)) (int (.Get 2))) 1) (.Scratch.Get "remLines") -}}
{{- $lines := first (add (sub (int (.Get 3)) (int (.Get 2))) 1) ($scratch.Get "remLines") -}}
{{- if (.Get 4) -}}
{{- .Scratch.Set "opts" (printf ",%s" (.Get 4)) -}}
{{- $scratch.Set "opts" (printf ",%s" (.Get 4)) -}}
{{- else -}}
{{- .Scratch.Set "opts" "" -}}
{{- $scratch.Set "opts" "" -}}
{{- end -}}
{{- if (.Get 5) -}}
{{- .Scratch.Set "hidden" (.Get 5) -}}
{{- $scratch.Set "hidden" (.Get 5) -}}
{{- end -}}
{{- partial "geturl.html" (dict "scratch" .Scratch "path" (.Get 1)) -}}
{{- partial "linerangestr.html" (dict "scratch" .Scratch "from" (.Get 2) "to" (.Get 3)) -}}
{{- 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") -}}
<details><summary>{{ . | markdownify }}</summary>
{{- with ($scratch.Get "hidden") -}}
<details><summary>{{- . | markdownify -}}</summary>
{{- end -}}
{{- $groupconfig := dict
"url" (.Scratch.Get "bestUrl")
"basePath" (.Scratch.Get "bestPath")
"url" ($scratch.Get "bestUrl")
"basePath" ($scratch.Get "bestPath")
"path" (.Get 1)
"comment" (.Scratch.Get "comment")
"comment" ($scratch.Get "comment")
"code" (delimit $lines "\n")
"firstLine" (int (.Get 2))
"lastLine" (int (.Get 3))
"language" (.Get 0)
"opts" (printf "linenos=table,linenostart=%d%s" (.Get 2) (.Scratch.Get "opts"))
"opts" (printf "linenos=table,linenostart=%d%s" (.Get 2) ($scratch.Get "opts"))
-}}
{{- partial "highlightgroup.html" $groupconfig -}}
{{- with (.Scratch.Get "hidden") -}}
{{- with ($scratch.Get "hidden") -}}
</details>
{{- end -}}

View File

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

View File

@ -1,4 +1,4 @@
<details>
<summary>{{ .Get "summary" | markdownify }}</summary>
{{ .Inner | markdownify }}
<summary>{{- .Get "summary" | markdownify -}}</summary>
{{- .Inner | markdownify -}}
</details>

View File

@ -1,3 +1,3 @@
<p class="dialog">
{{ .Inner }}
{{- .Inner -}}
</p>

View File

@ -5,6 +5,7 @@
{{- $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) -}}
{{- 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) -}}

View File

@ -1,10 +1,10 @@
<span class="message side-{{ .Get 0 }}">
<span class="message-sender">
{{ if (eq (.Get 1) "reader") }}
{{ partial "icon.html" "moon" }}
{{ else }}
{{ partial "icon.html" "sun" }}
{{ end }}
{{- if (eq (.Get 1) "reader") -}}
{{- partial "icon.html" "moon" -}}
{{- else -}}
{{- partial "icon.html" "sun" -}}
{{- end -}}
</span>
<span class="message-text">{{ .Inner }}</span>
<span class="message-text">{{- .Inner -}}</span>
</span>

View File

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

View File

@ -1,13 +1,13 @@
<span class="sidenote">
<label class="sidenote-label" for="{{ .Get 1 }}">{{ .Get 2 }}</label>
<input class="sidenote-checkbox" type="checkbox" id="{{ .Get 1 }}"></input>
{{ if $offset := .Get 3 }}
<span class="sidenote-content sidenote-{{ .Get 0 }}" style="margin-top: {{ $offset }}rem">
{{ else }}
<span class="sidenote-content sidenote-{{ .Get 0 }}">
{{ end }}
<span class="sidenote-delimiter">[{{ i18n "note" }}:</span>
{{ .Inner }}
<label class="sidenote-label" for="{{- .Get 1 -}}">{{- .Get 2 -}}</label>
<input class="sidenote-checkbox" type="checkbox" id="{{- .Get 1 -}}"></input>
{{- if $offset := .Get 3 -}}
<span class="sidenote-content sidenote-{{- .Get 0 -}}" style="margin-top: {{- $offset -}}rem">
{{- else -}}
<span class="sidenote-content sidenote-{{- .Get 0 -}}">
{{- end -}}
<span class="sidenote-delimiter">[{{- i18n "note" -}}:</span>
{{- .Inner -}}
<span class="sidenote-delimiter">]</span>
</span>
</span>

View File

@ -1,3 +1,3 @@
<div style="background-color: tomato; color: white; padding: 10px;">
<em>TODO: </em>{{ .Inner }}
<em>TODO: </em>{{- .Inner -}}
</div>