docs-v2/layouts/partials/header/javascript.html

61 lines
1.8 KiB
HTML

<!-- $productPathData here is buggy - it might not return the current page path due to the context in which .RelPermalink is called -->
{{ $productPathData := findRE "[^/]+.*?" .RelPermalink }}
{{ $product := index $productPathData 0 }}
{{ $currentVersion := index $productPathData 1 }}
<!-- Get site data -->
<!-- Load cloudUrls array -->
{{ $cloudUrls := slice }}
{{- range .Site.Data.influxdb_urls.cloud.providers }}
{{- range .regions }}
{{ $cloudUrls = $cloudUrls | append (safeHTML .url) }}
{{ end -}}
{{ end -}}
{{ $products := .Site.Data.products }}
{{ $influxdb_urls := .Site.Data.influxdb_urls }}
<!-- Build main.js -->
{{ $isDevelopment := false }}
{{ $isTesting := false }}
{{ with hugo }}
{{ if .IsDevelopment }}
{{ $isDevelopment = .IsDevelopment }}
{{ end }}
{{ end }}
{{ if eq .Site.Params.env "testing" }}
{{ $isTesting = true }}
{{ end }}
{{ if eq .Site.Params.environment "testing" }}
{{ $isTesting = true }}
{{ end }}
{{ $isDevelopmentOrTesting := or $isDevelopment $isTesting }}
{{ with resources.Get "js/main.js" }}
{{ $opts := dict
"minify" hugo.IsProduction
"sourceMap" (cond $isDevelopmentOrTesting "inline" "")
"format" (cond $isDevelopmentOrTesting "esm" "iife")
"bundle" true
"targetPath" "js/main.js"
"params" (dict
"product" $product
"currentVersion" $currentVersion
"isServer" hugo.IsServer
"products" $products
"influxdb_urls" $influxdb_urls
"cloudUrls" $cloudUrls
"isDevelopment" $isDevelopmentOrTesting
)
}}
{{ with . | js.Build $opts }}
{{ if hugo.IsProduction }}
{{ with . | fingerprint }}
<script src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script>
{{ end }}
{{ else }}
<script type="module" src="{{ .RelPermalink }}"></script>
{{ end }}
{{ end }}
{{ end }}