style(*): google js style & trim whitespace

This commit is contained in:
olOwOlo 2018-07-10 01:41:34 +08:00
parent d3a1ab071c
commit 5e356c5f63
No known key found for this signature in database
GPG key ID: 456394B6E7A15EA6
17 changed files with 362 additions and 357 deletions

View file

@ -1,6 +1,6 @@
{{ define "title" }}404 page not found - {{ .Site.Title }}{{ end }} {{- define "title" }}404 page not found - {{ .Site.Title }}{{ end -}}
{{ define "content" }} {{- define "content" -}}
<div class="not-found"> <div class="not-found">
<h1 class="error-emoji"></h1> <h1 class="error-emoji"></h1>
<p class="error-text">/* 404 page not found. */</p> <p class="error-text">/* 404 page not found. */</p>
@ -15,4 +15,4 @@
var errorEmoji = emojiArray[Math.floor(Math.random() * emojiArray.length)]; var errorEmoji = emojiArray[Math.floor(Math.random() * emojiArray.length)];
errorEmojiContainer.appendChild(document.createTextNode(errorEmoji)); errorEmojiContainer.appendChild(document.createTextNode(errorEmoji));
</script> </script>
{{ end }} {{- end -}}

View file

@ -1,6 +1,6 @@
{{ define "title" }}{{ T "archive" }} - {{ .Site.Title }}{{ end }} {{- define "title" }}{{ T "archive" }} - {{ .Site.Title }}{{ end -}}
{{ define "content"}} {{- define "content" }}
{{- $paginator := .Paginate .Data.Pages.ByDate.Reverse .Site.Params.archivePaginate }} {{- $paginator := .Paginate .Data.Pages.ByDate.Reverse .Site.Params.archivePaginate }}
<section id="archive" class="archive"> <section id="archive" class="archive">
{{- if and (not $paginator.HasPrev) .Site.Params.showArchiveCount }} {{- if and (not $paginator.HasPrev) .Site.Params.showArchiveCount }}
@ -14,7 +14,7 @@
{{- range $index, $element := $paginator.Pages -}} {{- range $index, $element := $paginator.Pages -}}
{{- $thisYear := $element.Date.Format "2006" }} {{- $thisYear := $element.Date.Format "2006" }}
{{- $lastElement := $index | add -1 | index $paginator.Pages }} {{- $lastElement := $index | add -1 | index $paginator.Pages }}
{{ if or (eq $index 0) ( ne ($lastElement.Date.Format "2006") $thisYear ) }} {{- if or (eq $index 0) ( ne ($lastElement.Date.Format "2006") $thisYear ) }}
<div class="collection-title"> <div class="collection-title">
<h2 class="archive-year">{{ $thisYear }}</h2> <h2 class="archive-year">{{ $thisYear }}</h2>
</div> </div>
@ -47,4 +47,4 @@
</a> </a>
{{- end }} {{- end }}
</nav> </nav>
{{ end }} {{- end }}

View file

@ -1,21 +1,21 @@
{{ define "title" }}{{ .Title }} · {{ .Site.Title }}{{ end }} {{- define "title" }}{{ .Title }} · {{ .Site.Title }}{{ end -}}
{{ define "content"}} {{- define "content" }}
{{ $paginator := .Paginate .Data.Pages.ByDate.Reverse .Site.Params.archivePaginate }} {{- $paginator := .Paginate .Data.Pages.ByDate.Reverse .Site.Params.archivePaginate -}}
<section id="archive" class="archive"> <section id="archive" class="archive">
{{ if not $paginator.HasPrev }} {{ if not $paginator.HasPrev -}}
{{ if eq .Data.Plural "tags" }} {{ if eq .Data.Plural "tags" -}}
<div class="archive-title tag"> <div class="archive-title tag">
<h2 class="archive-name">{{ .Title }}</h2> <h2 class="archive-name">{{ .Title }}</h2>
</div> </div>
{{ else if eq .Data.Plural "categories" }} {{- else if eq .Data.Plural "categories" -}}
<div class="archive-title category"> <div class="archive-title category">
<h2 class="archive-name">{{ .Title }}</h2> <h2 class="archive-name">{{ .Title }}</h2>
</div> </div>
{{ end }} {{- end }}
{{ end }} {{- end }}
{{ range $paginator.Pages }} {{ range $paginator.Pages -}}
<div class="archive-post"> <div class="archive-post">
<span class="archive-post-time"> <span class="archive-post-time">
{{ .Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }} {{ .Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }}
@ -26,21 +26,21 @@
</a> </a>
</span> </span>
</div> </div>
{{ end }} {{- end }}
</section> </section>
<!-- pagination --> <!-- pagination -->
<nav class="pagination"> <nav class="pagination">
{{ with $paginator.Prev }} {{ with $paginator.Prev -}}
<a class="prev" href="{{ .URL }}"> <a class="prev" href="{{ .URL }}">
<i class="iconfont icon-left"></i> <i class="iconfont icon-left"></i>
<span class="prev-text">{{ T "prevPage" }}</span> <span class="prev-text">{{ T "prevPage" }}</span>
</a> </a>
{{- end }} {{- end }}
{{ with $paginator.Next }} {{ with $paginator.Next -}}
<a class="next" href="{{ .URL }}"> <a class="next" href="{{ .URL }}">
<span class="next-text">{{ T "nextPage" }}</span> <span class="next-text">{{ T "nextPage" }}</span>
<i class="iconfont icon-right"></i> <i class="iconfont icon-right"></i>
</a> </a>
{{- end }} {{- end }}
</nav> </nav>
{{ end }} {{- end }}

