update head.html
This commit is contained in:
105
layouts/partials/js-selector.html
Normal file
105
layouts/partials/js-selector.html
Normal file
@ -0,0 +1,105 @@
|
||||
{{ $origin := cond (eq .Site.Params.self_host true) "basic" "cors" }}
|
||||
{{ $data := index .Site.Data.origin $origin }}
|
||||
{{ $is_home := false }}
|
||||
{{ if or (eq .RelPermalink "/") (eq .RelPermalink (relLangURL "/")) }}
|
||||
{{ $is_home = true }}
|
||||
{{ end }}
|
||||
{{- $jsOpts := dict
|
||||
"target" "es2015"
|
||||
"minify" (eq hugo.Environment "production")
|
||||
-}}
|
||||
|
||||
{{ $urls := slice }}
|
||||
|
||||
|
||||
{{ $urls = $urls | append $data.search.js }}
|
||||
|
||||
|
||||
<!-- layout specified -->
|
||||
{{ if or (eq .Type "post") (eq .Type "page") $is_home }}
|
||||
{{ with $data.lazyPolyfill.js }}
|
||||
{{ $urls = $urls | append . }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not $is_home }}
|
||||
<!-- image lazy-loading & popup & clipboard -->
|
||||
{{ with $data.glightbox.js }}
|
||||
{{ $urls = $urls | append . }}
|
||||
{{ end }}
|
||||
{{ with $data.clipboard.js }}
|
||||
{{ $urls = $urls | append . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if or $is_home (eq .Type "post") (eq .Type "archives") (eq .Type "category") (eq .Type "tag") }}
|
||||
{{ $locale := strings.TrimSuffix (path.Ext .Lang) .Lang }}
|
||||
|
||||
{{ with $data.dayjs.js.common }}
|
||||
{{ $urls = $urls | append . }}
|
||||
{{ end }}
|
||||
{{ with replace $data.dayjs.js.locale ":LOCALE" $locale }}
|
||||
{{ $urls = $urls | append . }}
|
||||
{{ end }}
|
||||
{{ with $data.dayjs.js.relativeTime }}
|
||||
{{ $urls = $urls | append . }}
|
||||
{{ end }}
|
||||
{{ with $data.dayjs.js.localizedFormat }}
|
||||
{{ $urls = $urls | append . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if or (strings.Contains .Content "<h2") (strings.Contains .Content "<h3") }}
|
||||
{{ if and site.Params.toc (default true .Params.toc) }}
|
||||
{{ with $data.toc.js }}
|
||||
{{ $urls = $urls | append . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if .Params.mermaid }}
|
||||
{{ with $data.mermaid.js }}
|
||||
{{ $urls = $urls | append . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ range $urls }}
|
||||
<script src="{{ . }}"></script>
|
||||
{{ end }}
|
||||
|
||||
{{ $js := "commons" }}
|
||||
{{ if $is_home }}
|
||||
{{ $js = "home" }}
|
||||
{{ else if eq .Type "categories" }}
|
||||
{{ $js = "categories" }}
|
||||
{{ else if eq .Type "post" }}
|
||||
{{ $js = "post" }}
|
||||
{{ else if eq .Type "page" }}
|
||||
{{ $js = "page" }}
|
||||
{{ else if or (eq .Type "archives") (eq .Type "category") (eq .Type "tag") }}
|
||||
{{ $js = "misc" }}
|
||||
{{ end }}
|
||||
|
||||
{{- $script := resources.Get (printf "js/%s.js" $js) | js.Build $jsOpts -}}
|
||||
<script defer src="{{ $script.RelPermalink }}"></script>
|
||||
|
||||
{{ if .Params.math }}
|
||||
<!-- MathJax -->
|
||||
{{ $mathjaxConfig := resources.Get "js/data/mathjax.js" | minify | fingerprint }}
|
||||
<script async src="{{ $mathjaxConfig.RelPermalink }}"></script>
|
||||
<script async src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=es6"></script>
|
||||
{{ $mathjax := (index site.Data.origin site.Params.cdn).mathjax.js }}
|
||||
<script id="MathJax-script" async src="{{ $mathjax }}"></script>
|
||||
{{ end }}
|
||||
|
||||
<!-- Pageviews -->
|
||||
{{ if eq .Type "post" }}
|
||||
{{ $provider := site.Params.pageviews.provider }}
|
||||
{{ if and $provider (ne $provider "") }}
|
||||
{{ if eq $provider "goatcounter" }}
|
||||
{{ if and site.Params.analytics.goatcounter.id (ne site.Params.analytics.goatcounter.id "") }}
|
||||
{{ partial (printf "pageviews/%s.html" $provider) . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
Reference in New Issue
Block a user