shortcode: make .context always a page #527

This commit is contained in:
Sören Weber 2023-05-18 14:01:50 +02:00
parent dc695da6a1
commit 77f41e9607
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
24 changed files with 40 additions and 40 deletions

View file

@ -3,12 +3,12 @@
{{- $pagefield := cond (ne $content nil) nil (.pagefield | default "Content") }} {{- $pagefield := cond (ne $content nil) nil (.pagefield | default "Content") }}
{{- $writenotice := cond (ne .writenotice nil) .writenotice false }} {{- $writenotice := cond (ne .writenotice nil) .writenotice false }}
{{- $langtrg := "pir" }} {{- $langtrg := "pir" }}
{{- $langsrc := cond (eq $context.Page.Lang $langtrg) (.langsrc | default "en") $context.Page.Lang }} {{- $langsrc := cond (eq $context.Lang $langtrg) (.langsrc | default "en") $context.Lang }}
{{- $baseURL := urls.Parse site.BaseURL }} {{- $baseURL := urls.Parse site.BaseURL }}
{{- $baseURLpath := $baseURL.Path | default "/" }} {{- $baseURLpath := $baseURL.Path | default "/" }}
{{- $l := "" }} {{- $l := "" }}
{{- $c := "" }} {{- $c := "" }}
{{- range $context.Page.AllTranslations }} {{- range $context.AllTranslations }}
{{- if eq .Language.Lang $langsrc }} {{- if eq .Language.Lang $langsrc }}
{{- $l = .RelPermalink }} {{- $l = .RelPermalink }}
{{- if ne $content nil }} {{- if ne $content nil }}
@ -21,10 +21,10 @@
{{- break }} {{- break }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- if eq $context.Page.Lang $langtrg }} {{- if eq $context.Lang $langtrg }}
{{- if $writenotice }} {{- if $writenotice }}
{{- partial "shortcodes/notice.html" (dict {{- partial "shortcodes/notice.html" (dict
"context" . "context" $context
"content" "<p>Fello' pirrrates, grog made us dizzy! Be awarrre <b>some stuff may not work</b> in this trrranslat'n. Like see'n <b>Merrrmaids</b>, do'n <b>math or chemistrrry</b>, writ'n docs and stuff.</p>\n" "content" "<p>Fello' pirrrates, grog made us dizzy! Be awarrre <b>some stuff may not work</b> in this trrranslat'n. Like see'n <b>Merrrmaids</b>, do'n <b>math or chemistrrry</b>, writ'n docs and stuff.</p>\n"
"icon" "skull-crossbones" "icon" "skull-crossbones"
"style" "warning" "style" "warning"

View file

@ -1,5 +1,5 @@
{{- partial "shortcodes/piratify.html" (dict {{- partial "shortcodes/piratify.html" (dict
"context" . "context" .Page
"pagefield" "Content" "pagefield" "Content"
"writenotice" (.Get "writenotice" | default (.Get 0)) "writenotice" (.Get "writenotice" | default (.Get 0))
) }} ) }}

View file

@ -21,23 +21,23 @@
{{- end }} {{- end }}
{{- $sort := .sort | default "asc" }} {{- $sort := .sort | default "asc" }}
{{- $pattern := .pattern | default "" }} {{- $pattern := .pattern | default "" }}
{{- $defaultUrlPrefix := strings.TrimRight "/" $context.Page.RelPermalink }} {{- $defaultUrlPrefix := strings.TrimRight "/" $context.RelPermalink }}
{{- if .IsTranslated -}} {{- if .IsTranslated -}}
{{- $defaultLanguage := (index $context.Site.Home.AllTranslations 0).Lang }} {{- $defaultLanguage := (index $context.Site.Home.AllTranslations 0).Lang }}
{{- $defaultLanguagePage := index (where $context.Page.AllTranslations "Language.Lang" $defaultLanguage) 0 }} {{- $defaultLanguagePage := index (where $context.AllTranslations "Language.Lang" $defaultLanguage) 0 }}
{{- $defaultUrlPrefix = strings.TrimRight "/" $defaultLanguagePage.RelPermalink }} {{- $defaultUrlPrefix = strings.TrimRight "/" $defaultLanguagePage.RelPermalink }}
{{- end }} {{- end }}
{{- $urlPrefix := strings.TrimRight "/" $context.Page.RelPermalink }} {{- $urlPrefix := strings.TrimRight "/" $context.RelPermalink }}
{{- with $context }} {{- with $context }}
<div class="box attachments cstyle {{ $style }}"{{ if $color }} style="--VARIABLE-BOX-color: {{ $color }};"{{ end }}> <div class="box attachments cstyle {{ $style }}"{{ if $color }} style="--VARIABLE-BOX-color: {{ $color }};"{{ end }}>
<div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title | markdownify }}</div> <div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title | markdownify }}</div>
<ul class="box-content attachments-files"> <ul class="box-content attachments-files">
{{- $fileLink := printf "%s/%s" (.Page.Language.ContentDir | default "content") .Page.File.Dir }} {{- $fileLink := printf "%s/%s" (.Language.ContentDir | default "content") .File.Dir }}
{{- $fileLink = replace (replace $fileLink "\\" "/") "content/" "" }} {{- $fileLink = replace (replace $fileLink "\\" "/") "content/" "" }}
{{- $fileDir := printf "%s/%s" (.Page.Language.ContentDir | default "content") .Page.File.Dir }} {{- $fileDir := printf "%s/%s" (.Language.ContentDir | default "content") .File.Dir }}
{{- $fileDir = replace $fileDir "\\" "/" }} {{- $fileDir = replace $fileDir "\\" "/" }}
{{- $filesName := printf "%s.files" .Page.File.BaseFileName }} {{- $filesName := printf "%s.files" .File.BaseFileName }}
{{- if and (eq .Page.File.BaseFileName "index") (fileExists (printf "%sfiles" $fileDir)) }} {{- if and (eq .File.BaseFileName "index") (fileExists (printf "%sfiles" $fileDir)) }}
{{- $c := "" }}{{/* backward compat to < 5.9.0 behavior */}} {{- $c := "" }}{{/* backward compat to < 5.9.0 behavior */}}
{{- $filesName = "files" }} {{- $filesName = "files" }}
{{- end }} {{- end }}

View file

@ -17,10 +17,10 @@
{{- with $context }} {{- with $context }}
{{ (printf "<%s class=\"children children-%s children-sort-%s\">" $containerstyle $style $sortTerm)|safeHTML }} {{ (printf "<%s class=\"children children-%s children-sort-%s\">" $containerstyle $style $sortTerm)|safeHTML }}
{{- $pages := .Page.Pages }} {{- $pages := .Pages }}
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }} {{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
{{- $currentOrdersectionsby := $sortTerm | default (.Page.Params.ordersectionsby | default $defaultOrdersectionsby) }} {{- $currentOrdersectionsby := $sortTerm | default (.Params.ordersectionsby | default $defaultOrdersectionsby) }}
{{- if eq $currentOrdersectionsby "weight" }} {{- if eq $currentOrdersectionsby "weight" }}
{{- template "childs" dict "menu" $pages.ByWeight "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm "context" . }} {{- template "childs" dict "menu" $pages.ByWeight "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm "context" . }}
{{- else if or (eq $currentOrdersectionsby "name") (eq $currentOrdersectionsby "title") }} {{- else if or (eq $currentOrdersectionsby "name") (eq $currentOrdersectionsby "title") }}
@ -83,10 +83,10 @@
{{- (printf "<%s>" $.containerstyle)|safeHTML }} {{- (printf "<%s>" $.containerstyle)|safeHTML }}
{{- end }} {{- end }}
{{- $pages := .Page.Pages }} {{- $pages := .Pages }}
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }} {{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
{{- $currentOrdersectionsby := $.sortTerm | default (.Page.Params.ordersectionsby | default $defaultOrdersectionsby) }} {{- $currentOrdersectionsby := $.sortTerm | default (.Params.ordersectionsby | default $defaultOrdersectionsby) }}
{{- if eq $currentOrdersectionsby "weight" }} {{- if eq $currentOrdersectionsby "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 "context" $context }} {{- template "childs" dict "menu" $pages.ByWeight "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm "context" $context }}
{{- else if or (eq $.currentOrdersectionsby "name") (eq $.currentOrdersectionsby "title") }} {{- else if or (eq $.currentOrdersectionsby "name") (eq $.currentOrdersectionsby "title") }}

View file

@ -6,7 +6,7 @@
{{- if eq (printf "%T" $expanded) "string" }} {{- if eq (printf "%T" $expanded) "string" }}
{{- $expanded = (eq $expanded "true") }} {{- $expanded = (eq $expanded "true") }}
{{- end }} {{- end }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $context.Page) .id }} {{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $context) .id }}
{{- with $context }} {{- with $context }}
<div class="expand"> <div class="expand">
<input type="checkbox" id="expand-{{ $id }}" aria-controls="expandcontent-{{ $id }}" {{ if $expanded }} checked{{ end }}> <input type="checkbox" id="expand-{{ $id }}" aria-controls="expandcontent-{{ $id }}" {{ if $expanded }} checked{{ end }}>

