Improved the comments plug-in load function, close #12

This commit is contained in:
凡梦星尘
2022-07-13 21:25:15 +08:00
parent bf55ada93c
commit 81cff8a5c2
50 changed files with 405 additions and 326 deletions

View File

@@ -1,20 +1 @@
{{- with .Site.Params.artalk }}
<link href="//unpkg.com/artalk@2.3.4/dist/Artalk.css" rel="stylesheet">
<script src="//unpkg.com/artalk@2.3.4/dist/Artalk.js"></script>
<!-- Artalk -->
<div id="Comments"></div>
<script>
new Artalk({
el : '#Comments',
pageKey : '{{ $.Page.RelPermalink }}',
pageTitle : '{{ $.Page.Title }}',
server : '{{ .server }}',
site : '{{ .site }}',
locale : 'auto',
placeholder : '{{ .placeholder }}'
})
</script>
{{- end }}
<div class="artalk-container"></div>

View File

@@ -1,18 +1 @@
{{- with .Site.Params.giscus }}
<div class="giscus" style="position: relative;"></div>
<script src="https://giscus.app/client.js"
data-repo="{{ .repo }}"
data-repo-id="{{ .repoId }}"
data-category="{{ .category }}"
data-category-id="{{ .categoryId }}"
data-mapping="{{ .mapping }}"
data-reactions-enabled="{{ int .reactions }}"
data-emit-metadata="{{ int .emit }}"
data-input-position="{{ .inputPosition }}"
data-theme="{{ .theme }}"
data-lang="{{ $.Site.LanguageCode }}"
data-loading="lazy"
crossorigin="anonymous"
async>
</script>
{{- end }}
<div class="giscus-container"></div>

View File

@@ -1,13 +1 @@
{{- with .Site.Params.LiveRe }}
<div id="lv-container" data-id="city" data-uid="{{ .uid }}"></div>
<script type="text/javascript">
(function(d, s) {
var j, e = d.getElementsByTagName(s)[0];
if (typeof LivereTower === 'function') { return; }
j = d.createElement(s);
j.src = '//cdn-city.livere.com/js/embed.dist.js';
j.async = true;
e.parentNode.insertBefore(j, e);
})(document, 'script');
</script>
{{- end }}
<div id="lv-container" data-id="city" data-uid="{{ .Site.Params.livere.uid }}"></div>

View File

@@ -1,9 +1 @@
{{- with .Site.Params.utterances }}
<script src="https://utteranc.es/client.js"
repo="{{ .repo }}"
issue-term="{{ .issueTerm }}"
label="{{ .label }}"
crossorigin="anonymous"
theme="{{ .theme }}" async>
</script>
{{- end }}
<div class="utterances-container"></div>

View File

@@ -1,23 +1 @@
{{- with .Site.Params.waline }}
<div id="waline"></div>
<link rel="stylesheet" href="//unpkg.com/@waline/client@v2/dist/waline.css"/>
<script src="//unpkg.com/@waline/client@v2/dist/waline.js"></script>
<script type="text/javascript">
const locale = {
placeholder: "{{ .placeholder }}"
};
Waline.init({
locale,
el : "#waline",
pageview : {{ .pageView }},
emoji : {{ .emoji }},
imageUploader : {{ .imgUploader }},
wordLimit : {{ .wordLimit }},
requiredMeta : {{ .requiredMeta }},
serverURL : "{{ .serverURL }}",
lang : "{{ $.Lang }}",
dark : "auto"
});
</script>
{{- end }}
<div class="waline-container"></div>

View File

@@ -1,5 +1,3 @@
{{- with .Site.Params.addThisId }}
<div class="addthis_inline_share_toolbox" style="text-align: center;">
<script src="//s7.addthis.com/js/300/addthis_widget.js#pubid={{ . }}" async="async"></script>
</div>
{{- if isset .Site.Params "addthisid" }}
<div class="addthis_inline_share_toolbox" style="text-align: center;"></div>
{{- end }}

View File

@@ -1,7 +1,9 @@
<!-- Website icons -->
<link rel="shortcut icon" type="image/x-icon" href="{{ .Site.Params.favicon.icon }}">
<link rel="icon" type="image/x-icon" href="{{ .Site.Params.favicon.icon }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ .Site.Params.favicon.small }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ .Site.Params.favicon.medium }}">
<link rel="apple-touch-icon" sizes="180x180" href="{{ .Site.Params.favicon.appleTouchIcon }}">
{{- with .Site.Params.favicon }}
<link rel="shortcut icon" type="image/x-icon" href="{{ .icon }}">
<link rel="icon" type="image/x-icon" href="{{ .icon }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ .small }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ .medium }}">
<link rel="apple-touch-icon" sizes="180x180" href="{{ .appleTouchIcon }}">
{{- end }}
<!-- Website icons -->

View File

