From fe7eb1d4320d95e7840d0fb18ed8f35207f3da9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 12 Sep 2021 09:44:34 +0200 Subject: [PATCH] theme: wildspace in shortcodes and shortcode output --- layouts/shortcodes/attachments.html | 47 ++++---- layouts/shortcodes/button.html | 22 ++-- layouts/shortcodes/children.html | 170 ++++++++++++++-------------- layouts/shortcodes/expand.html | 8 +- layouts/shortcodes/include.html | 6 +- layouts/shortcodes/mermaid.html | 6 +- layouts/shortcodes/notice.html | 10 +- layouts/shortcodes/tab.html | 1 - layouts/shortcodes/tabs.html | 36 +++--- 9 files changed, 153 insertions(+), 153 deletions(-) diff --git a/layouts/shortcodes/attachments.html b/layouts/shortcodes/attachments.html index 108dcda659..b2311bb3ca 100644 --- a/layouts/shortcodes/attachments.html +++ b/layouts/shortcodes/attachments.html @@ -5,33 +5,32 @@
{{ $title }}
- {{- $filesName := "files" }} - {{- if ne .Page.File.BaseFileName "index" }} - {{- $filesName = printf "%s.files" .Page.File.BaseFileName }} - {{- end}} + {{- $filesName := "files" }} + {{- if ne .Page.File.BaseFileName "index" }} + {{- $filesName = printf "%s.files" .Page.File.BaseFileName }} + {{- end}} - {{- $fileDir := replace .Page.File.Dir "\\" "/" }} - {{- $pattern := .Get "pattern" | default "" }} - {{- range sort (readDir (printf "content/%s%s" .Page.File.Dir $filesName) ) "Name" $sort }} - {{- if findRE $pattern .Name}} - {{- $size := .Size }} - {{- $unit := "Byte-symbol" }} - {{- if ge $size 1024 }} - {{- $size = div $size 1024 }} - {{- $unit = "Kilobyte-symbol" }} - {{- end }} - {{- if ge $size 1024 }} - {{- $size = div $size 1024 }} - {{- $unit = "Megabyte-symbol" }} - {{- end }} - {{- $unitsymbol := $unit | T }} - -
  • - {{.Name}} - ({{$size}} {{$unitsymbol}}) -
  • + {{- $fileDir := replace .Page.File.Dir "\\" "/" }} + {{- $pattern := .Get "pattern" | default "" }} + {{- range sort (readDir (printf "content/%s%s" .Page.File.Dir $filesName) ) "Name" $sort }} + {{- if findRE $pattern .Name}} + {{- $size := .Size }} + {{- $unit := "Byte-symbol" }} + {{- if ge $size 1024 }} + {{- $size = div $size 1024 }} + {{- $unit = "Kilobyte-symbol" }} {{- end }} + {{- if ge $size 1024 }} + {{- $size = div $size 1024 }} + {{- $unit = "Megabyte-symbol" }} + {{- end }} + {{- $unitsymbol := $unit | T }} +
  • + {{.Name}} + ({{$size}} {{$unitsymbol}}) +
  • {{- end }} + {{- end }}
    {{- .Inner }}
    diff --git a/layouts/shortcodes/button.html b/layouts/shortcodes/button.html index 7cfc389486..05147986c9 100644 --- a/layouts/shortcodes/button.html +++ b/layouts/shortcodes/button.html @@ -1,14 +1,14 @@ -{{ $_hugo_config := `{ "version": 1 }` }} - - {{ $icon := .Get "icon" }} - {{ $iconposition := .Get "icon-position" }} - {{ if ($icon) }} - {{ if or (not ($iconposition)) (eq $iconposition "left") }} - - {{ end }} - {{ end }} +{{- $_hugo_config := `{ "version": 1 }` }} + + {{- $icon := .Get "icon" }} + {{- $iconposition := .Get "icon-position" }} + {{- if ($icon) }} + {{- if or (not ($iconposition)) (eq $iconposition "left") }} + + {{- end }} + {{- end }} {{ .Inner }} - {{ if and ($icon) (eq $iconposition "right")}} + {{- if and ($icon) (eq $iconposition "right")}} - {{ end }} + {{- end }} diff --git a/layouts/shortcodes/children.html b/layouts/shortcodes/children.html index b551931387..eb5e6b01b1 100644 --- a/layouts/shortcodes/children.html +++ b/layouts/shortcodes/children.html @@ -1,100 +1,100 @@ -{{ $_hugo_config := `{ "version": 1 }` }} -{{ $showhidden := .Get "showhidden"}} -{{ $style := .Get "style" | default "li" }} -{{ $depth := .Get "depth" | default 1 }} -{{ $withDescription := .Get "description" | default false }} -{{ $sortTerm := .Get "sort" | default (.Site.Params.ordersectionsby | default "weight") | lower }} -{{ $containerstyle := .Get "containerstyle" | default "ul" }} +{{- $_hugo_config := `{ "version": 1 }` }} +{{- $showhidden := .Get "showhidden"}} +{{- $style := .Get "style" | default "li" }} +{{- $depth := .Get "depth" | default 1 }} +{{- $withDescription := .Get "description" | default false }} +{{- $sortTerm := .Get "sort" | default (.Site.Params.ordersectionsby | default "weight") | lower }} +{{- $containerstyle := .Get "containerstyle" | default "ul" }} -{{(printf "<%s class=\"children children-%s children-sort-%s\">" $containerstyle $style $sortTerm)|safeHTML}} - {{ .Scratch.Set "pages" .Page.Pages }} +{{ (printf "<%s class=\"children children-%s children-sort-%s\">" $containerstyle $style $sortTerm)|safeHTML }} + {{- .Scratch.Set "pages" .Page.Pages }} - {{if .Page.IsHome}} + {{- if .Page.IsHome }} - {{ $rootPage := where .Page.Pages "Dir" "" }} - {{ .Scratch.Set "pages" (.Page.Sections | union $rootPage)}} - {{else}} - {{ if .Page.Sections}} - {{ .Scratch.Set "pages" (.Page.Pages | union .Page.Sections) }} - {{end}} - {{end}} + {{- $rootPage := where .Page.Pages "Dir" "" }} + {{- .Scratch.Set "pages" (.Page.Sections | union $rootPage)}} + {{- else }} + {{- if .Page.Sections}} + {{- .Scratch.Set "pages" (.Page.Pages | union .Page.Sections) }} + {{- end }} + {{- end }} - {{ $pages := (.Scratch.Get "pages") }} + {{- $pages := (.Scratch.Get "pages") }} - {{if eq $sortTerm "weight"}} - {{template "childs" dict "menu" $pages.ByWeight "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}} - {{else if or (eq $sortTerm "name") (eq $sortTerm "title")}} - {{template "childs" dict "menu" $pages.ByTitle "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}} - {{else if eq $sortTerm "publishdate"}} - {{template "childs" dict "menu" $pages.ByPublishDate "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}} - {{else if eq $sortTerm "date"}} - {{template "childs" dict "menu" $pages.ByDate "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}} - {{else if eq $sortTerm "length"}} - {{template "childs" dict "menu" $pages.ByLength "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}} - {{else}} - {{template "childs" dict "menu" $pages "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}} - {{end}} -{{(printf "" $containerstyle)|safeHTML}} + {{- if eq $sortTerm "weight" }} + {{- template "childs" dict "menu" $pages.ByWeight "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }} + {{- else if or (eq $sortTerm "name") (eq $sortTerm "title") }} + {{- template "childs" dict "menu" $pages.ByTitle "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }} + {{- else if eq $sortTerm "publishdate" }} + {{- template "childs" dict "menu" $pages.ByPublishDate "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }} + {{- else if eq $sortTerm "date" }} + {{- template "childs" dict "menu" $pages.ByDate "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }} + {{- else if eq $sortTerm "length" }} + {{- template "childs" dict "menu" $pages.ByLength "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }} + {{- else }} + {{- template "childs" dict "menu" $pages "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }} + {{- end }} +{{ (printf "" $containerstyle)|safeHTML }} -{{ define "childs" }} - {{ range .menu }} - {{ $hidden := and (or (.Params.hidden) (eq .Title "")) (not $.showhidden) }} - {{ if not $hidden }} - {{if not .IsHome}} - {{if hasPrefix $.style "h"}} - {{$num := sub ( int (trim $.style "h") ) 1 }} - {{$numn := add $num $.count }} +{{- define "childs" }} + {{- range .menu }} + {{- $hidden := and (or (.Params.hidden) (eq .Title "")) (not $.showhidden) }} + {{- if not $hidden }} + {{- if not .IsHome }} + {{- if hasPrefix $.style "h" }} + {{- $num := sub ( int (trim $.style "h") ) 1 }} + {{- $numn := add $num $.count }} -{{(printf "" $numn)|safeHTML}} -{{ .Title }} -{{(printf "" $numn)|safeHTML}} +{{ (printf "" $numn)|safeHTML -}} +{{ .Title }} +{{- (printf "" $numn)|safeHTML }} - {{else}} -{{(printf "<%s>" $.style)|safeHTML}} -{{ .Title }} -{{(printf "" $.style)|safeHTML}} - {{end}} + {{- else }} +{{ (printf "<%s>" $.style)|safeHTML -}} +{{ .Title }} +{{- (printf "" $.style)|safeHTML }} + {{- end }} - {{if $.description}} - {{if .Description}} -

    {{.Description}}

    + {{- if $.description }} + {{- if .Description }} +

    {{ .Description }}

    {{else}} -

    {{.Summary}}

    - {{end}} - {{end}} - {{end}} - {{ if lt $.count $.depth}} +

    {{ .Summary }}

    + {{- end }} + {{- end }} + {{- end }} + {{- if lt $.count $.depth }} - {{if eq $.style "li"}} -{{(printf "<%s>" $.containerstyle)|safeHTML}} - {{end}} + {{- if eq $.style "li" }} +{{- (printf "<%s>" $.containerstyle)|safeHTML }} + {{- end }} - {{ if .Sections}} - {{ .Scratch.Set "pages" (.Pages | union .Sections) }} - {{else}} - {{ .Scratch.Set "pages" .Pages }} - {{end}} + {{- if .Sections }} + {{- .Scratch.Set "pages" (.Pages | union .Sections) }} + {{- else }} + {{- .Scratch.Set "pages" .Pages }} + {{- end }} - {{ $pages := (.Scratch.Get "pages") }} + {{- $pages := (.Scratch.Get "pages") }} - {{if eq $.sortTerm "weight"}} - {{template "childs" dict "menu" $pages.ByWeight "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}} - {{else if or (eq $.sortTerm "name") (eq $.sortTerm "title")}} - {{template "childs" dict "menu" $pages.ByTitle "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}} - {{else if eq $.sortTerm "publishdate"}} - {{template "childs" dict "menu" $pages.ByPublishDate "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}} - {{else if eq $.sortTerm "date"}} - {{template "childs" dict "menu" $pages.ByDate "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}} - {{else if eq $.sortTerm "length"}} - {{template "childs" dict "menu" $pages.ByLength "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}} - {{else}} - {{template "childs" dict "menu" $pages "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}} - {{end}} + {{- if eq $.sortTerm "weight" }} + {{- template "childs" dict "menu" $pages.ByWeight "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }} + {{- else if or (eq $.sortTerm "name") (eq $.sortTerm "title") }} + {{- template "childs" dict "menu" $pages.ByTitle "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }} + {{- else if eq $.sortTerm "publishdate" }} + {{- template "childs" dict "menu" $pages.ByPublishDate "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }} + {{- else if eq $.sortTerm "date" }} + {{- template "childs" dict "menu" $pages.ByDate "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }} + {{- else if eq $.sortTerm "length" }} + {{- template "childs" dict "menu" $pages.ByLength "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }} + {{- else }} + {{- template "childs" dict "menu" $pages "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }} + {{- end }} - {{if eq $.style "li"}} -{{(printf "" $.containerstyle)|safeHTML}} - {{end}} - {{end}} - {{end}} - {{end}} -{{end}} \ No newline at end of file + {{- if eq $.style "li" }} +{{- (printf "" $.containerstyle)|safeHTML }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/layouts/shortcodes/expand.html b/layouts/shortcodes/expand.html index cb792c4a22..4de845a773 100644 --- a/layouts/shortcodes/expand.html +++ b/layouts/shortcodes/expand.html @@ -1,7 +1,7 @@ -{{ $_hugo_config := `{ "version": 1 }` }} -{{ $title := .Get 0 | default (T "Expand-title") }} -{{ $content := .Inner | safeHTML }} -{{ $expanded := eq (.Get 1) "true" }} +{{- $_hugo_config := `{ "version": 1 }` }} +{{- $title := .Get 0 | default (T "Expand-title") }} +{{- $content := .Inner | safeHTML }} +{{- $expanded := eq (.Get 1) "true" }}
    diff --git a/layouts/shortcodes/include.html b/layouts/shortcodes/include.html index bade73f36e..50d06263c3 100644 --- a/layouts/shortcodes/include.html +++ b/layouts/shortcodes/include.html @@ -1,6 +1,6 @@ -{{ $file := .Get 0 }} -{{ $showFirstHeading := .Get 1 | default true }} -
    +{{- $file := .Get 0 }} +{{- $showFirstHeading := .Get 1 | default true }} +
    {{ $file | readFile | safeHTML }}
    diff --git a/layouts/shortcodes/mermaid.html b/layouts/shortcodes/mermaid.html index 287bc380c1..a3e99e1a14 100644 --- a/layouts/shortcodes/mermaid.html +++ b/layouts/shortcodes/mermaid.html @@ -1,2 +1,4 @@ -{{ $_hugo_config := `{ "version": 1 }` }} -
    {{ safeHTML .Inner }}
    +{{- $_hugo_config := `{ "version": 1 }` }} +
    + {{- safeHTML .Inner -}} +
    diff --git a/layouts/shortcodes/notice.html b/layouts/shortcodes/notice.html index a20ae2dcc8..b5783a7b66 100644 --- a/layouts/shortcodes/notice.html +++ b/layouts/shortcodes/notice.html @@ -1,7 +1,7 @@ -{{ $_hugo_config := `{ "version": 1 }` }} -{{ $style := .Get 0 }} -{{ $title := $style | T }} +{{- $_hugo_config := `{ "version": 1 }` }} +{{- $style := .Get 0 }} +{{- $title := $style | T }}
    {{ $title }}
    - {{ .Inner }} -
    + {{- .Inner }} +
    \ No newline at end of file diff --git a/layouts/shortcodes/tab.html b/layouts/shortcodes/tab.html index 0afa1ae17d..661af3615c 100644 --- a/layouts/shortcodes/tab.html +++ b/layouts/shortcodes/tab.html @@ -9,4 +9,3 @@ {{ else }} {{- errorf "[%s] %q: tab shortcode missing its parent" site.Language.Lang .Page.Path -}} {{ end}} - diff --git a/layouts/shortcodes/tabs.html b/layouts/shortcodes/tabs.html index 163d12f95d..e39cd20938 100644 --- a/layouts/shortcodes/tabs.html +++ b/layouts/shortcodes/tabs.html @@ -1,21 +1,21 @@ -{{ with .Inner }}{{/* don't do anything, just call it */}}{{ end }} -{{ $groupId := default "default" (.Get "groupId") }} +{{- with .Inner }}{{/* don't do anything, just call it */}}{{ end }} +{{- $groupId := default "default" (.Get "groupId") }}
    -
    - {{ range $idx, $tab := .Scratch.Get "tabs" }} - - {{ end }} -
    -
    - {{ range $idx, $tab := .Scratch.Get "tabs" }} -
    - {{ .content }} -
    - {{ end }} +
    + {{- range $idx, $tab := .Scratch.Get "tabs" }} + + {{- end }} +
    +
    + {{- range $idx, $tab := .Scratch.Get "tabs" }} +
    +{{ .content }}
    + {{- end }} +