diff options
author | Dillon <dillonzq@outlook.com> | 2020-04-21 17:55:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-21 17:55:06 +0300 |
commit | f14301c395ffd63ef72625bf8bfe887fa211d013 (patch) | |
tree | 367e8f5a699a0b1df5d142f0ae259c9d6dd9de3f /layouts/shortcodes | |
parent | 8a0e61085cfc2f2d1a342697c73b10cbc1d27a68 (diff) |
feat: improve configuration (#245)
* feat: improve configuration
* fix: fix partials/footer.html error
Diffstat (limited to 'layouts/shortcodes')
-rw-r--r-- | layouts/shortcodes/echarts.html | 6 | ||||
-rw-r--r-- | layouts/shortcodes/mapbox.html | 18 | ||||
-rw-r--r-- | layouts/shortcodes/mermaid.html | 6 | ||||
-rw-r--r-- | layouts/shortcodes/music.html | 4 | ||||
-rw-r--r-- | layouts/shortcodes/typeit.html | 10 |
5 files changed, 18 insertions, 26 deletions
diff --git a/layouts/shortcodes/echarts.html b/layouts/shortcodes/echarts.html index ec0e4c8..a3b3cdd 100644 --- a/layouts/shortcodes/echarts.html +++ b/layouts/shortcodes/echarts.html @@ -1,8 +1,6 @@ -{{- $scratch := .Page.Scratch.Get "scratch" -}} - {{- $content := .Inner | transform.Unmarshal | jsonify -}} -{{- $id := partial "function/id.html" (dict "content" $content "scratch" $scratch) -}} +{{- $id := partial "function/id.html" (dict "content" $content "scratch" .Page.Scratch) -}} {{- $width := cond .IsNamedParams (.Get "width") (.Get 0) | default "100%" -}} {{- $height := cond .IsNamedParams (.Get "height") (.Get 1) | default "30rem" -}} <div class="echarts" id="{{ $id }}" style="width: {{ $width }}; height: {{ $height }};"></div> -{{- $scratch.Set "echarts" true -}} +{{- dict "echarts" true | merge (.Page.Scratch.Get "this") | .Page.Scratch.Set "this" -}} diff --git a/layouts/shortcodes/mapbox.html b/layouts/shortcodes/mapbox.html index 6aa2a79..e5749f6 100644 --- a/layouts/shortcodes/mapbox.html +++ b/layouts/shortcodes/mapbox.html @@ -1,15 +1,15 @@ -{{- $scratch := .Page.Scratch.Get "scratch" -}} +{{- $mapbox := (.Page.Scratch.Get "params").page.mapbox | default dict -}} {{- $lng := cond .IsNamedParams (.Get "lng") (.Get 0) -}} {{- $lat := cond .IsNamedParams (.Get "lat") (.Get 1) -}} {{- $zoom := cond .IsNamedParams (.Get "zoom") (.Get 2) | default 10 -}} {{- $marked := cond .IsNamedParams (.Get "marked") (.Get 3) | ne false -}} -{{- $lightStyle := .Page.Params.mapbox.lightStyle | default .Page.Site.Params.mapbox.lightStyle -}} -{{- $darkStyle := .Page.Params.mapbox.darkStyle | default .Page.Site.Params.mapbox.darkStyle -}} -{{- $navigation := ne .Page.Params.mapbox.navigation false | and (ne .Page.Site.Params.mapbox.navigation false) -}} -{{- $geolocate := ne .Page.Params.mapbox.geolocate false | and (ne .Page.Site.Params.mapbox.geolocate false) -}} -{{- $scale := ne .Page.Params.mapbox.scale false | and (ne .Page.Site.Params.mapbox.scale false) -}} -{{- $fullscreen := ne .Page.Params.mapbox.fullscreen false | and (ne .Page.Site.Params.mapbox.fullscreen false) -}} +{{- $lightStyle := $mapbox.lightStyle -}} +{{- $darkStyle := $mapbox.darkStyle -}} +{{- $navigation := $mapbox.navigation -}} +{{- $geolocate := $mapbox.geolocate -}} +{{- $scale := $mapbox.scale -}} +{{- $fullscreen := $mapbox.fullscreen -}} {{- $width := "100%" -}} {{- $height := "20rem" -}} @@ -28,6 +28,6 @@ {{- end -}} {{- $darkStyle = $darkStyle | default $lightStyle -}} {{- $options := dict "lng" $lng "lat" $lat "zoom" $zoom "marked" $marked "lightStyle" $lightStyle "darkStyle" $darkStyle "geolocate" $geolocate "navigation" $navigation "scale" $scale "fullscreen" $fullscreen -}} -{{- $id := partial "function/id.html" (dict "content" $options "scratch" $scratch) -}} +{{- $id := partial "function/id.html" (dict "content" $options "scratch" .Page.Scratch) -}} <div class="mapbox" id="{{ $id }}" style="width: {{ $width }}; height: {{ $height }};"></div> -{{- $scratch.Set "mapbox" true -}} +{{- dict "mapbox" true | merge (.Page.Scratch.Get "this") | .Page.Scratch.Set "this" -}} diff --git a/layouts/shortcodes/mermaid.html b/layouts/shortcodes/mermaid.html index 872fae8..61f0d9b 100644 --- a/layouts/shortcodes/mermaid.html +++ b/layouts/shortcodes/mermaid.html @@ -1,5 +1,3 @@ -{{- $scratch := .Page.Scratch.Get "scratch" -}} - -{{- $id := partial "function/id.html" (dict "content" (trim .Inner "\n") "scratch" $scratch) -}} +{{- $id := partial "function/id.html" (dict "content" (trim .Inner "\n") "scratch" .Page.Scratch) -}} <div class="mermaid" id="{{ $id }}"></div> -{{- $scratch.Set "mermaid" true -}} +{{- dict "mermaid" true | merge (.Page.Scratch.Get "this") | .Page.Scratch.Set "this" -}} diff --git a/layouts/shortcodes/music.html b/layouts/shortcodes/music.html index 82228fc..0933914 100644 --- a/layouts/shortcodes/music.html +++ b/layouts/shortcodes/music.html @@ -1,5 +1,3 @@ -{{- $scratch := .Page.Scratch.Get "scratch" -}} - {{- $theme := "#448aff" -}} {{- if .IsNamedParams -}} {{- $theme = .Get "theme" | default $theme -}} @@ -41,4 +39,4 @@ {{- else -}} <meting-js server="{{ .Get 0 }}" type="{{ .Get 1 }}" id="{{ .Get 2 }}" theme="{{ $theme }}"></meting-js> {{- end -}} -{{- $scratch.Set "music" true -}} +{{- dict "music" true | merge (.Page.Scratch.Get "this") | .Page.Scratch.Set "this" -}} diff --git a/layouts/shortcodes/typeit.html b/layouts/shortcodes/typeit.html index fdbecf1..95aa89e 100644 --- a/layouts/shortcodes/typeit.html +++ b/layouts/shortcodes/typeit.html @@ -1,5 +1,3 @@ -{{- $scratch := .Page.Scratch.Get "scratch" -}} - {{- $content := .Inner -}} {{- $classList := .Get "class" | slice -}} {{- $tag := .Get "tag" | default "div" -}} @@ -22,11 +20,11 @@ {{- /* trim the newline */ -}} {{- $content = trim $content "\n" -}} -{{- $id := partial "function/id.html" (dict "content" $content "scratch" $scratch) -}} -{{- $key := .Get "group" | default $id -}} -{{- $group := index ($scratch.Get "typeitMap" | default dict) $key -}} +{{- $id := partial "function/id.html" (dict "content" $content "scratch" .Page.Scratch) -}} +{{- $key := .Get "group" | string | default $id -}} +{{- $group := index ((.Page.Scratch.Get "this").typeitMap | default dict) $key -}} {{- $group = $group | default slice | append $id -}} -{{- $scratch.SetInMap "typeitMap" $key $group -}} +{{- dict $key $group | dict "typeitMap" | merge (.Page.Scratch.Get "this") | .Page.Scratch.Set "this" -}} <div class="typeit"> {{- printf `<%s id="%s" class="%s"></%s>` $tag $id (delimit $classList " ") $tag | safeHTML -}} |