@@ -1,22 +1,22 @@
<!-- Plugin style files -->
{{- $cssRes := .Site.Data.resources.css }}
{{- $vendor := .Site.Params.vendors.plugins }}
{{- $vendorCDN := .Scratch.Get "pluginCDN" }}
{{- $router := .Scratch.Get "router" }}
{{ $cssFmt := "%s/%s@%s/%s" }}
{{- range $css := $cssRes }}
{{- $pluginCSS := $vendorCDN }}
{{- $npm := $css.name }}
{{- $file := $css.file }}
{{- if eq $vendor "cdnjs" }}
{{- with $css.alias }}
{{- $npm = . }}
{{- end }}
{{- end }}
{{- $file = replaceRE `(dist|lib|source\/js)\/` "" $css.file }}
{{- $cssFmt = "%s/%s/%s/%s" }}
{{- end }}
{{- $pluginCSS = replace $pluginCSS "${name}" $npm }}
{{- $pluginCSS = replace $pluginCSS "${version}" $css.version }}
{{- $pluginCSS = replace $pluginCSS "${file}" $file }}
<link rel="stylesheet" href="{{ $pluginCSS }}">
{{- $pluginCSS := printf $cssFmt $router $npm $css.version $file }}
<link type="text/css" rel="stylesheet" href="{{ $pluginCSS }}" />
{{- end }}
<!-- Main Style file -->
{{- $scss := resources.Get "css/main.scss" }}
{{- $scss = $scss | resources.ExecuteAsTemplate "main.scss" . }}

View File

@@ -8,7 +8,6 @@
{{- .Scratch.Set "postsCount" (len (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)) -}}
{{- .Scratch.Set "catsCount" (len .Site.Taxonomies.categories) -}}
{{- .Scratch.Set "tagsCount" (len .Site.Taxonomies.tags) -}}
{{- $vendors := .Site.Data.resources.vendors -}}
{{- $pluginVen := .Site.Params.vendors.plugins -}}
{{- $pluginCDN := index $vendors $pluginVen -}}
{{- .Scratch.Set "pluginCDN" $pluginCDN -}}
{{- $vendor := .Site.Params.vendors.plugins -}}
{{- $router := index .Site.Data.resources.vendors $vendor -}}
{{- .Scratch.Set "router" $router -}}

View File

@@ -1,9 +1,9 @@
<!-- Plugin scripts files -->
{{- $jsRes := .Site.Data.resources.js }}
{{- $vendor := .Site.Params.vendors.plugins }}
{{- $vendorCDN := .Scratch.Get "pluginCDN" }}
{{- $router := .Scratch.Get "router" }}
{{ $jsFmt := "%s/%s@%s/%s" }}
{{- range $js := $jsRes }}
{{- $pluginJS := $vendorCDN }}
{{- $npm := $js.name }}
{{- $file := $js.file }}
{{- if eq $vendor "cdnjs" }}
@@ -11,10 +11,9 @@
{{- $npm = . }}
{{- end }}
{{- $file = replaceRE `(dist|lib|source\/js)\/` "" $js.file }}
{{- $jsFmt = "%s/%s/%s/%s" }}
{{- end }}
{{- $pluginJS = replace $pluginJS "${name}" $npm }}
{{- $pluginJS = replace $pluginJS "${version}" $js.version }}
{{- $pluginJS = replace $pluginJS "${file}" $file }}
{{- $pluginJS := printf $jsFmt $router $npm $js.version $file }}
<script type="text/javascript" src="{{ $pluginJS }}" defer></script>
{{- end }}
@@ -39,8 +38,32 @@
{{- $pjaxjs := resources.Get "js/pjax.js" }}
{{- $nextjs = $nextjs | append $pjaxjs }}
{{- end }}
{{- if isset .Site.Params "addthisid" }}
{{- $addthisjs := resources.Get "js/third-party/share/addthis.js" }}
{{- $nextjs = $nextjs | append $addthisjs }}
{{- end }}
{{- if isset .Site.Params "waline" }}
{{- $walinejs := resources.Get "js/third-party/comments/waline.js" }}
{{- $nextjs = $nextjs | append $walinejs }}
{{- end }}
{{- if isset .Site.Params "giscus" }}
{{- $giscusjs := resources.Get "js/third-party/comments/giscus.js" }}
{{- $nextjs = $nextjs | append $giscusjs }}
{{- end }}
{{- if isset .Site.Params "livere" }}
{{- $liverejs := resources.Get "js/third-party/comments/livere.js" }}
{{- $nextjs = $nextjs | append $liverejs }}
{{- end }}
{{- if isset .Site.Params "artalk" }}
{{- $artalkjs := resources.Get "js/third-party/comments/artalk.js" }}
{{- $nextjs = $nextjs | append $artalkjs }}
{{- end }}
{{- if isset .Site.Params "utterances" }}
{{- $utterancesjs := resources.Get "js/third-party/comments/utterances.js" }}
{{- $nextjs = $nextjs | append $utterancesjs }}
{{- end }}
{{- $nextjs = $nextjs | resources.Concat "js/hugo-next.js"}}
{{ if hugo.IsProduction }}
{{- $nextjs = $nextjs | minify | fingerprint }}
{{ end }}
<script type="text/javascript" src="{{ $nextjs.RelPermalink }}" defer></script>
<script type="text/javascript" src="{{ $nextjs.RelPermalink }}" defer></script>