View file

@ -6,8 +6,8 @@
{{- $target := .target | default "" }} {{- $target := .target | default "" }}
{{- if and (eq (len $target) 0) (or (strings.HasPrefix $url "http://") (strings.HasPrefix $url "https://") ) }} {{- if and (eq (len $target) 0) (or (strings.HasPrefix $url "http://") (strings.HasPrefix $url "https://") ) }}
{{- $target = "_blank" }} {{- $target = "_blank" }}
{{- if isset $context.Page.Site.Params "externallinktarget" }} {{- if isset $context.Site.Params "externallinktarget" }}
{{- $target = $context.Page.Site.Params.externalLinkTarget }} {{- $target = $context.Site.Params.externalLinkTarget }}
{{- end }} {{- end }}
{{- end -}} {{- end -}}
<a href="{{ $url | safeURL }}"{{ if $title }} title="{{ $title }}"{{ end }}{{ if gt (len $target) 0 }} target="{{ $target }}"{{ end }}>{{ $content | safeHTML }}</a> <a href="{{ $url | safeURL }}"{{ if $title }} title="{{ $title }}"{{ end }}{{ if gt (len $target) 0 }} target="{{ $target }}"{{ end }}>{{ $content | safeHTML }}</a>

View file

@ -5,5 +5,5 @@
<span class="math align-{{ $align }}"> <span class="math align-{{ $align }}">
{{- $content | safeHTML -}} {{- $content | safeHTML -}}
</span> </span>
{{- .Page.Store.Set "hasMathJax" true }} {{- .Store.Set "hasMathJax" true }}
{{- end }} {{- end }}

