fix(srcatch): fix srcatch bugs
This commit is contained in:
@@ -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 -}}
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<span> </span>
|
||||
</a>
|
||||
|
||||
{{- /* Load script */ -}}
|
||||
{{- partial "script.html" . -}}
|
||||
{{- /* Load JavaScript scripts and CSS */ -}}
|
||||
{{- partial "assets.html" . -}}
|
||||
</body>
|
||||
</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 -}}
|
||||
|
||||
|
||||
@@ -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 */ -}}
|
||||
6
layouts/partials/function/id.html
Normal file
6
layouts/partials/function/id.html
Normal file
@@ -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 -}}
|
||||
@@ -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 -}}
|
||||
{{- . -}}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 -}}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 -}}
|
||||
|
||||
|
||||
@@ -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 -}}
|
||||
|
||||
|
||||
@@ -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 -}}
|
||||
|
||||
|
||||
@@ -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) -}}
|
||||
6
layouts/shortcodes/echarts.html
Normal file
6
layouts/shortcodes/echarts.html
Normal file
@@ -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" -}}
|
||||
@@ -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" -}}
|
||||
|
||||
@@ -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 ` ` " " $content | replaceRE `(<\w+) ` "$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 -}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user