Improve page scripts configuration files.

This commit is contained in:
凡梦星尘
2022-07-22 17:16:34 +08:00
parent a9ff14d312
commit 31f6e21671
15 changed files with 198 additions and 138 deletions

View File

@@ -4,12 +4,14 @@
script.charset = "UTF-8";
script.id = "LA_COLLECT";
script.src = "{{ .ctx.Site.Data.resources.analytics.la }}";
script.src = "{{ .Site.Data.resources.analytics.la }}";
script.async = "true"
script.onload = function() {
LA.init({ id: "{{ .id }}",ck: "{{ .id }}", autoTrack:true });
{{ with .Site.Params.analytics.laId }}
LA.init({ id: "{{ . }}",ck: "{{ . }}", autoTrack:true });
{{ end }}
}
document.head.appendChild(script);
});
document.head.appendChild(script);
});
</script>

View File

@@ -5,4 +5,6 @@
{{- partial "head/facebook.html" . }}
{{- partial "head/verify.html" . }}
{{- partialCached "head/style.html" . }}
{{- partialCached "head/analytics.html" . }}
{{- partial "head/config.html" . }}
{{- partialCached "head/analytics.html" . }}

View File

@@ -1,6 +1,3 @@
{{ $ctx := . }}
{{- with .Site.Params.analytics }}
{{- if isset . "laid" }}
{{ partial "_thirdparty/analytics/51la.html" (dict "ctx" $ctx "id" .laId) }}
{{- if isset .Site.Params.analytics "laid" }}
{{ partial "_thirdparty/analytics/51la.html" . }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,63 @@
<script class="next-config" data-name="page" type="application/json">
{{- $pageCnf := dict }}
{{- $pageCnf = merge $pageCnf (dict
"isHome" .IsHome
"isPage" .IsPage
"lang" .Site.LanguageCode
"comments" .Site.Params.comments.enable
"permalink" (.Page.Permalink | absURL)
"path" (.Page.Permalink | path.Base)
"title" .Page.Title
) }}
{{- if .IsPage }}
{{- with .Site.Params.waline }}
{{- $waline := dict
"js" $.Site.Data.resources.waline.js
"css" $.Site.Data.resources.waline.css
"cfg" .
}}
{{- $pageCnf = merge $pageCnf (dict "waline" $waline) }}
{{- end }}
{{- with .Site.Params.giscus }}
{{- $giscus := dict
"js" $.Site.Data.resources.giscus.js
"cfg" .
}}
{{- $pageCnf = merge $pageCnf (dict "giscus" $giscus) }}
{{- end }}
{{- with .Site.Params.artalk }}
{{- $artalk := dict
"js" $.Site.Data.resources.artalk.js
"css" $.Site.Data.resources.artalk.css
"cfg" .
}}
{{- $pageCnf = merge $pageCnf (dict "artalk" $artalk) }}
{{- end }}
{{- with .Site.Params.livere }}
{{- $livere := dict "js" $.Site.Data.resources.livere.js }}
{{- $pageCnf = merge $pageCnf (dict "livere" $livere) }}
{{- end }}
{{- with .Site.Params.utterances }}
{{- $utterances := dict
"js" $.Site.Data.resources.utterances.js
"cfg" .
}}
{{- $pageCnf = merge $pageCnf (dict "utterances" $utterances) }}
{{- end }}
{{- with .Site.Params.addThisId }}
{{- $addthis := dict
"js" $.Site.Data.resources.addthis.js
"cfg" (dict "pubid" .)
}}
{{- $pageCnf = merge $pageCnf (dict "addthis" $addthis) }}
{{- end }}
{{- end }}
{{- $pageCnf -}}
</script>

View File

@@ -1,18 +1,37 @@
{{/* Use to defind global variables */}}
{{- if not hugo.IsExtended }}
{{- warnf "Hugo NexT 主题使用了 SCSS 框架,请到官方地址下载 Hugo Extended 版本https://github.com/gohugoio/hugo/releases" -}}
{{- errorf "Because that use SCSS framework in Hugo NexT, Please download Hugo extended version on offical site: https://github.com/gohugoio/hugo/releases" -}}
{{- end }}
{{ if not hugo.IsExtended }}
{{ warnf "Hugo NexT 主题使用了 SCSS 框架,请到官方地址下载 Hugo Extended 版本https://github.com/gohugoio/hugo/releases" }}
{{ errorf "Because that use SCSS framework in Hugo NexT, Please download Hugo extended version on offical site: https://github.com/gohugoio/hugo/releases" }}
{{ end }}
{{- $globalVars := newScratch -}}
{{ $globalVars := newScratch }}
{{- $globalVars.Set "postsCount" (len (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)) -}}
{{- $globalVars.Set "catsCount" (len .Site.Taxonomies.categories) -}}
{{- $globalVars.Set "tagsCount" (len .Site.Taxonomies.tags) -}}
{{ $globalVars.Set "postsCount" (len (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)) }}
{{ $globalVars.Set "catsCount" (len .Site.Taxonomies.categories) }}
{{ $globalVars.Set "tagsCount" (len .Site.Taxonomies.tags) }}
{{- $vendor := .Site.Params.vendors.plugins -}}
{{- $router := index .Site.Data.resources.vendors $vendor -}}
{{- $globalVars.Set "router" $router -}}
{{ $vendor := .Site.Params.vendors.plugins }}
{{ $router := index .Site.Data.resources.vendors $vendor }}
{{ $globalVars.Set "router" $router }}
{{- return $globalVars.Values -}}
{{ $vendorDict := dict
"plugins" $vendor
"router" $router
}}
{{ $config := dict
"hostname" .Site.BaseURL
"root" "/"
"vendor" $vendorDict
"darkmode" .Site.Params.darkmode
"version" .Site.Data.config.version
"scheme" .Site.Params.scheme
"sidebar" .Site.Params.sidebar
"copybtn" .Site.Params.codeblock.copyBtn
"bookmark" .Site.Params.bookmark
"lazyload" .Site.Params.lazyload
"motion" .Site.Params.motion
}}
{{ $globalVars.Set "config" $config }}
{{ return $globalVars.Values }}

View File

@@ -17,7 +17,9 @@
<script type="text/javascript" src="{{ $pluginJS }}" defer></script>
{{- end }}
{{- $config := resources.Get "js/config.js" | resources.ExecuteAsTemplate "config.js" . }}
<script class="next-config" data-name="main" type="application/json">{{- .Scratch.Get "config" -}}</script>
{{- $config := resources.Get "js/config.js" }}
{{- $motion := resources.Get "js/motion.js" }}
{{- $boot := resources.Get "js/next-boot.js" }}
{{- $utils := resources.Get "js/utils.js" }}
@@ -62,7 +64,7 @@
{{- $utterancesjs := resources.Get "js/third-party/comments/utterances.js" }}
{{- $nextjs = $nextjs | append $utterancesjs }}
{{- end }}
{{- $nextjs = $nextjs | resources.Concat "js/hugo-next.js"}}
{{- $nextjs = $nextjs | resources.Concat "js/main.js"}}
{{ if hugo.IsProduction }}
{{- $nextjs = $nextjs | minify | fingerprint }}
{{ end }}