Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/uPagge/uBlogger.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDillon <dillonzq@outlook.com>2020-02-27 15:14:40 +0300
committerDillon <dillonzq@outlook.com>2020-02-27 15:14:40 +0300
commitae81e3767e125cb84f7fb216ade3cd2d406727c5 (patch)
tree91376707e9628c94cd3d620f0ef67f970317ab26 /layouts
parent0dc5feb7f39043a8ba00bcad683f3907cad0bf96 (diff)
fix(srcatch): fix srcatch bugs
Diffstat (limited to 'layouts')
-rw-r--r--layouts/_default/_markup/render-image.html2
-rw-r--r--layouts/_default/baseof.html4
-rw-r--r--layouts/_default/summary.html4
-rw-r--r--layouts/partials/assets.html (renamed from layouts/partials/script.html)49
-rw-r--r--layouts/partials/function/id.html6
-rw-r--r--layouts/partials/home/profile.html9
-rw-r--r--layouts/partials/plugin/icon.html11
-rw-r--r--layouts/partials/plugin/image.html33
-rw-r--r--layouts/partials/plugin/link.html7
-rw-r--r--layouts/partials/plugin/share.html6
-rw-r--r--layouts/partials/plugin/social.html12
-rw-r--r--layouts/posts/single.html2
-rw-r--r--layouts/shortcodes/dev/echarts.html6
-rw-r--r--layouts/shortcodes/echarts.html6
-rw-r--r--layouts/shortcodes/mermaid.html5
-rw-r--r--layouts/shortcodes/typeit.html15
16 files changed, 83 insertions, 94 deletions
diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html
index 5f8de9e..7c7e389 100644
--- a/layouts/_default/_markup/render-image.html
+++ b/layouts/_default/_markup/render-image.html
@@ -1,6 +1,6 @@
<figure>
{{- $lightgallery := ne .Page.Site.Params.page.lightgallery false | and (ne .Page.Params.lightgallery false) -}}
- {{- partial "plugin/image.html" (dict "src" .Destination "title" .Title "description" .Text "lightgallery" $lightgallery "context" .Page) -}}
+ {{- partial "plugin/image.html" (dict "src" .Destination "title" .Title "description" .Text "lightgallery" $lightgallery "scratch" (.Page.Scratch.Get "scratch")) -}}
{{- with (.Title | default .Text) -}}
<figcaption class="image-caption">
{{- . | safeHTML -}}
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index 637135b..dd6a792 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -58,7 +58,7 @@
<span>&nbsp;</span>
</a>
- {{- /* Load script */ -}}
- {{- partial "script.html" . -}}
+ {{- /* Load JavaScript scripts and CSS */ -}}
+ {{- partial "assets.html" . -}}
</body>
</html>
diff --git a/layouts/_default/summary.html b/layouts/_default/summary.html
index d3fb3df..0fe2c7d 100644
--- a/layouts/_default/summary.html
+++ b/layouts/_default/summary.html
@@ -1,9 +1,11 @@
+{{- $scratch := .Scratch.Get "scratch" -}}
+
<article class="single summary" itemscope itemtype="http://schema.org/Article">
{{- /* Featured image */ -}}
{{- with .Params.featuredImage -}}
<div class="featured-image-preview">
{{- $image := $.Params.featuredImagePreview | default . -}}
- {{- partial "plugin/image.html" (dict "src" $image "description" $.Description "context" $) -}}
+ {{- partial "plugin/image.html" (dict "src" $image "description" $.Description "scratch" $scratch) -}}
</div>
{{- end -}}
diff --git a/layouts/partials/script.html b/layouts/partials/assets.html
index fe85de3..9a0d4e4 100644
--- a/layouts/partials/script.html
+++ b/layouts/partials/assets.html
@@ -146,7 +146,7 @@
{{- end -}}
{{- /* mermaid */ -}}
-{{- with $scratch.Get "mermaidMap" -}}
+{{- with $scratch.Get "mermaidArr" -}}
{{- with $CDN.mermaidJS -}}
{{- slice . | $scratch.Add "scriptCDN" -}}
{{- else -}}
@@ -154,7 +154,24 @@
{{- end -}}
{{- slice "lib/mermaid/mermaid.scss" | $scratch.Add "linkLocal" -}}
<script>
- window.mermaidMap = {{ jsonify . | safeJS }};
+ window.mermaidArr = {{ jsonify . | safeJS }};
+ </script>
+{{- end -}}
+
+{{- /* ECharts */ -}}
+{{- with $scratch.Get "echartsArr" -}}
+ {{- with $CDN.echartsJS -}}
+ {{- slice . | $scratch.Add "scriptCDN" -}}
+ {{- else -}}
+ {{- slice "lib/echarts/echarts.min.js" | $scratch.Add "scriptLocal" -}}
+ {{- end -}}
+ {{- with $CDN.echartsMacaronsJS -}}
+ {{- slice . | $scratch.Add "scriptCDN" -}}
+ {{- else -}}
+ {{- slice "lib/echarts/macarons.js" | $scratch.Add "scriptLocal" -}}
+ {{- end -}}
+ <script>
+ window.echartsArr = {{ jsonify . | safeJS }};
</script>
{{- end -}}
@@ -181,28 +198,14 @@
{{- end -}}
{{- end -}}
-{{- /* dev feature */ -}}
+{{- /* Dev feature */ -}}
{{- if .Params.dev -}}
- {{- /* ECharts */ -}}
- {{- with $scratch.Get "echartsMap" -}}
- {{- with $CDN.echartsJS -}}
- {{- slice . | $scratch.Add "scriptCDN" -}}
- {{- else -}}
- {{- slice "lib/echarts/echarts.min.js" | $scratch.Add "scriptLocal" -}}
- {{- end -}}
- {{- with $CDN.echartsMacaronsJS -}}
- {{- slice . | $scratch.Add "scriptCDN" -}}
- {{- else -}}
- {{- slice "lib/echarts/macarons.js" | $scratch.Add "scriptLocal" -}}
- {{- end -}}
- <script>
- window.echartsMap = {
- {{- range $key, $var := . -}}
- {{- $key }}: {{ $var | safeJS -}},
- {{- end -}}
- };
- </script>
- {{- end -}}
+{{- end -}}
+
+{{- with $scratch.Get "contentMap" -}}
+ <script>
+ window.contentMap = {{ jsonify . | safeJS }};
+ </script>
{{- end -}}
{{- /* Theme script */ -}}
diff --git a/layouts/partials/function/id.html b/layouts/partials/function/id.html
new file mode 100644
index 0000000..081fc67
--- /dev/null
+++ b/layouts/partials/function/id.html
@@ -0,0 +1,6 @@
+{{- /* ID */ -}}
+{{- /* Content -> unique ID */ -}}
+{{- /* shuffle md5 as id */ -}}
+{{- $id := delimit (split (md5 now.Unix) "" | shuffle | first 6) "" | printf "id-%s" -}}
+{{- .scratch.SetInMap "contentMap" $id .content -}}
+{{- return $id -}}
diff --git a/layouts/partials/home/profile.html b/layouts/partials/home/profile.html
index bdeff75..ad3d7f7 100644
--- a/layouts/partials/home/profile.html
+++ b/layouts/partials/home/profile.html
@@ -8,7 +8,7 @@
{{- with $avatar -}}
<div class="home-avatar">
<a href="/posts">
- {{- partial "plugin/image.html" (dict "src-s" . "title" "avatar" "description" (T "home") "context" $) -}}
+ {{- partial "plugin/image.html" (dict "src_s" . "title" "avatar" "description" (T "home") "scratch" $scratch) -}}
</a>
</div>
{{- end -}}
@@ -16,11 +16,8 @@
{{- with .Site.Params.home.profile.subtitle -}}
<h2 class="home-description">
{{- if $.Site.Params.home.profile.typeit -}}
- {{- $id := md5 . | printf "tp-%s" -}}
- <div id={{ printf "r%s" $id }} hidden=true>
- {{- . -}}
- </div>
- <div id={{ $id }} class="typeit"></div>
+ {{- $id := partial "function/id.html" (dict "content" . "scratch" $scratch) -}}
+ <div id="{{ $id }}" class="typeit"></div>
{{- $scratch.SetInMap "typeitMap" $id (slice $id) -}}
{{- else -}}
{{- . -}}
diff --git a/layouts/partials/plugin/icon.html b/layouts/partials/plugin/icon.html
index 85b258e..6ed4061 100644
--- a/layouts/partials/plugin/icon.html
+++ b/layouts/partials/plugin/icon.html
@@ -1,6 +1,5 @@
-{{- $type := index . "type" | default "fa" -}}
-{{- $classList := split (index . "class") " " -}}
-{{- $context := index . "context" -}}
+{{- $type := .type | default "fa" -}}
+{{- $classList := split .class " " -}}
{{- /* Fork Awesome */ -}}
{{- if eq $type "fo" -}}
{{- $newClassList := slice -}}
@@ -12,13 +11,11 @@
{{- end -}}
{{- end -}}
{{- $classList = $newClassList -}}
- {{- $scratch := $context.Scratch.Get "scratch" -}}
- {{- $scratch.Set "forkawesome" true -}}
+ {{- .scratch.Set "forkawesome" true -}}
{{- /* default is Font Awesome */ -}}
{{- /* Others */ -}}
{{- else if ne $type "fa" -}}
- {{- $scratch := $context.Scratch.Get "scratch" -}}
- {{- $scratch.Set "iconfont" true -}}
+ {{- .scratch.Set "iconfont" true -}}
{{- end -}}
<i class="{{ delimit $classList ` ` }}"></i>
diff --git a/layouts/partials/plugin/image.html b/layouts/partials/plugin/image.html
index 5d0a66d..18e8e59 100644
--- a/layouts/partials/plugin/image.html
+++ b/layouts/partials/plugin/image.html
@@ -1,34 +1,29 @@
{{- /* lazysizes and lightgallery.js */ -}}
-{{- $src := index . "src" -}}
-{{- $small := index . "src-s" | default $src -}}
-{{- $large := index . "src-l" | default $src -}}
-{{- $title := index . "title" -}}
-{{- $description := index . "description" -}}
-{{- $context := index . "context" -}}
-{{- $scratch := $context.Scratch.Get "scratch" -}}
+{{- $small := .src_s | default .src -}}
+{{- $large := .src_l | default .src -}}
{{- $loading := resources.Get "svg/loading.svg" | minify -}}
-{{- if not (index . "src") | and (index . "src-s") -}}
+{{- if not .src | and .src_s -}}
{{- $loading = resources.Get "svg/loading.small.svg" | minify -}}
{{- end -}}
-{{- if index . "lightgallery" -}}
- <a class="lightgallery" href="{{ $large | safeURL }}" title="{{ $description }}" data-thumbnail="{{ $small | safeURL }}"{{ if $title }} data-sub-html="<h2>{{ $title }}</h2><p>{{ $description }}</p>"{{ end }}>
+{{- if .lightgallery -}}
+ <a class="lightgallery" href="{{ $large | safeURL }}" title="{{ .description }}" data-thumbnail="{{ $small | safeURL }}"{{ if .title }} data-sub-html="<h2>{{ .title }}</h2><p>{{ .description }}</p>"{{ end }}>
<img
class="lazyload"
src="{{ $loading.RelPermalink | safeURL }}"
data-sizes="auto"
- data-srcset="{{ $small | safeURL }}, {{ $src | safeURL }} 1.5x, {{ $large | safeURL }} 2x"
- data-src="{{ $src | safeURL }}"
- alt="{{ $title | default $description }}" />
+ data-srcset="{{ $small | safeURL }}, {{ .src | safeURL }} 1.5x, {{ $large | safeURL }} 2x"
+ data-src="{{ .src | safeURL }}"
+ alt="{{ .title | default .description }}" />
</a>
- {{- $scratch.Set "lightgallery" true -}}
+ {{- .scratch.Set "lightgallery" true -}}
{{- else -}}
<img
class="lazyload"
src="{{ $loading.RelPermalink | safeURL }}"
data-sizes="auto"
- data-srcset="{{ $small | safeURL }}, {{ $src | safeURL }} 1.5x, {{ $large | safeURL }} 2x"
- data-src="{{ $src | safeURL }}"
- alt="{{ $title | default $description }}"
- title="{{ $description }}" />
+ data-srcset="{{ $small | safeURL }}, {{ .src | safeURL }} 1.5x, {{ $large | safeURL }} 2x"
+ data-src="{{ .src | safeURL }}"
+ alt="{{ .title | default .description }}"
+ title="{{ .description }}" />
{{- end -}}
-{{- $scratch.Set "lazysizes" true -}}
+{{- .scratch.Set "lazysizes" true -}}
diff --git a/layouts/partials/plugin/link.html b/layouts/partials/plugin/link.html
index 8a8f4ea..c71bf34 100644
--- a/layouts/partials/plugin/link.html
+++ b/layouts/partials/plugin/link.html
@@ -1,9 +1,8 @@
-{{- $href := index . "href" -}}
-<a href="{{ $href | safeURL }}"{{ with index . "title" }} title="{{ . }}"{{ end }}{{ if strings.HasPrefix $href "http" }} target="_blank"{{ end }} rel="noopener noreffer{{ with index . `rel` }} {{ . }}{{ end }}">
- {{- with index . "icon" -}}
+<a href="{{ .href | safeURL }}"{{ with .title }} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .href "http" }} target="_blank"{{ end }} rel="noopener noreffer{{ with .rel }} {{ . }}{{ end }}">
+ {{- with .icon -}}
{{- partial "plugin/icon.html" . -}}
{{- end -}}
- {{- with index . "content" -}}
+ {{- with .content -}}
{{- . | safeHTML -}}
{{- end -}}
</a>
diff --git a/layouts/partials/plugin/share.html b/layouts/partials/plugin/share.html
index 7d10c78..4996fb8 100644
--- a/layouts/partials/plugin/share.html
+++ b/layouts/partials/plugin/share.html
@@ -97,7 +97,7 @@
{{- /* 014: Instapaper */ -}}
{{- if .Params.Share.Instapaper | default .Site.Params.Share.Instapaper | eq true -}}
<a href="javascript:void(0);" title="{{ T `share` }} Instapaper" data-sharer="instapaper" data-url="{{ .Permalink }}" data-title="{{ .Title }}" data-description="{{ .Description }}">
- {{- partial "plugin/icon.html" (dict "class" "loveit it-instapaper-fill" "type" "other" "context" .) -}}
+ {{- partial "plugin/icon.html" (dict "class" "loveit it-instapaper-fill" "type" "other" "scratch" $scratch) -}}
</a>
{{- end -}}
@@ -146,7 +146,7 @@
{{- /* 021: Myspace */ -}}
{{- if .Params.Share.Myspace | default .Site.Params.Share.Myspace | eq true -}}
<a href="javascript:void(0);" title="{{ T `share` }} Myspace" data-sharer="myspace" data-url="{{ .Permalink }}" data-title="{{ .Title }}" data-description="{{ .Description }}">
- {{- partial "plugin/icon.html" (dict "class" "loveit it-myspace-fill" "type" "other" "context" .) -}}
+ {{- partial "plugin/icon.html" (dict "class" "loveit it-myspace-fill" "type" "other" "scratch" $scratch) -}}
</a>
{{- end -}}
@@ -160,7 +160,7 @@
{{- /* 023: 百度 */ -}}
{{- if .Params.Share.Baidu | default .Site.Params.Share.Baidu | eq true -}}
<a href="javascript:void(0);" title="{{ T `share` }} 百度" data-sharer="baidu" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
- {{- partial "plugin/icon.html" (dict "class" "loveit it-baidu-fill" "type" "other" "context" .) -}}
+ {{- partial "plugin/icon.html" (dict "class" "loveit it-baidu-fill" "type" "other" "scratch" $scratch) -}}
</a>
{{- end -}}
diff --git a/layouts/partials/plugin/social.html b/layouts/partials/plugin/social.html
index f7eb995..bb6dc3f 100644
--- a/layouts/partials/plugin/social.html
+++ b/layouts/partials/plugin/social.html
@@ -1,3 +1,5 @@
+{{- $scratch := .Scratch.Get "scratch" -}}
+
{{- /* 001: Github */ -}}
{{- with .Site.Params.Social.Github -}}
{{- $options := dict "href" (printf "https://github.com/%s" .) "title" "GitHub" "rel" "me" -}}
@@ -302,7 +304,7 @@
{{- /* 044: 知乎 */ -}}
{{- with .Site.Params.Social.Zhihu -}}
{{- $options := dict "href" (printf "https://www.zhihu.com/people/%s" .) "title" "知乎" "rel" "me" -}}
- {{- $options = dict "icon" (dict "class" "loveit it-zhihu-line" "type" "other" "context" $) | merge $options -}}
+ {{- $options = dict "icon" (dict "class" "loveit it-zhihu-line" "type" "other" "scratch" $scratch) | merge $options -}}
{{- partial "plugin/link.html" $options -}}
{{- end -}}
@@ -394,28 +396,28 @@
{{- /* 055: Gitea */ -}}
{{- with .Site.Params.Social.Gitea -}}
{{- $options := dict "href" . "title" "Gitea" "rel" "me" -}}
- {{- $options = dict "icon" (dict "class" "fa fa-gitea fa-fw" "type" "fo" "context" $) | merge $options -}}
+ {{- $options = dict "icon" (dict "class" "fa fa-gitea fa-fw" "type" "fo" "scratch" $scratch) | merge $options -}}
{{- partial "plugin/link.html" $options -}}
{{- end -}}
{{- /* 056: XMPP */ -}}
{{- with .Site.Params.Social.XMPP -}}
{{- $options := dict "href" (printf "xmpp:%s" .) "title" "XMPP" "rel" "me" -}}
- {{- $options = dict "icon" (dict "class" "fa fa-xmpp fa-fw" "type" "fo" "context" $) | merge $options -}}
+ {{- $options = dict "icon" (dict "class" "fa fa-xmpp fa-fw" "type" "fo" "scratch" $scratch) | merge $options -}}
{{- partial "plugin/link.html" $options -}}
{{- end -}}
{{- /* 057: Matrix */ -}}
{{- with .Site.Params.Social.Matrix -}}
{{- $options := dict "href" (printf "https://matrix.to/#/%s" .) "title" "Matrix" "rel" "me" -}}
- {{- $options = dict "icon" (dict "class" "fa fa-matrix-org fa-fw" "type" "fo" "context" $) | merge $options -}}
+ {{- $options = dict "icon" (dict "class" "fa fa-matrix-org fa-fw" "type" "fo" "scratch" $scratch) | merge $options -}}
{{- partial "plugin/link.html" $options -}}
{{- end -}}
{{- /* 058: bilibili */ -}}
{{- with .Site.Params.Social.Bilibili -}}
{{- $options := dict "href" (printf "https://space.bilibili.com/%s" .) "title" "bilibili" "rel" "me" -}}
- {{- $options = dict "icon" (dict "class" "loveit it-bilibili-fill" "type" "other" "context" $) | merge $options -}}
+ {{- $options = dict "icon" (dict "class" "loveit it-bilibili-fill" "type" "other" "scratch" $scratch) | merge $options -}}
{{- partial "plugin/link.html" $options -}}
{{- end -}}
diff --git a/layouts/posts/single.html b/layouts/posts/single.html
index 3330f22..60a70af 100644
--- a/layouts/posts/single.html
+++ b/layouts/posts/single.html
@@ -47,7 +47,7 @@
{{- /* Featured image */ -}}
{{- with .Params.featuredImage -}}
<div class="featured-image">
- {{- partial "plugin/image.html" (dict "src" . "description" $.Description "context" $) -}}
+ {{- partial "plugin/image.html" (dict "src" . "description" $.Description "scratch" $scratch) -}}
</div>
{{- end -}}
diff --git a/layouts/shortcodes/dev/echarts.html b/layouts/shortcodes/dev/echarts.html
deleted file mode 100644
index ad967bd..0000000
--- a/layouts/shortcodes/dev/echarts.html
+++ /dev/null
@@ -1,6 +0,0 @@
-{{- $scratch := .Page.Scratch.Get "scratch" -}}
-
-{{- /* shuffle md5 as id */ -}}
-{{- $id := delimit (split (md5 .Inner) "" | shuffle) "" | printf "echarts-%s" -}}
-<div class="echarts" id="{{ $id }}"></div>
-{{- $scratch.SetInMap "echartsMap" $id (printf "{%s}" .Inner) -}}
diff --git a/layouts/shortcodes/echarts.html b/layouts/shortcodes/echarts.html
new file mode 100644
index 0000000..9d609f0
--- /dev/null
+++ b/layouts/shortcodes/echarts.html
@@ -0,0 +1,6 @@
+{{- $scratch := .Page.Scratch.Get "scratch" -}}
+
+{{- $content := .Inner | transform.Unmarshal | jsonify -}}
+{{- $id := partial "function/id.html" (dict "content" $content "scratch" $scratch) -}}
+<div class="echarts" id="{{ $id }}"></div>
+{{- slice $id | $scratch.Add "echartsArr" -}}
diff --git a/layouts/shortcodes/mermaid.html b/layouts/shortcodes/mermaid.html
index 1d13be1..dd11ce8 100644
--- a/layouts/shortcodes/mermaid.html
+++ b/layouts/shortcodes/mermaid.html
@@ -1,6 +1,5 @@
{{- $scratch := .Page.Scratch.Get "scratch" -}}
-{{- /* shuffle md5 as id */ -}}
-{{- $id := delimit (split (md5 .Inner) "" | shuffle) "" | printf "mermaid-%s" -}}
+{{- $id := partial "function/id.html" (dict "content" (trim .Inner "\n") "scratch" $scratch) -}}
<div class="mermaid" id="{{ $id }}"></div>
-{{- $scratch.SetInMap "mermaidMap" $id (trim .Inner "\n") -}}
+{{- slice $id | $scratch.Add "mermaidArr" -}}
diff --git a/layouts/shortcodes/typeit.html b/layouts/shortcodes/typeit.html
index 80d384c..9176f0f 100644
--- a/layouts/shortcodes/typeit.html
+++ b/layouts/shortcodes/typeit.html
@@ -1,16 +1,12 @@
{{- $scratch := .Page.Scratch.Get "scratch" -}}
{{- /* only the trailing newline is retained */ -}}
-{{- $content := replaceRE `(?s)^\n*(.*?)\n*$` "$1\n" .Inner | .Page.RenderString -}}
-{{- /* shuffle md5 as id */ -}}
-{{- $id := delimit (split (md5 $content) "" | shuffle) "" | printf "typeit-%s" -}}
+{{- $content := replaceRE `(?s)^\n*(.*?)\n*$` "$1\n" .Inner | .Page.RenderString | chomp -}}
+{{- $id := partial "function/id.html" (dict "content" $content "scratch" $scratch) -}}
<div class={{ .Get "class" | default "typeit" }}>
{{- /* raw html content */ -}}
{{- if .Get "raw" -}}
- <div id={{ printf "r%s" $id }} hidden=true>
- {{- $content | safeHTML -}}
- </div>
<div id={{ $id }}></div>
{{- else if .Get "code" -}}
{{- /* highlight code content without line number */ -}}
@@ -23,16 +19,9 @@
{{- $content = replaceRE ` ` "&nbsp;" $content | replaceRE `(<\w+)&nbsp;` "$1 " | replaceRE `\n` "<br />" -}}
{{- /* fix "<br />" location error which is a bug of Typeit HTML parser */ -}}
{{- $content = replaceRE `<br /></span>` "</span><br />" $content -}}
- <div id={{ printf "r%s" $id }} hidden=true>
- {{- $content | safeHTML -}}
- </div>
<div class="highlight" id={{ $id }}></div>
{{- else -}}
{{- $tag := .Get "tag" | default "p" -}}
- {{- $content = $content | chomp -}}
- <div id={{ printf "r%s" $id }} hidden=true>
- {{- $content | safeHTML -}}
- </div>
{{- printf "<%s id=%s></%s>" $tag $id $tag | safeHTML -}}
{{- end -}}