mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-26 03:00:50 +02:00
feat: support site.Params.marketing.google_optimize
Also: - refactor Bootstrap JS out of wowchemy.js for easier maintenance - refactor lengthy env checks to hugo.IsProduction - refactor window.PlotlyConfig from inline JS to the init script - no longer prevent loading GA if GTM provided, in case user wants both
This commit is contained in:
parent
5072eddcc1
commit
aa1071adfc
7 changed files with 22 additions and 14 deletions
|
@ -27,3 +27,6 @@ if (window.netlifyIdentity) {
|
|||
|
||||
// Initialize theme variation and set body theme class.
|
||||
initThemeVariation();
|
||||
|
||||
// For Plotly compatibility with MathJax (must appear prior to loading Plotly).
|
||||
window.PlotlyConfig = {MathJaxConfig: 'local'};
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
{{ $wcIsSiteThemeDark := not (.Scratch.Get "light") | default false }}
|
||||
{{ $js_params := dict "wcDarkLightEnabled" $wcDarkLightEnabled "wcIsSiteThemeDark" $wcIsSiteThemeDark }}
|
||||
{{ $js_bundle := resources.Get "js/wowchemy-init.js" | js.Build (dict "params" $js_params) }}
|
||||
{{- if eq hugo.Environment "production" -}}
|
||||
{{- if hugo.IsProduction -}}
|
||||
{{ $js_bundle = $js_bundle | minify }}
|
||||
{{- end -}}
|
||||
{{ $js_bundle := slice $js_bundle_head $js_bundle | resources.Concat "js/wowchemy-init.min.js" }}
|
||||
{{- if eq hugo.Environment "production" -}}
|
||||
{{- if hugo.IsProduction -}}
|
||||
{{- $js_bundle = $js_bundle | fingerprint "md5" -}}
|
||||
{{- end -}}
|
||||
<script src="{{ $js_bundle.RelPermalink }}"></script>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{{ $ga := site.Params.marketing.google_analytics | default site.GoogleAnalytics | default "" }}
|
||||
{{ $gtm := site.Params.marketing.google_tag_manager | default "" }}
|
||||
|
||||
{{ if (in (slice (getenv "HUGO_ENV") hugo.Environment) "production") | and $ga | and (not $gtm) }}
|
||||
{{ if hugo.IsProduction | and $ga }}
|
||||
|
||||
{{ $gtag_config := cond site.Params.privacy_pack "{ 'anonymize_ip': true }" "{}" }}
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{$ga}}"></script>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{{ if (in (slice (getenv "HUGO_ENV") hugo.Environment) "production") | and site.Params.marketing.google_tag_manager }}
|
||||
{{ if hugo.IsProduction | and site.Params.marketing.google_tag_manager }}
|
||||
<script>
|
||||
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
||||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{{ if (in (slice (getenv "HUGO_ENV") hugo.Environment) "production") | and site.Params.marketing.microsoft_clarity }}
|
||||
{{ if hugo.IsProduction | and site.Params.marketing.microsoft_clarity }}
|
||||
<script>
|
||||
(function(c,l,a,r,i,t,y){
|
||||
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
|
||||
|
|
|
@ -7,6 +7,11 @@
|
|||
{{ if not (and $is_sponsor $hide_generator) }}
|
||||
<meta name="generator" content="Wowchemy {{ site.Data.wowchemy.version }} for Hugo" />
|
||||
{{ end }}
|
||||
|
||||
{{ with site.Params.marketing.google_optimize }}
|
||||
<script src="https://www.googleoptimize.com/optimize.js?id={{ . }}"></script>
|
||||
{{- end -}}
|
||||
|
||||
{{ with site.Params.marketing.google_site_verification }}
|
||||
<meta name="google-site-verification" content="{{ . }}" />
|
||||
{{- end -}}
|
||||
|
|
|
@ -93,9 +93,6 @@
|
|||
|
||||
{{/* Charts */}}
|
||||
{{ if .HasShortcode "chart" }}
|
||||
<script>
|
||||
window.PlotlyConfig = {MathJaxConfig: 'local'};
|
||||
</script>
|
||||
{{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.plotly.url $js.plotly.version) $js.plotly.sri | safeHTML }}
|
||||
{{ end }}
|
||||
|
||||
|
@ -104,6 +101,12 @@
|
|||
<script id="dsq-count-scr" src="https://{{site.Params.comments.disqus.shortname}}.disqus.com/count.js" async></script>
|
||||
{{ end }}
|
||||
|
||||
{{ $js_bootstrap := resources.Get "js/_vendor/bootstrap.bundle.js" }}
|
||||
{{- if hugo.IsProduction -}}
|
||||
{{ $js_bootstrap = $js_bootstrap | minify | fingerprint "md5" }}
|
||||
{{- end -}}
|
||||
<script src="{{ $js_bootstrap.RelPermalink }}"></script>
|
||||
|
||||
{{ $js_search_params := dict }}
|
||||
{{ if ne site.Params.search.engine 0 }}
|
||||
{{/* Configure search engine. */}}
|
||||
|
@ -119,11 +122,9 @@
|
|||
{{ $js_license := $js_license | printf "%s/*! Copyright 2016-present George Cushen (https://georgecushen.com/) */\n" }}
|
||||
{{ $js_license := $js_license | printf "%s/*! License: https://github.com/wowchemy/wowchemy-hugo-modules/blob/master/LICENSE.md */\n" }}
|
||||
{{ $js_bundle_head := $js_license | resources.FromString "js/bundle-head.js" }}
|
||||
{{ $js_linebreak := "\n" | resources.FromString "js/linebreak.js" }}{{/* Fix no line break after Bootstrap JS causing error. */}}
|
||||
{{ $js_params := dict "hugoEnvironment" hugo.Environment "codeHighlighting" ($scr.Get "highlight_enabled" | default false) "searchEnabled" (ne site.Params.search.engine 0) }}
|
||||
{{ $js_academic := resources.Get "js/wowchemy.js" | js.Build (dict "targetPath" (printf "%s/js/wow-core.js" .Lang ) "params" $js_params) }}
|
||||
{{ $js_bootstrap := resources.Get "js/_vendor/bootstrap.bundle.js" }}
|
||||
{{ $js_bundle := slice $js_bootstrap $js_linebreak $js_academic }}
|
||||
{{ $js_bundle := slice $js_academic }}
|
||||
{{ if eq site.Params.search.engine 1 }}
|
||||
{{ $js_academic_search := resources.Get "js/wowchemy-search.js" | js.Build (dict "targetPath" (printf "%s/js/wow-search-built.js" .Lang) "params" $js_search_params) }}
|
||||
{{ $js_bundle = $js_bundle | append $js_academic_search }}
|
||||
|
@ -135,11 +136,11 @@
|
|||
{{ $js_bundle = $js_bundle | append (resources.Get (printf "js/%s.js" .)) }}
|
||||
{{ end }}
|
||||
{{ $js_bundle := $js_bundle | resources.Concat (printf "%s/js/wowchemy-bundle.js" .Lang) }}
|
||||
{{- if eq hugo.Environment "production" -}}
|
||||
{{- if hugo.IsProduction -}}
|
||||
{{ $js_bundle = $js_bundle | minify }}
|
||||
{{- end -}}
|
||||
{{ $js_bundle := slice $js_bundle_head $js_bundle | resources.Concat (printf "%s/js/wowchemy.min.js" .Lang) }}
|
||||
{{- if eq hugo.Environment "production" -}}
|
||||
{{- if hugo.IsProduction -}}
|
||||
{{- $js_bundle = $js_bundle | fingerprint "md5" -}}
|
||||
{{- end -}}
|
||||
<script src="{{ $js_bundle.RelPermalink }}"></script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue