Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
chore: refactor some code
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonzq committed May 18, 2020
1 parent c1016df commit 8f53c99
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 90 deletions.
2 changes: 1 addition & 1 deletion layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h2 class="single-subtitle">{{ . }}</h2>

{{- /* Content */ -}}
<div class="content" id="content">
{{- dict "content" .Content "ruby" $params.ruby "fraction" $params.fraction "fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
{{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
</div>

{{- /* Comment */ -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h1 class="single-title" itemprop="name headline">
{{- /* Summary content */ -}}
<div class="content">
{{- with .Summary -}}
{{- dict "content" . "ruby" $params.ruby "fraction" $params.fraction "fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
{{- dict "Content" . "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
{{- else -}}
{{- .Description | safeHTML -}}
{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{- if .Content -}}
<div class="single">
<div class="content" id="content">
{{- dict "content" .Content "ruby" $params.ruby "fraction" $params.fraction "fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
{{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
</div>
</div>
{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{{- end -}}
{{- $params := .Params | merge $.Site.Params.page -}}
{{/* Extended Markdown syntax */}}
{{- $content := dict "content" .Content "ruby" $params.ruby "fraction" $params.fraction "fontawesome" $params.fontawesome | partial "function/content.html" -}}
{{- $content := dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" -}}
{{/* Remove line number for code */}}
{{- $content = $content | replaceRE `<span class="lnt?"> *\d*\n?</span>` "" -}}
{{- range $i, $contenti := split $content "<h2 id=" -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/index.rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
{{ end }}
{{- range where .Site.RegularPages "Type" "posts" | first (.Site.Params.home.rss | default 10) -}}
{{- dict "page" . "site" .Site | partial "rss/item.html" -}}
{{- dict "Page" . "Site" .Site | partial "rss/item.html" -}}
{{- end -}}
</channel>
</rss>
80 changes: 40 additions & 40 deletions layouts/partials/assets.html

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions layouts/partials/comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{- if $disqus.enable -}}
<div id="disqus_thread" class="comment"></div>
{{- $source := printf "https://%v.disqus.com/embed.js" $disqus.shortname -}}
{{- dict "source" $source "defer" true | dict "scratch" .Scratch "data" | partial "scratch/script.html" -}}
{{- dict "source" $source "defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
<noscript>
Please enable JavaScript to view the comments powered by <a href="https://disqus.com/?ref_noscript">Disqus</a>.
</noscript>
Expand All @@ -21,9 +21,9 @@
{{- if $gitalk.enable -}}
<div id="gitalk" class="comment"></div>
{{- $source := $cdn.gitalkCSS | default "lib/gitalk/gitalk.css" -}}
{{- dict "source" $source "minify" true "fingerprint" $fingerprint | dict "scratch" .Scratch "data" | partial "scratch/style.html" -}}
{{- dict "source" $source "minify" true "fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}}
{{- $source := $cdn.gitalkJS | default "lib/gitalk/gitalk.min.js" -}}
{{- dict "source" $source "fingerprint" $fingerprint | dict "scratch" .Scratch "data" | partial "scratch/script.html" -}}
{{- dict "source" $source "fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- $commentConfig = dict "id" .Date "title" .Title "clientID" $gitalk.clientId "clientSecret" $gitalk.clientSecret "repo" $gitalk.repo "owner" $gitalk.owner "admin" (slice $gitalk.owner) | dict "gitalk" | merge $commentConfig -}}
<noscript>
Please enable JavaScript to view the comments powered by <a href="https://github.com/gitalk/gitalk"></a>Gitalk</a>.
Expand All @@ -35,9 +35,9 @@
{{- if $valine.enable -}}
<div id="valine" class="comment"></div>
{{- $options := dict "targetPath" "lib/valine/valine.min.css" -}}
{{- dict "source" "lib/valine/valine.scss" "toCSS" $options | dict "scratch" .Scratch "data" | partial "scratch/style.html" -}}
{{- dict "source" "lib/valine/valine.scss" "toCSS" $options | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}}
{{- $source := $cdn.valineJS | default "lib/valine/Valine.min.js" -}}
{{- dict "source" $source "fingerprint" $fingerprint | dict "scratch" .Scratch "data" | partial "scratch/script.html" -}}
{{- dict "source" $source "fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- $commentConfig = dict "el" "#valine" "appId" $valine.appId "appKey" $valine.appKey "lang" ($valine.lang | default (T "valineLang")) "visitor" $valine.visitor "recordIP" $valine.recordIP "placeholder" ($valine.placeholder | default (T "valinePlaceholder")) "highlight" (ne $valine.highlight false) "enableQQ" $valine.enableQQ | dict "valine" | merge $commentConfig -}}
{{- with $valine.avatar -}}
{{- $commentConfig = dict "avatar" . | dict "valine" | merge $commentConfig -}}
Expand Down Expand Up @@ -68,7 +68,7 @@
data-numposts="{{ $facebook.numPosts }}"
></div>
{{- $source := printf "https://connect.facebook.net/%v/sdk.js#xfbml=1&version=v5.0&appId=%v&autoLogAppEvents=1" ($facebook.languageCode | default (T "facebookLanguageCode")) $facebook.appId -}}
{{- dict "source" $source "defer" true | dict "scratch" .Scratch "data" | partial "scratch/script.html" -}}
{{- dict "source" $source "defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
<noscript>
Please enable JavaScript to view the comments powered by <a href="https://developers.facebook.com/docs/plugins/comments/"></a>Facebook</a>.
</noscript>
Expand All @@ -95,7 +95,7 @@
{{- if $telegram.outlined -}}
{{- $attr = printf `%v data-outlined="1"` $attr -}}
{{- end -}}
{{- dict "source" "https://comments.app/js/widget.js?2" "defer" true "attr" $attr | dict "scratch" .Scratch "data" | partial "scratch/script.html" -}}
{{- dict "source" "https://comments.app/js/widget.js?2" "defer" true "attr" $attr | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
<noscript>
Please enable JavaScript to view the comments powered by <a href="https://comments.app/">Telegram Comments</a>.
</noscript>
Expand All @@ -105,7 +105,7 @@
{{- $commento := $comment.commento | default dict -}}
{{- if $commento.enable -}}
<div id="commento"></div>
{{- dict "source" "https://cdn.commento.io/js/commento.js" "defer" true | dict "scratch" .Scratch "data" | partial "scratch/script.html" -}}
{{- dict "source" "https://cdn.commento.io/js/commento.js" "defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
<noscript>
Please enable JavaScript to view the comments powered by <a href="https://commento.io/">Commento</a>.
</noscript>
Expand Down
8 changes: 4 additions & 4 deletions layouts/partials/function/content.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{{- $content := .content -}}
{{- $content := .Content -}}

{{- if .ruby -}}
{{- if .Ruby -}}
{{- $content = partial "function/ruby.html" $content -}}
{{- end -}}

{{- if .fraction -}}
{{- if .Fraction -}}
{{- $content = partial "function/fraction.html" $content -}}
{{- end -}}

{{- if .fontawesome -}}
{{- if .Fontawesome -}}
{{- $content = partial "function/fontawesome.html" $content -}}
{{- end -}}

Expand Down
8 changes: 4 additions & 4 deletions layouts/partials/function/id.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{- /* ID */ -}}
{{- $count := (.scratch.Get "this").count | default 1 -}}
{{- $count := (.Scratch.Get "this").count | default 1 -}}
{{- $id := printf "id-%d" $count -}}
{{- $count | add 1 | .scratch.SetInMap "this" "count" -}}
{{- with .content -}}
{{- dict $id . | dict "data" | dict "config" | merge ($.scratch.Get "this") | $.scratch.Set "this" -}}
{{- $count | add 1 | .Scratch.SetInMap "this" "count" -}}
{{- with .Content -}}
{{- dict $id . | dict "data" | dict "config" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}}
{{- end -}}
{{- return $id -}}
4 changes: 2 additions & 2 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<span class="header-title-pre">{{ . | safeHTML }}</span>
{{- end -}}
{{- if .typeit -}}
{{- $id := dict "content" .name "scratch" $.Scratch | partial "function/id.html" -}}
{{- $id := dict "Content" .name "Scratch" $.Scratch | partial "function/id.html" -}}
<span id="{{ $id }}" class="typeit"></span>
{{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}}
{{- else -}}
Expand Down Expand Up @@ -95,7 +95,7 @@
<span class="header-title-pre">{{ . | safeHTML }}</span>
{{- end -}}
{{- if .typeit -}}
{{- $id := dict "content" .name "scratch" $.Scratch | partial "function/id.html" -}}
{{- $id := dict "Content" .name "Scratch" $.Scratch | partial "function/id.html" -}}
<span id="{{ $id }}" class="typeit"></span>
{{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}}
{{- else -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/home/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h1 class="home-title">
{{- with $profile.subtitle -}}
<h2 class="home-subtitle">
{{- if $profile.typeit -}}
{{- $id := dict "content" . "scratch" $.Scratch | partial "function/id.html" -}}
{{- $id := dict "Content" . "Scratch" $.Scratch | partial "function/id.html" -}}
<div id="{{ $id }}" class="typeit"></div>
{{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}}
{{- else -}}
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/plugin/compatibility.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
{{- end -}}
{{- end -}}
{{- with $features | uniq -}}
{{- delimit . "%2C" | printf "https://polyfill.io/v3/polyfill.min.js?features=%v" | dict "source" | dict "scratch" $.Scratch "data" | partial "scratch/script.html" -}}
{{- delimit . "%2C" | printf "https://polyfill.io/v3/polyfill.min.js?features=%v" | dict "source" | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
{{- end -}}
{{- end -}}

{{- /* object-fit-images */ -}}
{{- if $compatibility.objectFit -}}
{{- $source := $cdn.objectFitImagesJS | default "lib/object-fit-images/ofi.min.js" -}}
{{- dict "source" $source "fingerprint" $fingerprint | dict "scratch" .Scratch "data" | partial "scratch/script.html" -}}
{{- dict "source" $source "fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- end -}}
18 changes: 9 additions & 9 deletions layouts/partials/rss/item.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{{- $params := .page.Params | merge .site.Params.page | merge (dict "author" .site.Author.name) -}}
{{- $params := .Page.Params | merge .Site.Params.Page | merge (dict "author" .Site.Author.name) -}}
<item>
<title>
{{- .page.Title -}}
{{- .Page.Title -}}
</title>
<link>
{{- .page.Permalink -}}
{{- .Page.Permalink -}}
</link>
<pubDate>
{{- .page.Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}}
{{- .Page.Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}}
</pubDate>
<author>
{{- .params.author | default (T "author") -}}
</author>
<guid>
{{- .page.Permalink -}}
{{- .Page.Permalink -}}
</guid>
<description>
{{- "<![CDATA[" | safeHTML -}}
Expand All @@ -22,12 +22,12 @@
<img src="{{ . | relURL }}" referrerpolicy="no-referrer">
</div>
{{- end -}}
{{- $content := .page.Description -}}
{{- $content := .Page.Description -}}
{{- if $params.rssFullText -}}
{{- $content = dict "content" .page.Content "ruby" $params.ruby "fraction" $params.fraction "fontawesome" $params.fontawesome | partial "function/content.html" -}}
{{- $content = dict "Content" .Page.Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" -}}
{{- else -}}
{{- with .page.Summary -}}
{{- $content = dict "content" . "ruby" $params.ruby "fraction" $params.fraction "fontawesome" $params.fontawesome | partial "function/content.html" -}}
{{- with .Page.Summary -}}
{{- $content = dict "Content" . "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" -}}
{{- end -}}
{{- end -}}
{{- $content | replaceRE `<figure[^>]*>.*</figure>` "" | replaceRE `<img[^>]*( /)?>` "" | safeHTML -}}
Expand Down
6 changes: 3 additions & 3 deletions layouts/partials/scratch/script.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- $this := .scratch.Get "this" -}}
{{- $this := .Scratch.Get "this" -}}
{{- $script := $this.script | default slice -}}
{{- $script = $script | append (slice .data) -}}
{{- .scratch.SetInMap "this" "script" $script -}}
{{- $script = $script | append (slice .Data) -}}
{{- .Scratch.SetInMap "this" "script" $script -}}
6 changes: 3 additions & 3 deletions layouts/partials/scratch/style.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- $this := .scratch.Get "this" -}}
{{- $this := .Scratch.Get "this" -}}
{{- $style := $this.style | default slice -}}
{{- $style = $style | append (slice .data) -}}
{{- .scratch.SetInMap "this" "style" $style -}}
{{- $style = $style | append (slice .Data) -}}
{{- .Scratch.SetInMap "this" "style" $style -}}
2 changes: 1 addition & 1 deletion layouts/posts/rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{{- end -}}
<atom:link href="{{ .Permalink }}" rel="self" type="application/rss+xml" />
{{- range .Pages | first (.Site.Params.section.rss | default 10) -}}
{{- dict "page" . "site" .Site | partial "rss/item.html" -}}
{{- dict "Page" . "Site" .Site | partial "rss/item.html" -}}
{{- end -}}
</channel>
</rss>
4 changes: 2 additions & 2 deletions layouts/posts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ <h2 class="single-subtitle">{{ . }}</h2>
<span><i class="details-icon fas fa-angle-right"></i></span>
</div>
<div class="details-content toc-content" id="toc-content-static">
{{- dict "content" .TableOfContents "ruby" $params.ruby "fraction" $params.fraction "fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
{{- dict "Content" .TableOfContents "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
</div>
</div>
{{- end -}}

{{- /* Content */ -}}
<div class="content" id="content">
{{- dict "content" .Content "ruby" $params.ruby "fraction" $params.fraction "fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
{{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
</div>

{{- /* Footer */ -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/shortcodes/echarts.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- $content := .Inner | transform.Unmarshal | jsonify -}}
{{- $id := dict "content" $content "scratch" .Page.Scratch | partial "function/id.html" -}}
{{- $id := dict "Content" $content "Scratch" .Page.Scratch | partial "function/id.html" -}}
{{- $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>
Expand Down
2 changes: 1 addition & 1 deletion layouts/shortcodes/mapbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 := dict "content" $options "scratch" .Page.Scratch | partial "function/id.html" -}}
{{- $id := dict "Content" $options "Scratch" .Page.Scratch | partial "function/id.html" -}}
<div class="mapbox" id="{{ $id }}" style="width: {{ $width }}; height: {{ $height }};"></div>
{{- .Page.Scratch.SetInMap "this" "mapbox" true -}}
2 changes: 1 addition & 1 deletion layouts/shortcodes/mermaid.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{- $id := dict "content" (trim .Inner "\n") "scratch" .Page.Scratch | partial "function/id.html" -}}
{{- $id := dict "Content" (trim .Inner "\n") "Scratch" .Page.Scratch | partial "function/id.html" -}}
<div class="mermaid" id="{{ $id }}"></div>
{{- .Page.Scratch.SetInMap "this" "mermaid" true -}}
2 changes: 1 addition & 1 deletion layouts/shortcodes/style.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- $content := .Inner | .Page.RenderString -}}
{{- $id := dict "scratch" .Page.Scratch | partial "function/id.html" -}}
{{- $id := dict "Scratch" .Page.Scratch | partial "function/id.html" -}}
{{- $tag := .Get 1 | default "div" -}}
{{- printf `<%v id="%v">%v</%v>` $tag $id $content $tag | safeHTML -}}

Expand Down
2 changes: 1 addition & 1 deletion layouts/shortcodes/typeit.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{{- end -}}

{{- /* trim the newline */ -}}
{{- $id := dict "content" $content "scratch" .Page.Scratch | partial "function/id.html" -}}
{{- $id := dict "Content" $content "Scratch" .Page.Scratch | partial "function/id.html" -}}
{{- $key := .Get "group" | string | default $id -}}
{{- $typeitMap := (.Page.Scratch.Get "this").typeitMap | default dict -}}
{{- $group := index $typeitMap $key -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/taxonomy/rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{{- end -}}
<atom:link href="{{ .Permalink }}" rel="self" type="application/rss+xml" />
{{- range .Pages | first (.Site.Params.list.rss | default 10) -}}
{{- dict "page" . "site" .Site | partial "rss/item.html" -}}
{{- dict "Page" . "Site" .Site | partial "rss/item.html" -}}
{{- end -}}
</channel>
</rss>

0 comments on commit 8f53c99

Please sign in to comment.