View file

@ -1,44 +1,44 @@
{{ define "title" }}{{ T .Data.Plural }} - {{ .Site.Title }}{{ end }} {{- define "title" }}{{ T .Data.Plural }} - {{ .Site.Title }}{{ end -}}
{{ define "content" }} {{- define "content" -}}
{{ $name := .Data.Plural -}} {{ $name := .Data.Plural -}}
{{ $terms := .Data.Terms.ByCount -}} {{ $terms := .Data.Terms.ByCount -}}
{{ $length := len $terms -}} {{ $length := len $terms -}}
{{ if eq $name "categories" }} {{ if eq $name "categories" -}}
<div class="categories"> <div class="categories">
<div class="categories-title"> <div class="categories-title">
{{ if eq $length 0 }} {{ if eq $length 0 -}}
{{ T "zeroCategoryCounter" }} {{ T "zeroCategoryCounter" }}
{{ else }} {{- else -}}
{{ T "categoryCounter" $length }} {{ T "categoryCounter" $length }}
{{ end }} {{- end }}
</div> </div>
<div class="categories-tags"> <div class="categories-tags">
{{ range $key, $value := $terms }} {{ range $key, $value := $terms -}}
<a class="category-link" href="{{ $name | relLangURL }}/{{ $value.Term | urlize }}/"> <a class="category-link" href="{{ $name | relLangURL }}/{{ $value.Term | urlize }}/">
{{ $value.Term }} {{ $value.Term }}
<span class="category-count">{{ len $value.Pages }}</span> <span class="category-count">{{ len $value.Pages }}</span>
</a> </a>
{{ end }} {{ end -}}
</div> </div>
</div> </div>
{{ else if eq $name "tags" }} {{- else if eq $name "tags" -}}
<div class="tag-cloud"> <div class="tag-cloud">
<div class="tag-cloud-title"> <div class="tag-cloud-title">
{{ if eq $length 0 }} {{ if eq $length 0 -}}
{{ T "zeroTagCounter" }} {{ T "zeroTagCounter" }}
{{ else }} {{- else -}}
{{ T "tagCounter" $length }} {{ T "tagCounter" $length }}
{{ end }} {{- end }}
</div> </div>
<div class="tag-cloud-tags"> <div class="tag-cloud-tags">
{{ range $key, $value := $terms }} {{- range $key, $value := $terms }}
<a href="{{ $name | relLangURL }}/{{ $value.Term | urlize }}/"> <a href="{{ $name | relLangURL }}/{{ $value.Term | urlize }}/">
{{ $value.Term }} {{ $value.Term }}
<span class="tag-count">{{ len $value.Pages }}</span> <span class="tag-count">{{ len $value.Pages }}</span>
</a> </a>
{{ end }} {{ end -}}
</div> </div>
</div> </div>
{{ end }} {{- end }}
{{ end }} {{- end }}

View file

@ -1,24 +1,24 @@
{{ define "content" }} {{- define "content" -}}
<section id="posts" class="posts"> <section id="posts" class="posts">
{{/* (index .Site.Paginate) */}} {{/* (index .Site.Paginate) */}}
{{ $paginator := .Paginate (where (where .Data.Pages "Type" "post") ".Params.hiddenfromhomepage" "!=" true) }} {{- $paginator := .Paginate (where (where .Data.Pages "Type" "post") ".Params.hiddenfromhomepage" "!=" true) }}
{{ range $paginator.Pages }} {{- range $paginator.Pages -}}
{{ .Render "summary" }} {{ .Render "summary" }}
{{ end }} {{ end -}}
</section> </section>
<!-- pagination --> <!-- pagination -->
<nav class="pagination"> <nav class="pagination">
{{ with $paginator.Prev }} {{ with $paginator.Prev -}}
<a class="prev" href="{{ .URL }}"> <a class="prev" href="{{ .URL }}">
<i class="iconfont icon-left"></i> <i class="iconfont icon-left"></i>
<span class="prev-text">{{ T "prevPage" }}</span> <span class="prev-text">{{ T "prevPage" }}</span>
</a> </a>
{{- end }} {{- end }}
{{ with $paginator.Next }} {{ with $paginator.Next -}}
<a class="next" href="{{ .URL }}"> <a class="next" href="{{ .URL }}">
<span class="next-text">{{ T "nextPage" }}</span> <span class="next-text">{{ T "nextPage" }}</span>
<i class="iconfont icon-right"></i> <i class="iconfont icon-right"></i>
</a> </a>
{{- end }} {{- end }}
</nav> </nav>
{{ end }} {{- end -}}

View file

@ -1,4 +1,4 @@
{{ if and .IsPage (ne .Params.comment false) }} {{ if and .IsPage (ne .Params.comment false) -}}
<!-- Disqus --> <!-- Disqus -->
{{- if .Site.DisqusShortname -}} {{- if .Site.DisqusShortname -}}
<div id="disqus_thread"></div> <div id="disqus_thread"></div>
@ -63,7 +63,7 @@
<script src="{{ "lib/gitment/gitment-0.0.3.min.js" | relURL }}"></script> <script src="{{ "lib/gitment/gitment-0.0.3.min.js" | relURL }}"></script>
{{- end }} {{- end }}
<script type="text/javascript"> <script type="text/javascript">
const gitment = new Gitment({ var gitment = new Gitment({
id: '{{ .Date }}', id: '{{ .Date }}',
title: '{{ .Title }}', title: '{{ .Title }}',
link: decodeURI(location.href), link: decodeURI(location.href),
@ -74,11 +74,11 @@
client_id: '{{ .Site.Params.gitment.clientId }}', client_id: '{{ .Site.Params.gitment.clientId }}',
client_secret: '{{ .Site.Params.gitment.clientSecret }}' client_secret: '{{ .Site.Params.gitment.clientSecret }}'
} }
}) });
gitment.render('comments-gitment') gitment.render('comments-gitment');
</script> </script>
<noscript>Please enable JavaScript to view the <a href="https://github.com/imsun/gitment">comments powered by gitment.</a></noscript> <noscript>Please enable JavaScript to view the <a href="https://github.com/imsun/gitment">comments powered by gitment.</a></noscript>
{{- end }} {{- end -}}
<!-- gitalk --> <!-- gitalk -->
{{- if .Site.Params.gitalk.owner -}} {{- if .Site.Params.gitalk.owner -}}

View file

@ -40,7 +40,7 @@
<span class="copyright-year"> <span class="copyright-year">
{{- $current := now.Format "2006" }} {{- $current := now.Format "2006" }}
&copy; &copy;
{{ if ne .Site.Params.since $current }} {{ if ne .Site.Params.since $current -}}
{{ .Site.Params.since }} - {{ .Site.Params.since }} -
{{ end }} {{ end }}
{{- $current }} {{- $current }}

View file

@ -14,16 +14,16 @@
{{- if .Description -}} {{- if .Description -}}
<meta name="description" content="{{ .Description | safeHTML }}" /> <meta name="description" content="{{ .Description | safeHTML }}" />
{{ else if .IsPage }} {{- else if .IsPage -}}
<meta name="description" content="{{ .Summary | plainify }}" /> <meta name="description" content="{{ .Summary | plainify }}" />
{{ else if .Site.Params.description }} {{- else if .Site.Params.description -}}
<meta name="description" content="{{ .Site.Params.description | safeHTML }}" /> <meta name="description" content="{{ .Site.Params.description | safeHTML }}" />
{{- end -}} {{- end -}}
{{- if .Keywords -}} {{- if .Keywords -}}
{{ $length := len .Keywords | add -1 -}} {{ $length := len .Keywords | add -1 -}}
<meta name="keywords" content="{{ range $index, $element := .Keywords }}{{ $element | safeHTML }}{{if ne $index $length }}, {{ end }}{{ end }}" /> <meta name="keywords" content="{{ range $index, $element := .Keywords }}{{ $element | safeHTML }}{{if ne $index $length }}, {{ end }}{{ end }}" />
{{ else if .Site.Params.keywords }} {{- else if .Site.Params.keywords -}}
{{ $length := len .Site.Params.keywords | add -1 -}} {{ $length := len .Site.Params.keywords | add -1 -}}
<meta name="keywords" content="{{ range $index, $element := .Site.Params.keywords }}{{ $element | safeHTML }}{{if ne $index $length }}, {{ end }}{{ end }}" /> <meta name="keywords" content="{{ range $index, $element := .Site.Params.keywords }}{{ $element | safeHTML }}{{if ne $index $length }}, {{ end }}{{ end }}" />
{{- end }} {{- end }}
@ -37,10 +37,10 @@
<!-- Permalink & RSSlink --> <!-- Permalink & RSSlink -->
<link rel="canonical" href="{{ .Permalink }}" /> <link rel="canonical" href="{{ .Permalink }}" />
{{ if .RSSLink -}} {{- if .RSSLink }}
<link href="{{ .RSSLink }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" /> <link href="{{ .RSSLink }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" />
<link href="{{ .RSSLink }}" rel="feed" type="application/rss+xml" title="{{ .Site.Title }}" /> <link href="{{ .RSSLink }}" rel="feed" type="application/rss+xml" title="{{ .Site.Title }}" />
{{ end -}} {{- end -}}
<!-- Favicon and Touch icons --> <!-- Favicon and Touch icons -->
<link rel="apple-touch-icon" sizes="180x180" href="{{ "apple-touch-icon.png" | relURL }}"> <link rel="apple-touch-icon" sizes="180x180" href="{{ "apple-touch-icon.png" | relURL }}">
@ -50,15 +50,15 @@
<link rel="mask-icon" href="{{ "safari-pinned-tab.svg" | relURL }}" color="#5bbad5"> <link rel="mask-icon" href="{{ "safari-pinned-tab.svg" | relURL }}" color="#5bbad5">
<!-- debug --> <!-- debug -->
{{- if .Site.Params.debug }} {{- if .Site.Params.debug -}}
<script src="https://cdn.jsdelivr.net/npm/eruda@1.2.6/eruda.min.js" integrity="sha256-Jmz4bc3kp+rRrXX2tGadNBKFLwtzMapr8kHABxSAAP8=" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/eruda@1.2.6/eruda.min.js" integrity="sha256-Jmz4bc3kp+rRrXX2tGadNBKFLwtzMapr8kHABxSAAP8=" crossorigin="anonymous"></script>
<script>eruda.init();</script> <script>eruda.init();</script>
{{- end }} {{- end -}}
<!-- busuanzi --> <!-- busuanzi -->
{{ if .Site.Params.busuanzi.enable -}} {{- if .Site.Params.busuanzi.enable -}}
<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script> <script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
{{- end }} {{- end -}}
<!-- Styles --> <!-- Styles -->
<link href="{{ print "dist/" .Site.Data.even.assets.even.css | relURL }}" rel="stylesheet"> <link href="{{ print "dist/" .Site.Data.even.assets.even.css | relURL }}" rel="stylesheet">
@ -66,10 +66,10 @@
{{ if .Site.Params.fancybox }}{{ .Site.Params.publicCDN.fancyboxCSS | safeHTML }}{{ end }} {{ if .Site.Params.fancybox }}{{ .Site.Params.publicCDN.fancyboxCSS | safeHTML }}{{ end }}
{{- else -}} {{- else -}}
{{ if .Site.Params.fancybox }}<link href="{{ "lib/fancybox/jquery.fancybox-3.1.20.min.css" | relURL }}" rel="stylesheet">{{ end }} {{ if .Site.Params.fancybox }}<link href="{{ "lib/fancybox/jquery.fancybox-3.1.20.min.css" | relURL }}" rel="stylesheet">{{ end }}
{{- end }} {{- end -}}
<!-- custom css --> <!-- custom css -->
{{ range .Site.Params.customCSS }} {{ range .Site.Params.customCSS -}}
<link rel="stylesheet" href="{{ "/css/" | relURL }}{{ . }}"> <link rel="stylesheet" href="{{ "/css/" | relURL }}{{ . }}">
{{ end }} {{ end }}

View file

@ -1,16 +1,16 @@
{{ if or .Params.reward (and .Site.Params.reward.enable (ne .Params.reward false)) }} {{ if or .Params.reward (and .Site.Params.reward.enable (ne .Params.reward false)) -}}
<div class="post-reward"> <div class="post-reward">
<input type="checkbox" name="reward" id="reward" hidden /> <input type="checkbox" name="reward" id="reward" hidden />
<label class="reward-button" for="reward">{{ T "reward" }}</label> <label class="reward-button" for="reward">{{ T "reward" }}</label>
<div class="qr-code"> <div class="qr-code">
{{ $qrCode := .Site.Params.reward }} {{ $qrCode := .Site.Params.reward }}
{{ with $qrCode.wechat }} {{ with $qrCode.wechat -}}
<label class="qr-code-image" for="reward"> <label class="qr-code-image" for="reward">
<img class="image" src="{{ . }}"> <img class="image" src="{{ . }}">
<span>{{ T "rewardWechat" }}</span> <span>{{ T "rewardWechat" }}</span>
</label> </label>
{{- end }} {{- end }}
{{ with $qrCode.alipay }} {{ with $qrCode.alipay -}}
<label class="qr-code-image" for="reward"> <label class="qr-code-image" for="reward">
<img class="image" src="{{ . }}"> <img class="image" src="{{ . }}">
<span>{{ T "rewardAlipay" }}</span> <span>{{ T "rewardAlipay" }}</span>

View file

@ -1,7 +1,7 @@
{{ if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) }} {{ if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) -}}
<div class="post-toc" id="post-toc"> <div class="post-toc" id="post-toc">
<h2 class="post-toc-title">{{ T "toc" }}</h2> <h2 class="post-toc-title">{{ T "toc" }}</h2>
{{ $globalAutoCollapseToc := .Site.Params.autoCollapseToc | default false }} {{- $globalAutoCollapseToc := .Site.Params.autoCollapseToc | default false }}
<div class="post-toc-content{{ if not (or .Params.autoCollapseToc (and $globalAutoCollapseToc (ne .Params.autoCollapseToc false))) }} always-active{{ end }}"> <div class="post-toc-content{{ if not (or .Params.autoCollapseToc (and $globalAutoCollapseToc (ne .Params.autoCollapseToc false))) }} always-active{{ end }}">
{{.TableOfContents}} {{.TableOfContents}}
</div> </div>

View file

