diff --git a/assets/js/blog.js b/assets/js/theme.js similarity index 89% rename from assets/js/blog.js rename to assets/js/theme.js index 0baad5fb..225ed4a0 100644 --- a/assets/js/blog.js +++ b/assets/js/theme.js @@ -2,16 +2,20 @@ jQuery(function($) { 'use strict'; - var _Blog = window._Blog || {}; + var _Theme = window._Theme || {}; - _Blog.toggleMobileMenu = function() { + _Theme.scroll = function () { + window.scroll = new SmoothScroll('[data-scroll]', {speed: 300, speedAsDuration: true}); + } + + _Theme.toggleMobileMenu = function () { $('#menu-toggle').on('click', () => { $('#menu-toggle').toggleClass('active'); $('#menu-mobile').toggleClass('active'); }); }; - _Blog.toggleTheme = function() { + _Theme.toggleTheme = function () { $('.theme-switch').on('click', () => { $('body').toggleClass('dark-theme'); window.isDark = !window.isDark; @@ -20,17 +24,7 @@ jQuery(function($) { }); }; - _Blog.changeTitle = function() { - var currentTitle = document.title; - window.onblur = function() { - document.title = currentTitle; - }; - window.onfocus = function() { - document.title = currentTitle; - }; - }; - - _Blog.dynamicToTop = function() { + _Theme.dynamicToTop = function () { const min = 300; var $toTop = $('#dynamic-to-top'); $(window).scroll(() => { @@ -73,7 +67,7 @@ jQuery(function($) { }); }; - _Blog.chroma = function () { + _Theme.chroma = function () { const blocks = document.querySelectorAll('.highlight > .chroma'); for (let i = 0; i < blocks.length; i++) { const block = blocks[i]; @@ -101,7 +95,7 @@ jQuery(function($) { } }; - _Blog.responsiveTable = function() { + _Theme.responsiveTable = function () { const tables = document.querySelectorAll('.content table'); for (let i = 0; i < tables.length; i++) { const table = tables[i]; @@ -112,7 +106,7 @@ jQuery(function($) { } }; - _Blog._refactorToc = function(toc) { + _Theme._refactorToc = function(toc) { // when headings do not start with `h1` const oldTocList = toc.children[0]; let newTocList = oldTocList; @@ -124,7 +118,7 @@ jQuery(function($) { if (newTocList !== oldTocList) toc.replaceChild(newTocList, oldTocList); }; - _Blog._linkToc = function() { + _Theme._linkToc = function () { const links = document.querySelectorAll('#TableOfContents a:first-child'); for (let i = 0; i < links.length; i++) links[i].className += ' toc-link'; @@ -137,7 +131,7 @@ jQuery(function($) { } }; - _Blog._initToc = function() { + _Theme._initToc = function () { const $toc = $('#post-toc'); if ($toc.length && $toc.css('display') !== 'none') { const SPACING = 80; @@ -145,7 +139,7 @@ jQuery(function($) { const minTop = $toc.position().top;; const mainTop = $('main').position().top; const minScrollTop = minTop + mainTop - SPACING; - const changeTocState = function() { + const changeTocState = function () { const scrollTop = $(window).scrollTop(); const maxTop = $footer.position().top - $toc.height(); const maxScrollTop = maxTop + mainTop - SPACING; @@ -213,7 +207,7 @@ jQuery(function($) { } }; - _Blog.toc = function() { + _Theme.toc = function () { const tocContainer = document.getElementById('post-toc'); if (tocContainer !== null) { const toc = document.getElementById('TableOfContents'); @@ -225,15 +219,16 @@ jQuery(function($) { this._linkToc(); this._initToc(); // Listen for orientation changes - window.addEventListener("resize", function() { - this.setTimeout(_Blog._initToc, 0); + window.addEventListener("resize", function () { + this.setTimeout(_Theme._initToc, 0); }, false); } } }; - _Blog.mermaid = function() { + _Theme.mermaid = function () { if (window.mermaidMap) { + mermaid.initialize({startOnLoad: false, theme: null}); const mermaidAPI = mermaid.mermaidAPI Object.keys(mermaidMap).forEach((id) => { const element = document.getElementById(id); @@ -246,7 +241,7 @@ jQuery(function($) { } } - _Blog.echarts = function() { + _Theme.echarts = function () { if (window.echartsMap) { for (let i = 0; i < echartsArr.length; i++) { echartsArr[i].dispose(); @@ -257,7 +252,7 @@ jQuery(function($) { myChart.setOption(echartsMap[id]); echartsArr.push(myChart); }); - window.addEventListener("resize", function() { + window.addEventListener("resize", function () { this.setTimeout(() => { for (let i = 0; i < echartsArr.length; i++) { echartsArr[i].resize(); @@ -267,7 +262,7 @@ jQuery(function($) { } } - _Blog.countdown = function() { + _Theme.countdown = function () { if (window.countdownMap) { Object.keys(countdownMap).forEach(function(id) { $(`#${id}`).countdown(countdownMap[id]['date'], {elapse: true}) @@ -278,7 +273,7 @@ jQuery(function($) { } }; - _Blog.typeit = function() { + _Theme.typeit = function () { if (window.typeitArr) { for (let i = 0; i < typeitArr.length; i++) { const group = typeitArr[i]; @@ -303,16 +298,16 @@ jQuery(function($) { }; $(document).ready(() => { - _Blog.toggleMobileMenu(); - _Blog.toggleTheme(); - _Blog.changeTitle(); - _Blog.dynamicToTop(); - _Blog.chroma(); - _Blog.responsiveTable(); - _Blog.mermaid(); - _Blog.echarts(); - _Blog.countdown(); - _Blog.typeit(); - _Blog.toc(); + _Theme.scroll(); + _Theme.toggleMobileMenu(); + _Theme.toggleTheme(); + _Theme.dynamicToTop(); + _Theme.chroma(); + _Theme.responsiveTable(); + _Theme.mermaid(); + _Theme.echarts(); + _Theme.countdown(); + _Theme.typeit(); + _Theme.toc(); }); }); diff --git a/layouts/404.html b/layouts/404.html index d3440bab..153b0d74 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -11,12 +11,12 @@

{{- end -}} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 03335500..bc131aef 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -3,6 +3,11 @@ {{- errorf "\n\nThere are two possible situations that led to this error:\n 1. You haven't copied the config.toml yet. See https://github.com/dillonzq/LoveIt#installation \n 2. You have an incompatible update. See https://github.com//dillonzq/LoveIt/blob/master/CHANGELOG.md \n\n有两种可能的情况会导致这个错误发生:\n 1. 你还没有复制 config.toml 参考 https://github.com/dillonzq/LoveIt#installation \n 2. 你进行了一次不兼容的更新 参考 https://github.com//dillonzq/LoveIt/blob/master/CHANGELOG.md \n" -}} {{- end -}} +{{- if eq (getenv "HUGO_ENV") "production" -}} + {{- .Scratch.Set "production" true -}} + {{- .Scratch.Set "CDN" .Site.Params.cdn -}} +{{- end -}} + @@ -51,7 +56,7 @@   - {{- /* Load scripts */ -}} - {{- partial "scripts.html" . -}} + {{- /* Load script */ -}} + {{- partial "script.html" . -}} diff --git a/layouts/partials/comment.html b/layouts/partials/comment.html index a6812a3e..ff412752 100644 --- a/layouts/partials/comment.html +++ b/layouts/partials/comment.html @@ -1,84 +1,94 @@ -{{- if eq (getenv "HUGO_ENV") "production" | and .IsPage | and (ne .Params.comment false) -}} +{{- if .Scratch.Get "production" | and .IsPage | and (ne .Params.comment false) -}} + {{- $CDN := .Scratch.Get "CDN" -}} + {{- /* Disqus Comment System */ -}} {{- with .Site.Params.disqus.shortname -}}
- - + {{- $script := printf `` . -}} + {{- slice $script | $.Scratch.Add "scriptCDN" -}} + {{- end -}} {{- /* Gitalk Comment System */ -}} {{- if .Site.Params.gitalk.owner -}}
- {{- if .Site.Params.cdn.gitalk_css -}} - {{- .Site.Params.cdn.gitalk_css | safeHTML -}} + {{- with $CDN.gitalk_css -}} + {{- slice . | $.Scratch.Add "linkCDN" -}} {{- else -}} - {{- $res := resources.Get "css/lib/gitalk/gitalk.css" | minify -}} - + {{- slice "css/lib/gitalk/gitalk.css" | .Scratch.Add "linkLocal" -}} {{- end -}} - {{- if .Site.Params.cdn.gitalk_js -}} - {{ .Site.Params.cdn.gitalk_js | safeHTML -}} + {{- with $CDN.gitalk_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} {{- else -}} - {{- $res := resources.Get "js/lib/gitalk/gitalk.min.js" -}} - + {{- slice "css/lib/gitalk/gitalk.min.js" | .Scratch.Add "scriptLocal" -}} {{- end -}} - + {{- end -}} {{- /* Valine Comment System */ -}} {{- if .Site.Params.valine.enable -}}
- {{- if .Site.Params.cdn.valine_js -}} - {{- .Site.Params.cdn.valine_js | safeHTML -}} + {{- with $CDN.valine_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} {{- else -}} - {{- $res := resources.Get "js/lib/valine/Valine.min.js" -}} - + {{- slice "js/lib/valine/Valine.min.js" | .Scratch.Add "scriptLocal" -}} {{- end -}} - + {{- end -}} {{- /* Facebook Comment System */ -}} @@ -90,12 +100,11 @@ data-width="{{ .Site.Params.facebook.width }}" data-numposts="{{ .Site.Params.facebook.numPosts }}" > - - + {{- $script := `` -}} + {{- $script = printf $script .Site.Params.facebook.languageCode .Site.Params.facebook.appId -}} + {{- slice $script | .Scratch.Add "scriptCDN" -}} + {{- end -}} {{- end -}} diff --git a/layouts/partials/head/link.html b/layouts/partials/head/link.html index 95b39315..8f27cd18 100644 --- a/layouts/partials/head/link.html +++ b/layouts/partials/head/link.html @@ -1,3 +1,5 @@ +{{- $CDN := .Scratch.Get "CDN" -}} + @@ -28,8 +30,8 @@ {{- /* Font Awesome https://fontawesome.com/ */ -}} -{{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.fontawesome_free_css -}} - {{- .Site.Params.cdn.fontawesome_free_css | safeHTML -}} +{{- with $CDN.fontawesome_free_css -}} + {{- . | safeHTML -}} {{- else -}} {{- $res := resources.Get "css/lib/fontawesome-free/all.min.css" -}} @@ -41,8 +43,8 @@ {{- /* Animate.css https://github.com/daneden/animate.css */ -}} -{{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.animate_css -}} - {{- .Site.Params.cdn.animate_css | safeHTML -}} +{{- with $CDN.animate_css -}} + {{- . | safeHTML -}} {{- else -}} {{ $res := resources.Get "css/lib/animate/animate.min.css" -}} diff --git a/layouts/partials/script.html b/layouts/partials/script.html new file mode 100644 index 00000000..00ae5f59 --- /dev/null +++ b/layouts/partials/script.html @@ -0,0 +1,194 @@ +{{- $CDN := .Scratch.Get "CDN" -}} + +{{- /* Google analytics async */ -}} +{{- if .Scratch.Get "production" | and .Site.GoogleAnalytics -}} + {{- template "_internal/google_analytics_async.html" . -}} +{{- end -}} + +{{- /* jQuery https://github.com/jquery/jquery */ -}} +{{- with $CDN.jquery_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} +{{- else -}} + {{- slice "js/lib/jquery/jquery.slim.min.js" | .Scratch.Add "scriptLocal" -}} +{{- end -}} + +{{- /* lazysizes https://github.com/aFarkas/lazysizes */ -}} +{{- with $CDN.lazysizes_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} +{{- else -}} + {{- slice "js/lib/lazysizes/lazysizes.min.js" | .Scratch.Add "scriptLocal" -}} +{{- end -}} + +{{- /* Smooth Scroll https://github.com/cferdinandi/smooth-scroll */ -}} +{{- with $CDN.smooth_scroll_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} +{{- else -}} + {{- slice "js/lib/smooth-scroll/smooth-scroll.polyfills.min.js" | .Scratch.Add "scriptLocal" -}} +{{- end -}} + +{{- /* TypeIt https://github.com/alexmacarthur/typeit */ -}} +{{- with .Scratch.Get "typeitMap" -}} + {{- with $CDN.typeit_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} + {{- else -}} + {{- slice "js/lib/typeit/typeit.min.js" | $.Scratch.Add "scriptLocal" -}} + {{- end -}} + {{- range $key, $val := . -}} + {{- slice $val | $.Scratch.Add "typeitArr" -}} + {{- end -}} + +{{- end -}} + +{{- /* KaTeX https://github.com/KaTeX/KaTeX */ -}} +{{- if .Site.Params.math.enable | and (ne .Params.math false) -}} + {{- with $CDN.katex_css -}} + {{- slice . | $.Scratch.Add "linkCDN" -}} + {{- else -}} + {{- slice "css/lib/katex/katex.min.css" | .Scratch.Add "linkLocal" -}} + {{- end -}} + {{- with $CDN.katex_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} + {{- else -}} + {{- slice "js/lib/katex/katex.min.js" | .Scratch.Add "scriptLocal" -}} + {{- end -}} + {{- with $CDN.katex_auto_render_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} + {{- else -}} + {{- slice "js/lib/katex/auto-render.min.js" | .Scratch.Add "scriptLocal" -}} + {{- end -}} + {{- $math := .Site.Params.math -}} + {{- if $math.copy_tex -}} + {{- with $CDN.katex_copy_tex_css -}} + {{- slice . | $.Scratch.Add "linkCDN" -}} + {{- else -}} + {{- slice "css/lib/katex/copy-tex.min.css" | .Scratch.Add "linkLocal" -}} + {{- end -}} + {{- with $CDN.katex_copy_tex_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} + {{- else -}} + {{- slice "js/lib/katex/copy-tex.min.js" | .Scratch.Add "scriptLocal" -}} + {{- end -}} + {{- end -}} + {{- if $math.mhchem -}} + {{- with $CDN.katex_mhchem_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} + {{- else -}} + {{- slice "js/lib/katex/mhchem.min.js" | .Scratch.Add "scriptLocal" -}} + {{- end -}} + {{- end -}} + +{{- end -}} + +{{- /* mermaid https://github.com/knsv/mermaid */ -}} +{{- with .Scratch.Get "mermaidMap" -}} + {{- with $CDN.mermaid_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} + {{- else -}} + {{- slice "js/lib/mermaid/mermaid.min.js" | $.Scratch.Add "scriptLocal" -}} + {{- end -}} + +{{- end -}} + +{{- /* Music */ -}} +{{- if .Scratch.Get "music" -}} + {{- /* APlayer https://github.com/MoePlayer/APlayer */ -}} + {{- with $CDN.aplayer_css -}} + {{- slice . | $.Scratch.Add "linkCDN" -}} + {{- else -}} + {{- slice "css/lib/aplayer/APlayer.min.css" | .Scratch.Add "linkLocal" -}} + {{- end -}} + {{- with $CDN.aplayer_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} + {{- else -}} + {{- slice "js/lib/aplayer/APlayer.min.js" | .Scratch.Add "scriptLocal" -}} + {{- end -}} + + {{- /* MetingJS https://github.com/metowolf/MetingJS */ -}} + {{- with $CDN.meting_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} + {{- else -}} + {{- slice "js/lib/meting/Meting.min.js" | .Scratch.Add "scriptLocal" -}} + {{- end -}} +{{- end -}} + +{{- /* jQuery.countdown https://github.com/hilios/jQuery.countdown */ -}} +{{- with .Scratch.Get "countdownMap" -}} + {{- with $CDN.jquery_countdown_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} + {{- else -}} + {{- slice "js/lib/jquery-countdown/jquery.countdown.min.js" | $.Scratch.Add "scriptLocal" -}} + {{- end -}} + +{{- end -}} + +{{- /* dev feature */ -}} +{{- if .Params.dev -}} + {{- /* ECharts https://github.com/apache/incubator-echarts */ -}} + {{- with .Scratch.Get "echartsMap" -}} + {{- with $CDN.echarts_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} + {{- else -}} + {{- slice "js/lib/echarts/echarts.min.js" | $.Scratch.Add "scriptLocal" -}} + {{- end -}} + {{- with $CDN.echarts_macarons_js -}} + {{- slice . | $.Scratch.Add "scriptCDN" -}} + {{- else -}} + {{- slice "js/lib/echarts/macarons.js" | $.Scratch.Add "scriptLocal" -}} + {{- end -}} + + {{- end -}} +{{- end -}} + +{{- /* Theme script */ -}} +{{- slice "js/theme.js" | .Scratch.Add "scriptLocal" -}} + +{{- range .Scratch.Get "linkCDN" -}} + {{- safeHTML . -}} +{{- end -}} +{{- range .Scratch.Get "linkLocal" -}} + {{- $res := resources.Get . -}} + {{- if not (strings.HasSuffix . ".min.css") -}} + {{- $res = minify $res -}} + {{- end -}} + +{{- end -}} + +{{- range .Scratch.Get "scriptCDN" -}} + {{- safeHTML . -}} +{{- end -}} +{{- range .Scratch.Get "scriptLocal" -}} + {{- $res := resources.Get . -}} + {{- if not (strings.HasSuffix . ".min.js") -}} + {{- $res = minify $res -}} + {{- end -}} + +{{- end -}} diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html deleted file mode 100644 index 6252e577..00000000 --- a/layouts/partials/scripts.html +++ /dev/null @@ -1,224 +0,0 @@ -{{- /* Google analytics async */ -}} -{{- if eq (getenv "HUGO_ENV") "production" | and .Site.GoogleAnalytics -}} - {{- template "_internal/google_analytics_async.html" . -}} -{{- end -}} - -{{- /* jQuery https://github.com/jquery/jquery */ -}} -{{- $jquery := "" -}} -{{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.jquery_js -}} - {{- $jquery = .Site.Params.cdn.jquery_js -}} -{{- else -}} - {{- $res := resources.Get "js/lib/jquery/jquery.slim.min.js" -}} - {{- $jquery = printf "" $res.RelPermalink -}} -{{- end -}} -{{- $jquery | safeHTML -}} - -{{- /* lazysizes https://github.com/aFarkas/lazysizes */ -}} -{{- $lazysizes := "" -}} -{{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.lazysizes_js -}} - {{- $lazysizes = .Site.Params.cdn.lazysizes_js -}} -{{- else -}} - {{- $res := resources.Get "js/lib/lazysizes/lazysizes.min.js" -}} - {{- $lazysizes = printf "" $res.RelPermalink -}} -{{- end -}} -{{- $lazysizes | safeHTML -}} - -{{- /* Smooth Scroll https://github.com/cferdinandi/smooth-scroll */ -}} -{{- $smooth_scroll := "" -}} -{{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.smooth_scroll_js -}} - {{- $smooth_scroll = .Site.Params.cdn.smooth_scroll_js -}} -{{- else -}} - {{- $res := resources.Get "js/lib/smooth-scroll/smooth-scroll.polyfills.min.js" -}} - {{- $smooth_scroll = printf "" $res.RelPermalink -}} -{{- end -}} -{{- $smooth_scroll = delimit (slice $smooth_scroll "") "" -}} -{{- $smooth_scroll | safeHTML -}} - -{{- /* TypeIt https://github.com/alexmacarthur/typeit */ -}} -{{- if .Scratch.Get "typeitMap" -}} - {{- $typeit := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.typeit_js -}} - {{- $typeit = .Site.Params.cdn.typeit_js -}} - {{- else -}} - {{- $res := resources.Get "js/lib/typeit/typeit.min.js" -}} - {{- $typeit = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $typeit | safeHTML -}} - {{- $typeitArr := slice -}} - {{- range $key, $val := .Scratch.Get "typeitMap" -}} - {{- $typeitArr = $typeitArr | append (slice $val) -}} - {{- end -}} - -{{- end -}} - -{{- /* KaTeX https://github.com/KaTeX/KaTeX */ -}} -{{- if .Site.Params.math.enable | and (ne .Params.math false) -}} - {{- $math := .Site.Params.math -}} - {{- $katex_css := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.katex_css -}} - {{- $katex_css = .Site.Params.cdn.katex_css -}} - {{- else -}} - {{- $res := resources.Get "css/lib/katex/katex.min.css" -}} - {{- $katex_css = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $katex_js := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.katex_js -}} - {{- $katex_js = .Site.Params.cdn.katex_js -}} - {{- else -}} - {{- $res := resources.Get "js/lib/katex/katex.min.js" -}} - {{- $katex_js = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $katex_auto_render_js := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.katex_auto_render_js -}} - {{- $katex_auto_render_js = .Site.Params.cdn.katex_auto_render_js -}} - {{- else -}} - {{- $res := resources.Get "js/lib/katex/auto-render.min.js" -}} - {{- $katex_auto_render_js = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $katex := delimit (slice $katex_css $katex_js $katex_auto_render_js) "" -}} - {{- if $math.copy_tex -}} - {{- $katex_copy_tex_css := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.katex_copy_tex_css -}} - {{- $katex_copy_tex_css = .Site.Params.cdn.katex_copy_tex_css -}} - {{- else -}} - {{- $res := resources.Get "css/lib/katex/copy-tex.min.css" -}} - {{- $katex_copy_tex_css = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $katex_copy_tex_js := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.katex_copy_tex_js -}} - {{- $katex_copy_tex_js = .Site.Params.cdn.katex_copy_tex_js -}} - {{- else -}} - {{- $res := resources.Get "js/lib/katex/copy-tex.min.js" -}} - {{- $katex_copy_tex_js = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $katex = delimit (slice $katex $katex_copy_tex_css $katex_copy_tex_js) "" -}} - {{- end -}} - {{- if $math.mhchem -}} - {{- $katex_mhchem_js := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.katex_mhchem_js -}} - {{- $katex_mhchem_js = .Site.Params.cdn.katex_mhchem_js -}} - {{- else -}} - {{- $res := resources.Get "js/lib/katex/mhchem.min.js" -}} - {{- $katex_mhchem_js = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $katex = delimit (slice $katex $katex_mhchem_js) "" -}} - {{- end -}} - {{- $katex | safeHTML -}} - -{{- end -}} - -{{- /* mermaid https://github.com/knsv/mermaid */ -}} -{{- if .Scratch.Get "mermaidMap" -}} - {{- $mermaid := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.mermaid_js -}} - {{- $mermaid = .Site.Params.cdn.mermaid_js -}} - {{- else -}} - {{- $res := resources.Get "js/lib/mermaid/mermaid.min.js" -}} - {{- $mermaid = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $mermaidInit := "" -}} - {{- $mermaid = delimit (slice $mermaid $mermaidInit) "" -}} - {{- $mermaid | safeHTML -}} - -{{- end -}} - -{{- /* Music */ -}} -{{- if .Scratch.Get "music" -}} - {{- /* APlayer https://github.com/MoePlayer/APlayer */ -}} - {{- $aplayer_css := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.aplayer_css -}} - {{- $aplayer_css = .Site.Params.cdn.aplayer_css -}} - {{- else -}} - {{- $res := resources.Get "css/lib/aplayer/APlayer.min.css" -}} - {{- $aplayer_css = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $aplayer_js := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.aplayer_js -}} - {{- $aplayer_js = .Site.Params.cdn.aplayer_js -}} - {{- else -}} - {{- $res := resources.Get "js/lib/aplayer/APlayer.min.js" -}} - {{- $aplayer_js = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $aplayer := delimit (slice $aplayer_css $aplayer_js) "" -}} - {{- $aplayer | safeHTML -}} - - {{- /* MetingJS https://github.com/metowolf/MetingJS */ -}} - {{- $meting := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.meting_js -}} - {{- $meting = .Site.Params.cdn.meting_js -}} - {{- else -}} - {{- $res := resources.Get "js/lib/meting/Meting.min.js" -}} - {{- $meting = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $meting | safeHTML -}} -{{- end -}} - -{{- /* jQuery.countdown https://github.com/hilios/jQuery.countdown */ -}} -{{- if .Scratch.Get "countdownMap" -}} - {{- $countdown := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.jquery_countdown_js -}} - {{- $countdown = .Site.Params.cdn.jquery_countdown_js -}} - {{- else -}} - {{- $res := resources.Get "js/lib/jquery-countdown/jquery.countdown.min.js" -}} - {{- $countdown = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $countdown | safeHTML -}} - -{{- end -}} - -{{- /* dev feature */ -}} -{{- if .Params.dev -}} - {{- /* ECharts https://github.com/apache/incubator-echarts */ -}} - {{- if .Scratch.Get "echartsMap" -}} - {{- $echarts_js := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.echarts_js -}} - {{- $echarts_js = .Site.Params.cdn.echarts_js -}} - {{- else -}} - {{- $res := resources.Get "js/lib/echarts/echarts.min.js" -}} - {{- $echarts_js = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $echarts_macarons_js := "" -}} - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.cdn.echarts_macarons_js -}} - {{- $echarts_macarons_js = .Site.Params.cdn.echarts_macarons_js -}} - {{- else -}} - {{- $res := resources.Get "js/lib/echarts/macarons.js" | minify -}} - {{- $echarts_macarons_js = printf "" $res.RelPermalink -}} - {{- end -}} - {{- $echarts := delimit (slice $echarts_js $echarts_macarons_js) "" -}} - {{- $echarts | safeHTML -}} - - {{- end -}} -{{- end -}} - -{{- /* Blog script */ -}} -{{- $res := resources.Get "/js/blog.js" | minify -}} - diff --git a/layouts/posts/single.html b/layouts/posts/single.html index 809932c5..90a0a678 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -30,7 +30,7 @@   {{ T "wordCount" .WordCount }}  {{ T "readingTime" .ReadingTime }}  - {{- if eq (getenv "HUGO_ENV") "production" | and .Site.Params.valine.enable | and .Site.Params.valine.visitor -}} + {{- if .Scratch.Get "production" | and .Site.Params.valine.enable | and .Site.Params.valine.visitor -}} {{ T "pageviews" | safeHTML }}