⚡ 🔥 Refactor struct & code for loading 3rd scripts.
This commit is contained in:
@@ -1,69 +1,97 @@
|
||||
{{- $jsRes := .Site.Data.resources.js }}
|
||||
{{- $vendor := .Site.Params.vendors.plugins }}
|
||||
{{- $router := .Scratch.Get "router" }}
|
||||
{{- range $jsRes }}
|
||||
{{/* Loading all page need scripts */}}
|
||||
{{ $jsRes := .Site.Data.resources.js }}
|
||||
{{ $vendor := .Site.Params.vendors.plugins }}
|
||||
{{ $router := .Scratch.Get "router" }}
|
||||
{{ range $jsRes }}
|
||||
{{ $pluginJS := partial "_funs/get_res.html" (dict "res" . "vendor" $vendor "router" $router) }}
|
||||
<script type="text/javascript" src="{{ $pluginJS }}" defer></script>
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
|
||||
<script class="next-config" data-name="main" type="application/json">{{- .Scratch.Get "config" -}}</script>
|
||||
<script class="next-config" data-name="main" type="application/json">{{ .Scratch.Get "config" -}}</script>
|
||||
|
||||
{{- $config := resources.Get "js/config.js" }}
|
||||
{{- $utils := resources.Get "js/utils.js" }}
|
||||
{{- $boot := resources.Get "js/next-boot.js" }}
|
||||
{{- $nextjs := (slice $config $utils $boot ) }}
|
||||
{{- if .Site.Params.motion.enable }}
|
||||
{{/* Core scripts */}}
|
||||
{{ $config := resources.Get "js/config.js" }}
|
||||
{{ $utils := resources.Get "js/utils.js" }}
|
||||
{{ $boot := resources.Get "js/next-boot.js" }}
|
||||
{{ $nextjs := slice $config $utils $boot }}
|
||||
|
||||
{{/* Animation scripts */}}
|
||||
{{ if .Site.Params.motion.enable }}
|
||||
{{ $motionjs := resources.Get "js/motion.js" }}
|
||||
{{ $nextjs = $nextjs | append $motionjs }}
|
||||
{{- end }}
|
||||
{{- if or (eq .Site.Params.shceme "Muse") (eq .Site.Params.shceme "Mist") }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Special scheme scripts */}}
|
||||
{{ if or (eq .Site.Params.shceme "Muse") (eq .Site.Params.shceme "Mist") }}
|
||||
{{ $musejs := resources.Get "js/schemes/muse.js" }}
|
||||
{{ $nextjs = $nextjs | append $musejs }}
|
||||
{{- end }}
|
||||
{{- if .Site.Params.bookmark.enable }}
|
||||
{{- $bookmarkjs := resources.Get "js/bookmark.js" }}
|
||||
{{- $nextjs = $nextjs | append $bookmarkjs }}
|
||||
{{- end }}
|
||||
{{- if .Site.Params.pjax }}
|
||||
{{- $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 }}
|
||||
{{- if .Site.Params.localSearch.enable }}
|
||||
{{- $search := resources.Get "js/third-party/search/local.js" }}
|
||||
{{- $nextjs = $nextjs | append $search }}
|
||||
{{ end }}
|
||||
{{- if .Site.Params.algoliaSearch.enable }}
|
||||
{{- $search := resources.Get "js/third-party/search/algolia.js" }}
|
||||
{{- $nextjs = $nextjs | append $search }}
|
||||
{{ end }}
|
||||
|
||||
{{- $nextjs = $nextjs | resources.Concat "js/main.js"}}
|
||||
{{/* Bookmark scripts */}}
|
||||
{{ if .Site.Params.bookmark.enable }}
|
||||
{{ $bookmarkjs := resources.Get "js/bookmark.js" }}
|
||||
{{ $nextjs = $nextjs | append $bookmarkjs }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Pjax scripts */}}
|
||||
{{ if .Site.Params.pjax }}
|
||||
{{ $pjaxjs := resources.Get "js/pjax.js" }}
|
||||
{{ $nextjs = $nextjs | append $pjaxjs }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Share scripts */}}
|
||||
{{ if isset .Site.Params "addthisid" }}
|
||||
{{ $addthisjs := resources.Get "js/third-party/share/addthis.js" }}
|
||||
{{ $nextjs = $nextjs | append $addthisjs }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Comments scripts */}}
|
||||
{{ 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 }}
|
||||
|
||||
{{/* Search engin scripts */}}
|
||||
{{ if .Site.Params.localSearch.enable }}
|
||||
{{ $search := resources.Get "js/third-party/search/local.js" }}
|
||||
{{ $nextjs = $nextjs | append $search }}
|
||||
{{ end }}
|
||||
{{ if .Site.Params.algoliaSearch.enable }}
|
||||
{{ $search := resources.Get "js/third-party/search/algolia.js" }}
|
||||
{{ $nextjs = $nextjs | append $search }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Other not useful scripts, eg: 51la widget, translate */}}
|
||||
{{ with .Site.Params.siteState.statistic }}
|
||||
{{ if and .enable (eq .plugin "51la") }}
|
||||
{{ $lawt := resources.Get "js/third-party/others/lawidget.js" }}
|
||||
{{ $nextjs = $nextjs | append $lawt }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ if .Site.Params.footer.translate }}
|
||||
{{ $translate := resources.Get "js/third-party/others/translate.js" }}
|
||||
{{ $nextjs = $nextjs | append $translate }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
{{ $nextjs = $nextjs | resources.Concat "js/main.js"}}
|
||||
{{ if hugo.IsProduction }}
|
||||
{{- $nextjs = $nextjs | minify | fingerprint }}
|
||||
{{ $nextjs = $nextjs | minify | fingerprint }}
|
||||
{{ end }}
|
||||
|
||||
<script type="text/javascript" src="{{ $nextjs.RelPermalink }}" defer></script>
|
||||
Reference in New Issue
Block a user