@ -23,12 +23,12 @@
<script type="text/javascript" src="{{ "lib/timeago/timeago-3.0.2.min.js" | relURL }}"></script> <script type="text/javascript" src="{{ "lib/timeago/timeago-3.0.2.min.js" | relURL }}"></script>
<script type="text/javascript" src="{{ "lib/timeago/timeago.locales-3.0.2.min.js" | relURL }}"></script> <script type="text/javascript" src="{{ "lib/timeago/timeago.locales-3.0.2.min.js" | relURL }}"></script>
{{- end }} {{- end }}
<script> // NOTE: timeago.js uses the language code format like "zh_CN" (underscore and case sensitive) <script><!-- NOTE: timeago.js uses the language code format like "zh_CN" (underscore and case sensitive) -->
var languageCode = {{ .Site.LanguageCode }}.replace(/-/g, '_').replace(/_(.*)/, function ($0, $1) {return $0.replace($1, $1.toUpperCase());}); var languageCode = {{ .Site.LanguageCode }}.replace(/-/g, '_').replace(/_(.*)/, function ($0, $1) {return $0.replace($1, $1.toUpperCase());});
timeago().render(document.querySelectorAll('.timeago'), languageCode); timeago().render(document.querySelectorAll('.timeago'), languageCode);
timeago.cancel(); // stop update timeago.cancel(); // stop update
</script> </script>
{{- end }} {{- end -}}
<!-- flowchart --> <!-- flowchart -->
{{- if and (or .Params.flowchartDiagrams.enable (and .Site.Params.flowchartDiagrams.enable (ne .Params.flowchartDiagrams.enable false))) (or .IsPage .IsHome) -}} {{- if and (or .Params.flowchartDiagrams.enable (and .Site.Params.flowchartDiagrams.enable (ne .Params.flowchartDiagrams.enable false))) (or .IsPage .IsHome) -}}

View file

@ -8,12 +8,12 @@
<span class="post-time"> {{ .Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }} </span> <span class="post-time"> {{ .Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }} </span>
{{ with .Params.categories -}} {{ with .Params.categories -}}
<div class="post-category"> <div class="post-category">
{{ range . }} {{ range . -}}
<a href="{{ "categories" | relLangURL }}/{{ . | urlize }}/"> {{ . }} </a> <a href="{{ "categories" | relLangURL }}/{{ . | urlize }}/"> {{ . }} </a>
{{ end }} {{ end -}}
</div> </div>
{{- end }} {{- end }}
{{ if .Site.Params.moreMeta -}} {{- if .Site.Params.moreMeta }}
<span class="more-meta"> {{ T "wordCount" .WordCount }} </span> <span class="more-meta"> {{ T "wordCount" .WordCount }} </span>
<span class="more-meta"> {{ T "readingTime" .ReadingTime }} </span> <span class="more-meta"> {{ T "readingTime" .ReadingTime }} </span>
{{- end }} {{- end }}
@ -25,10 +25,10 @@
</header> </header>
<!-- TOC --> <!-- TOC -->
{{ partial "post/toc.html" . }} {{- partial "post/toc.html" . -}}
<!-- Outdated Info Warning --> <!-- Outdated Info Warning -->
{{ partial "post/outdated-info-warning.html" . }} {{- partial "post/outdated-info-warning.html" . -}}
<!-- Content --> <!-- Content -->
<div class="post-content"> <div class="post-content">
@ -36,30 +36,30 @@
</div> </div>
<!-- Copyright --> <!-- Copyright -->
{{ partial "post/copyright.html" . }} {{- partial "post/copyright.html" . -}}
<!-- Reward --> <!-- Reward -->
{{ partial "post/reward.html" . }} {{- partial "post/reward.html" . -}}
<footer class="post-footer"> <footer class="post-footer">
{{ with .Params.tags -}} {{ with .Params.tags -}}
<div class="post-tags"> <div class="post-tags">
{{ range . }} {{ range . -}}
<a href="{{ "tags" | relLangURL }}/{{ . | urlize }}/">{{ . }}</a> <a href="{{ "tags" | relLangURL }}/{{ . | urlize }}/">{{ . }}</a>
{{ end }} {{ end -}}
</div> </div>
{{- end }} {{- end -}}
<!-- Post Pagination --> <!-- Post Pagination -->
<nav class="post-nav"> <nav class="post-nav">
{{ with .NextInSection }} {{ with .NextInSection -}}
<a class="prev" href="{{ .URL }}"> <a class="prev" href="{{ .URL }}">
<i class="iconfont icon-left"></i> <i class="iconfont icon-left"></i>
<span class="prev-text nav-default">{{ .Title }}</span> <span class="prev-text nav-default">{{ .Title }}</span>
<span class="prev-text nav-mobile">{{ T "prevPost" }}</span> <span class="prev-text nav-mobile">{{ T "prevPost" }}</span>
</a> </a>
{{- end }} {{- end }}
{{ with .PrevInSection }} {{ with .PrevInSection -}}
<a class="next" href="{{ .URL }}"> <a class="next" href="{{ .URL }}">
<span class="next-text nav-default">{{ .Title }}</span> <span class="next-text nav-default">{{ .Title }}</span>
<span class="next-text nav-mobile">{{ T "nextPost" }}</span> <span class="next-text nav-mobile">{{ T "nextPost" }}</span>

View file

@ -5,12 +5,12 @@
<span class="post-time"> {{ .Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }} </span> <span class="post-time"> {{ .Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }} </span>
{{ with .Params.categories -}} {{ with .Params.categories -}}
<div class="post-category"> <div class="post-category">
{{ range . }} {{ range . -}}
<a href="{{ "categories" | relLangURL }}/{{ . | urlize }}/"> {{ . }} </a> <a href="{{ "categories" | relLangURL }}/{{ . | urlize }}/"> {{ . }} </a>
{{ end }} {{ end -}}
</div> </div>
{{- end }} {{- end }}
{{ if .Site.Params.moreMeta -}} {{- if .Site.Params.moreMeta }}
<span class="more-meta"> {{ T "wordCount" .WordCount }} </span> <span class="more-meta"> {{ T "wordCount" .WordCount }} </span>
<span class="more-meta"> {{ T "readingTime" .ReadingTime }} </span> <span class="more-meta"> {{ T "readingTime" .ReadingTime }} </span>
{{- end }} {{- end }}