View file

@ -2,7 +2,7 @@
{{- $content := .content }} {{- $content := .content }}
{{- $align := .align | default "center" }} {{- $align := .align | default "center" }}
{{- $zoom := $context.Site.Params.mermaidZoom | default false }} {{- $zoom := $context.Site.Params.mermaidZoom | default false }}
{{- with $context.Page.Params.mermaidZoom }} {{- with $context.Params.mermaidZoom }}
{{- $zoom = . }} {{- $zoom = . }}
{{- if eq (printf "%T" .) "string" }} {{- if eq (printf "%T" .) "string" }}
{{- $zoom = (eq . "true") }} {{- $zoom = (eq . "true") }}
@ -18,5 +18,5 @@
<div class="mermaid align-{{ $align }}{{ if $zoom }} zoom{{ end }}"> <div class="mermaid align-{{ $align }}{{ if $zoom }} zoom{{ end }}">
{{- replaceRE "&#39;" "'" ( replaceRE "&#34;" "\"" ( $content | safeHTML ) ) -}} {{- replaceRE "&#39;" "'" ( replaceRE "&#34;" "\"" ( $content | safeHTML ) ) -}}
</div> </div>
{{- .Page.Store.Set "hasMermaid" true }} {{- .Store.Set "hasMermaid" true }}
{{- end }} {{- end }}

View file

@ -1,8 +1,8 @@
{{- $context := .context }} {{- $context := .context }}
{{- $src := .src }} {{- $src := .src }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $context.Page) .id }} {{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $context) .id }}
{{- with $context }} {{- with $context }}
{{- with .Page.Resources.Match $src }} {{- with .Resources.Match $src }}
{{- range . }} {{- range . }}
{{- $src = .RelPermalink }} {{- $src = .RelPermalink }}
{{- end }} {{- end }}
@ -14,5 +14,5 @@
openapi-url="{{ $src }}" openapi-url="{{ $src }}"
></div> ></div>
</div> </div>
{{- .Page.Store.Set "hasOpenapi" true }} {{- .Store.Set "hasOpenapi" true }}
{{- end }} {{- end }}

View file

@ -1,4 +1,4 @@
{{ warnf "DEPRECATED: Use shortcode openapi instead of swagger in %q" .context.Page.File.Path }} {{ warnf "DEPRECATED: Use shortcode openapi instead of swagger in %q" .context.File.Path }}
{{- partial "shortcodes/openapi.html" (dict {{- partial "shortcodes/openapi.html" (dict
"context" .context "context" .context
"src" .src "src" .src

View file

@ -1,6 +1,6 @@
{{- $_hugo_config := `{ "version": 1 }` }} {{- $_hugo_config := `{ "version": 1 }` }}
{{- partial "shortcodes/attachments.html" (dict {{- partial "shortcodes/attachments.html" (dict
"context" . "context" .Page
"color" (.Get "color") "color" (.Get "color")
"content" .Inner "content" .Inner
"icon" (.Get "icon") "icon" (.Get "icon")

View file

@ -1,6 +1,6 @@
{{- $_hugo_config := `{ "version": 1 }` }} {{- $_hugo_config := `{ "version": 1 }` }}
{{- partial "shortcodes/badge.html" (dict {{- partial "shortcodes/badge.html" (dict
"context" . "context" .Page
"color" (.Get "color") "color" (.Get "color")
"content" .Inner "content" .Inner
"icon" (.Get "icon") "icon" (.Get "icon")

View file

@ -1,6 +1,6 @@
{{- $_hugo_config := `{ "version": 1 }` }} {{- $_hugo_config := `{ "version": 1 }` }}
{{- partial "shortcodes/button.html" (dict {{- partial "shortcodes/button.html" (dict
"context" . "context" .Page
"color" (.Get "color") "color" (.Get "color")
"content" .Inner "content" .Inner
"href" (.Get "href") "href" (.Get "href")

View file

@ -1,6 +1,6 @@
{{- $_hugo_config := `{ "version": 1 }` }} {{- $_hugo_config := `{ "version": 1 }` }}
{{- partial "shortcodes/children.html" (dict {{- partial "shortcodes/children.html" (dict
"context" . "context" .Page
"containerstyle" (.Get "containerstyle") "containerstyle" (.Get "containerstyle")
"description" (.Get "description") "description" (.Get "description")
"depth" (.Get "depth") "depth" (.Get "depth")

View file

@ -7,7 +7,7 @@
{{- $id = .Ordinal }} {{- $id = .Ordinal }}
{{- end }} {{- end }}
{{- partial "shortcodes/expand.html" (dict {{- partial "shortcodes/expand.html" (dict
"context" . "context" .Page
"content" .Inner "content" .Inner
"open" (.Get "open" | default (.Get 1)) "open" (.Get "open" | default (.Get 1))
"title" (.Get "title" | default (.Get 0)) "title" (.Get "title" | default (.Get 0))

View file

@ -1,5 +1,5 @@
{{- $_hugo_config := `{ "version": 1 }` }} {{- $_hugo_config := `{ "version": 1 }` }}
{{- partial "shortcodes/icon.html" (dict {{- partial "shortcodes/icon.html" (dict
"context" . "context" .Page
"icon" (.Get "icon" | default (.Get 0)) "icon" (.Get "icon" | default (.Get 0))
) }} ) }}

View file

@ -1,5 +1,5 @@
{{- partial "shortcodes/include.html" (dict {{- partial "shortcodes/include.html" (dict
"context" . "context" .Page
"file" (.Get "file" | default (.Get 0)) "file" (.Get "file" | default (.Get 0))
"hidefirstheading" (.Get "hidefirstheading" | default (.Get 1)) "hidefirstheading" (.Get "hidefirstheading" | default (.Get 1))
) }} ) }}

View file

@ -1,6 +1,6 @@
{{- $_hugo_config := `{ "version": 1 }` }} {{- $_hugo_config := `{ "version": 1 }` }}
{{- partial "shortcodes/math.html" (dict {{- partial "shortcodes/math.html" (dict
"context" . "context" .Page
"content" .Inner "content" .Inner
"align" (.Get "align") "align" (.Get "align")
) }} ) }}

View file

@ -1,6 +1,6 @@
{{- $_hugo_config := `{ "version": 1 }` }} {{- $_hugo_config := `{ "version": 1 }` }}
{{- partial "shortcodes/mermaid.html" (dict {{- partial "shortcodes/mermaid.html" (dict
"context" . "context" .Page
"content" .Inner "content" .Inner
"align" (.Get "align") "align" (.Get "align")
"zoom" (.Get "zoom") "zoom" (.Get "zoom")

View file

@ -1,6 +1,6 @@
{{- $_hugo_config := `{ "version": 1 }` }} {{- $_hugo_config := `{ "version": 1 }` }}
{{- partial "shortcodes/notice.html" (dict {{- partial "shortcodes/notice.html" (dict
"context" . "context" .Page
"color" (.Get "color") "color" (.Get "color")
"content" .Inner "content" .Inner
"icon" (.Get "icon" | default (.Get 2)) "icon" (.Get "icon" | default (.Get 2))

View file

@ -6,7 +6,7 @@
{{- $id = .Ordinal }} {{- $id = .Ordinal }}
{{- end }} {{- end }}
{{- partial "shortcodes/openapi.html" (dict {{- partial "shortcodes/openapi.html" (dict
"context" . "context" .Page
"src" (.Get "src") "src" (.Get "src")
"id" $id "id" $id
) }} ) }}

View file

@ -1,4 +1,4 @@
{{- partial "shortcodes/siteparam.html" (dict {{- partial "shortcodes/siteparam.html" (dict
"context" . "context" .Page
"name" (.Get "name" | default (.Get 0)) "name" (.Get "name" | default (.Get 0))
) }} ) }}

View file

@ -6,7 +6,7 @@
{{- $id = .Ordinal }} {{- $id = .Ordinal }}
{{- end }} {{- end }}
{{- partial "shortcodes/swagger.html" (dict {{- partial "shortcodes/swagger.html" (dict
"context" . "context" .Page
"src" (.Get "src") "src" (.Get "src")
"id" $id "id" $id
) }} ) }}

View file

@ -1,5 +1,5 @@
{{- partial "shortcodes/tabs.html" (dict {{- partial "shortcodes/tabs.html" (dict
"context" . "context" .Page
"content" .Inner "content" .Inner
"groupid" ((.Get "groupid") | default (.Get "groupId")) "groupid" ((.Get "groupid") | default (.Get "groupId"))
"tabs" (.Scratch.Get "tabs") "tabs" (.Scratch.Get "tabs")