View file

@ -1,264 +1,269 @@
'use strict' 'use strict';
const Even = {} const Even = {};
Even.backToTop = function() { Even.backToTop = function() {
const $backToTop = $('#back-to-top') const $backToTop = $('#back-to-top');
$(window).scroll(function() { $(window).scroll(function() {
if ($(window).scrollTop() > 100) { if ($(window).scrollTop() > 100) {
$backToTop.fadeIn(1000) $backToTop.fadeIn(1000);
} else { } else {
$backToTop.fadeOut(1000) $backToTop.fadeOut(1000);
} }
}) });
$backToTop.click(function() { $backToTop.click(function() {
$('body,html').animate({ scrollTop: 0 }) $('body,html').animate({scrollTop: 0});
}) });
} };
Even.mobileNavbar = function() { Even.mobileNavbar = function() {
const $mobileNav = $('#mobile-navbar') const $mobileNav = $('#mobile-navbar');
const $mobileNavIcon = $('.mobile-navbar-icon') const $mobileNavIcon = $('.mobile-navbar-icon');
const slideout = new Slideout({ const slideout = new Slideout({
'panel': document.getElementById('mobile-panel'), 'panel': document.getElementById('mobile-panel'),
'menu': document.getElementById('mobile-menu'), 'menu': document.getElementById('mobile-menu'),
'padding': 180, 'padding': 180,
'tolerance': 70 'tolerance': 70,
}) });
slideout.disableTouch() slideout.disableTouch();
$mobileNavIcon.click(function() { $mobileNavIcon.click(function() {
slideout.toggle() slideout.toggle();
}) });
slideout.on('beforeopen', function() { slideout.on('beforeopen', function() {
$mobileNav.addClass('fixed-open') $mobileNav.addClass('fixed-open');
$mobileNavIcon.addClass('icon-click').removeClass('icon-out') $mobileNavIcon.addClass('icon-click').removeClass('icon-out');
}) });
slideout.on('beforeclose', function() { slideout.on('beforeclose', function() {
$mobileNav.removeClass('fixed-open') $mobileNav.removeClass('fixed-open');
$mobileNavIcon.addClass('icon-out').removeClass('icon-click') $mobileNavIcon.addClass('icon-out').removeClass('icon-click');
}) });
$('#mobile-panel').on('touchend', function() { $('#mobile-panel').on('touchend', function() {
slideout.isOpen() && $mobileNavIcon.click() slideout.isOpen() && $mobileNavIcon.click();
}) });
} };
Even._initToc = function() { Even._initToc = function() {
const SPACING = 20 const SPACING = 20;
const $toc = $('.post-toc') const $toc = $('.post-toc');
const $footer = $('.post-footer') const $footer = $('.post-footer');
if ($toc.length) { if ($toc.length) {
const minScrollTop = $toc.offset().top - SPACING const minScrollTop = $toc.offset().top - SPACING;
const maxScrollTop = $footer.offset().top - $toc.height() - SPACING const maxScrollTop = $footer.offset().top - $toc.height() - SPACING;
const tocState = { const tocState = {
start: { start: {
'position': 'absolute', 'position': 'absolute',
'top': minScrollTop 'top': minScrollTop,
}, },
process: { process: {
'position': 'fixed', 'position': 'fixed',
'top': SPACING 'top': SPACING,
}, },
end: { end: {
'position': 'absolute', 'position': 'absolute',
'top': maxScrollTop 'top': maxScrollTop,
} },
} };
$(window).scroll(function() { $(window).scroll(function() {
const scrollTop = $(window).scrollTop() const scrollTop = $(window).scrollTop();
if (scrollTop < minScrollTop) { if (scrollTop < minScrollTop) {
$toc.css(tocState.start) $toc.css(tocState.start);
} else if (scrollTop > maxScrollTop) { } else if (scrollTop > maxScrollTop) {
$toc.css(tocState.end) $toc.css(tocState.end);
} else { } else {
$toc.css(tocState.process) $toc.css(tocState.process);
} }
}) });
} }
const HEADERFIX = 30 const HEADERFIX = 30;
const $toclink = $('.toc-link') const $toclink = $('.toc-link');
const $headerlink = $('.headerlink') const $headerlink = $('.headerlink');
const $tocLinkLis = $('.post-toc-content li') const $tocLinkLis = $('.post-toc-content li');
const headerlinkTop = $.map($headerlink, function(link) { const headerlinkTop = $.map($headerlink, function(link) {
return $(link).offset().top return $(link).offset().top;
}) });
const headerLinksOffsetForSearch = $.map(headerlinkTop, function(offset) { const headerLinksOffsetForSearch = $.map(headerlinkTop, function(offset) {
return offset - HEADERFIX return offset - HEADERFIX;
}) });
const searchActiveTocIndex = function(array, target) { const searchActiveTocIndex = function(array, target) {
for (let i = 0; i < array.length - 1; i++) { for (let i = 0; i < array.length - 1; i++) {
if (target > array[i] && target <= array[i + 1]) return i if (target > array[i] && target <= array[i + 1]) return i;
}
if (target > array[array.length - 1]) return array.length - 1
return -1
} }
if (target > array[array.length - 1]) return array.length - 1;
return -1;
};
$(window).scroll(function() { $(window).scroll(function() {
const scrollTop = $(window).scrollTop() const scrollTop = $(window).scrollTop();
const activeTocIndex = searchActiveTocIndex(headerLinksOffsetForSearch, scrollTop) const activeTocIndex = searchActiveTocIndex(headerLinksOffsetForSearch, scrollTop);
$($toclink).removeClass('active') $($toclink).removeClass('active');
$($tocLinkLis).removeClass('has-active') $($tocLinkLis).removeClass('has-active');
if (activeTocIndex !== -1) { if (activeTocIndex !== -1) {
$($toclink[activeTocIndex]).addClass('active') $($toclink[activeTocIndex]).addClass('active');
let ancestor = $toclink[activeTocIndex].parentNode let ancestor = $toclink[activeTocIndex].parentNode;
while (ancestor.tagName !== 'NAV') { while (ancestor.tagName !== 'NAV') {
$(ancestor).addClass('has-active') $(ancestor).addClass('has-active');
ancestor = ancestor.parentNode.parentNode ancestor = ancestor.parentNode.parentNode;
} }
} }
}) });
} };
Even.fancybox = function() { Even.fancybox = function() {
if ($.fancybox) { if ($.fancybox) {
$('.post-content').each(function() { $('.post-content').each(function() {
$(this).find('img').each(function() { $(this).find('img').each(function() {
$(this).wrap(`<a class="fancybox" href="${this.src}" data-fancybox="gallery" data-caption="${this.title}"></a>`) $(this).wrap(`<a class="fancybox" href="${this.src}" data-fancybox="gallery" data-caption="${this.title}"></a>`);
}) });
}) });
$('.fancybox').fancybox({ $('.fancybox').fancybox({
selector: '.fancybox', selector: '.fancybox',
protect: true protect: true,
}) });
}
} }
};
Even.highlight = function() { Even.highlight = function() {
const blocks = document.querySelectorAll('pre code') const blocks = document.querySelectorAll('pre code');
for (let i = 0; i < blocks.length; i++) { for (let i = 0; i < blocks.length; i++) {
const block = blocks[i] const block = blocks[i];
const rootElement = block.parentElement const rootElement = block.parentElement;
const lineCodes = block.innerHTML.split(/\n/) const lineCodes = block.innerHTML.split(/\n/);
if (lineCodes[lineCodes.length - 1] === '') lineCodes.pop() if (lineCodes[lineCodes.length - 1] === '') lineCodes.pop();
const lineLength = lineCodes.length const lineLength = lineCodes.length;
let codeLineHtml = '' let codeLineHtml = '';
for (let i = 0; i < lineLength; i++) { for (let i = 0; i < lineLength; i++) {
codeLineHtml += `<div class="line">${i + 1}</div>` codeLineHtml += `<div class="line">${i + 1}</div>`;
} }
let codeHtml = '' let codeHtml = '';
for (let i = 0; i < lineLength; i++) { for (let i = 0; i < lineLength; i++) {
codeHtml += `<div class="line">${lineCodes[i]}</div>` codeHtml += `<div class="line">${lineCodes[i]}</div>`;
} }
block.className += ' highlight' block.className += ' highlight';
const figure = document.createElement('figure') const figure = document.createElement('figure');
figure.className = block.className figure.className = block.className;
figure.innerHTML = `<table><tbody><tr><td class="gutter"><pre>${codeLineHtml}</pre></td><td class="code"><pre>${codeHtml}</pre></td></tr></tbody></table>` figure.innerHTML = `<table><tbody><tr><td class="gutter"><pre>${codeLineHtml}</pre></td><td class="code"><pre>${codeHtml}</pre></td></tr></tbody></table>`;
rootElement.parentElement.replaceChild(figure, rootElement) rootElement.parentElement.replaceChild(figure, rootElement);
}
} }
};
Even.chroma = function() { Even.chroma = function() {
const blocks = document.querySelectorAll('.highlight > .chroma') const blocks = document.querySelectorAll('.highlight > .chroma');
for (let i = 0; i < blocks.length; i++) { for (let i = 0; i < blocks.length; i++) {
const block = blocks[i] const block = blocks[i];
const afterHighLight = block.querySelector('pre.chroma > code') const afterHighLight = block.querySelector('pre.chroma > code');
const lang = afterHighLight ? afterHighLight.className : '' const lang = afterHighLight ? afterHighLight.className : '';
block.className += ' ' + lang block.className += ' ' + lang;
}
} }
};
Even.toc = function() { Even.toc = function() {
const tocContainer = document.getElementById('post-toc') const tocContainer = document.getElementById('post-toc');
if (tocContainer !== null) { if (tocContainer !== null) {
const toc = document.getElementById('TableOfContents') const toc = document.getElementById('TableOfContents');
if (toc === null) { if (toc === null) {
// toc = true, but there are no headings // toc = true, but there are no headings
tocContainer.parentNode.removeChild(tocContainer) tocContainer.parentNode.removeChild(tocContainer);
} else { } else {
this._refactorToc(toc) this._refactorToc(toc);
this._linkToc() this._linkToc();
this._initToc() this._initToc();
}
} }
} }
};
Even._refactorToc = function(toc) { Even._refactorToc = function(toc) {
// when headings do not start with `h1` // when headings do not start with `h1`
const oldTocList = toc.children[0] const oldTocList = toc.children[0];
let newTocList = oldTocList let newTocList = oldTocList;
let temp let temp;
while (newTocList.children.length === 1 && (temp = newTocList.children[0].children[0]).tagName === 'UL') newTocList = temp while (newTocList.children.length === 1
&& (temp = newTocList.children[0].children[0]).tagName === 'UL') {
if (newTocList !== oldTocList) toc.replaceChild(newTocList, oldTocList) newTocList = temp;
} }
if (newTocList !== oldTocList) toc.replaceChild(newTocList, oldTocList);
};
Even._linkToc = function() { Even._linkToc = function() {
const links = document.querySelectorAll('#TableOfContents a:first-child') const links = document.querySelectorAll('#TableOfContents a:first-child');
for (let i = 0; i < links.length; i++) links[i].className += ' toc-link' for (let i = 0; i < links.length; i++) links[i].className += ' toc-link';
for (let num = 1; num <= 6; num++) { for (let num = 1; num <= 6; num++) {
const headers = document.querySelectorAll('.post-content>h' + num) const headers = document.querySelectorAll('.post-content>h' + num);
for (let i = 0; i < headers.length; i++) { for (let i = 0; i < headers.length; i++) {
const header = headers[i] const header = headers[i];
header.innerHTML = `<a href="#${header.id}" class="headerlink"></a>${header.innerHTML}` header.innerHTML = `<a href="#${header.id}" class="headerlink"></a>${header.innerHTML}`;
}
} }
} }
};
Even.flowchart = function() { Even.flowchart = function() {
if (!window.flowchart) return if (!window.flowchart) return;
const blocks = document.querySelectorAll('pre code.language-flowchart') const blocks = document.querySelectorAll('pre code.language-flowchart');
for (let i = 0; i < blocks.length; i++) { for (let i = 0; i < blocks.length; i++) {
if (!window.hljs && i % 2 === 0) continue if (!window.hljs && i % 2 === 0) continue;
const block = blocks[i] const block = blocks[i];
const rootElement = window.hljs const rootElement = window.hljs
? block.parentElement ? block.parentElement
: block.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement : block.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
const container = document.createElement('div') const container = document.createElement('div');
const id = `js-flowchart-diagrams-${i}` const id = `js-flowchart-diagrams-${i}`;
container.id = id container.id = id;
container.className = 'align-center' container.className = 'align-center';
rootElement.parentElement.replaceChild(container, rootElement) rootElement.parentElement.replaceChild(container, rootElement);
const diagram = flowchart.parse(block.childNodes[0].nodeValue) const diagram = flowchart.parse(block.childNodes[0].nodeValue);
diagram.drawSVG(id, window.flowchartDiagramsOptions ? window.flowchartDiagramsOptions : {}) diagram.drawSVG(id, window.flowchartDiagramsOptions ? window.flowchartDiagramsOptions : {});
}
} }
};
Even.sequence = function() { Even.sequence = function() {
if (!window.Diagram) return if (!window.Diagram) return;
const blocks = document.querySelectorAll('pre code.language-sequence') const blocks = document.querySelectorAll('pre code.language-sequence');
for (let i = 0; i < blocks.length; i++) { for (let i = 0; i < blocks.length; i++) {
if (!window.hljs && i % 2 === 0) continue if (!window.hljs && i % 2 === 0) continue;
const block = blocks[i] const block = blocks[i];
const rootElement = window.hljs const rootElement = window.hljs
? block.parentElement ? block.parentElement
: block.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement : block.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
const container = document.createElement('div') const container = document.createElement('div');
const id = `js-sequence-diagrams-${i}` const id = `js-sequence-diagrams-${i}`;
container.id = id container.id = id;
container.className = 'align-center' container.className = 'align-center';
rootElement.parentElement.replaceChild(container, rootElement) rootElement.parentElement.replaceChild(container, rootElement);
const diagram = Diagram.parse(block.childNodes[0].nodeValue) const diagram = Diagram.parse(block.childNodes[0].nodeValue);
diagram.drawSVG(id, window.sequenceDiagramsOptions ? window.sequenceDiagramsOptions : {theme: 'simple'}) diagram.drawSVG(id, window.sequenceDiagramsOptions
} ? window.sequenceDiagramsOptions
: {theme: 'simple'});
} }
};
export {Even} export {Even}

View file

@ -3,19 +3,19 @@ import {Even} from './even.js'
import '../css/style.scss' import '../css/style.scss'
$(document).ready(function () { $(document).ready(function () {
Even.backToTop() Even.backToTop();
Even.mobileNavbar() Even.mobileNavbar();
Even.toc() Even.toc();
Even.fancybox() Even.fancybox();
}) });
Even.flowchart() Even.flowchart();
Even.sequence() Even.sequence();
if (window.hljs) { if (window.hljs) {
hljs.initHighlighting() hljs.initHighlighting();
Even.highlight() Even.highlight();
} else { } else {
Even.chroma() Even.chroma();
} }