|
5 | 5 | <!-- Get site data -->
|
6 | 6 | <!-- Load cloudUrls array -->
|
7 | 7 | {{ $cloudUrls := slice }}
|
8 |
| -{{- range.Site.Data.influxdb_urls.cloud.providers }} |
9 |
| - {{- range.regions }} |
10 |
| - {{ $cloudUrls = $cloudUrls | append "{{ safeHTML .url }}" }} |
| 8 | +{{- range .Site.Data.influxdb_urls.cloud.providers }} |
| 9 | + {{- range .regions }} |
| 10 | + {{ $cloudUrls = $cloudUrls | append (safeHTML .url) }} |
11 | 11 | {{ end -}}
|
12 | 12 | {{ end -}}
|
13 | 13 | {{ $products := .Site.Data.products }}
|
|
16 | 16 | {{ $isDevelopmentOrTesting := or (eq .Site.Params.environment "development") (eq .Site.Params.environment "testing") (eq (getenv "HUGO_ENV") "development") (eq (getenv "HUGO_ENV") "testing") (not hugo.IsProduction) }}
|
17 | 17 |
|
18 | 18 | {{ if $isDevelopmentOrTesting }}
|
19 |
| - {{/* Load individual JS files for debugging */}} |
| 19 | + {{/* Load individual JS files for debugging with ESM format */}} |
20 | 20 | {{ $sharedParams := dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls }}
|
21 | 21 |
|
22 | 22 | {{/* Load main.js first to ensure proper initialization */}}
|
23 |
| - {{ with resources.Get "js/main.js" }} |
| 23 | + {{ $mainJS := resources.Get "js/main.js" }} |
| 24 | + {{ if $mainJS }} |
24 | 25 | {{ $opts := dict
|
25 | 26 | "minify" false
|
26 |
| - "sourceMap" "inline" |
| 27 | + "sourceMap" "external" |
27 | 28 | "targetPath" "js/main.js"
|
28 | 29 | "params" $sharedParams
|
| 30 | + "format" "esm" |
| 31 | + "external" (slice "*") |
| 32 | + "define" (dict |
| 33 | + "process.env.NODE_ENV" "\"development\"" |
| 34 | + ) |
| 35 | + "splitting" false |
| 36 | + "bundle" true |
29 | 37 | }}
|
30 |
| - {{ with . | js.Build $opts }} |
31 |
| - <script defer src="{{ .RelPermalink }}"></script> |
| 38 | + {{ $processed := $mainJS | js.Build $opts }} |
| 39 | + {{ if $processed }} |
| 40 | + <script type="module" src="{{ $processed.RelPermalink }}"></script> |
32 | 41 | {{ end }}
|
33 | 42 | {{ end }}
|
34 | 43 |
|
35 |
| - {{/* Load other individual JS files for debugging */}} |
36 |
| - {{ range $file := (readDir "assets/js") }} |
37 |
| - {{ if and (strings.HasSuffix $file.Name ".js") (ne $file.Name "main.js") }} |
38 |
| - {{ $jsPath := printf "js/%s" $file.Name }} |
39 |
| - {{ with resources.Get $jsPath }} |
40 |
| - {{ $opts := dict |
41 |
| - "minify" false |
42 |
| - "sourceMap" "inline" |
43 |
| - "targetPath" $jsPath |
44 |
| - "params" $sharedParams |
45 |
| - }} |
46 |
| - {{ with . | js.Build $opts }} |
47 |
| - <script defer src="{{ .RelPermalink }}"></script> |
| 44 | + {{/* Load other individual JS files for debugging with error handling */}} |
| 45 | + {{ $jsDir := "assets/js" }} |
| 46 | + {{ if fileExists $jsDir }} |
| 47 | + {{ range $file := (readDir $jsDir) }} |
| 48 | + {{ if and (strings.HasSuffix $file.Name ".js") (ne $file.Name "main.js") }} |
| 49 | + {{ $jsPath := printf "js/%s" $file.Name }} |
| 50 | + {{ $jsResource := resources.Get $jsPath }} |
| 51 | + {{ if $jsResource }} |
| 52 | + {{ $opts := dict |
| 53 | + "minify" false |
| 54 | + "sourceMap" "external" |
| 55 | + "targetPath" $jsPath |
| 56 | + "params" $sharedParams |
| 57 | + "format" "esm" |
| 58 | + "external" (slice "*") |
| 59 | + "define" (dict |
| 60 | + "process.env.NODE_ENV" "\"development\"" |
| 61 | + ) |
| 62 | + "splitting" false |
| 63 | + "bundle" true |
| 64 | + }} |
| 65 | + {{ $processed := $jsResource | js.Build $opts }} |
| 66 | + {{ if $processed }} |
| 67 | + <script type="module" src="{{ $processed.RelPermalink }}"></script> |
| 68 | + {{ end }} |
48 | 69 | {{ end }}
|
49 | 70 | {{ end }}
|
50 | 71 | {{ end }}
|
51 | 72 | {{ end }}
|
52 | 73 | {{ else }}
|
53 |
| - {{/* Non-development environment: Bundle everything */}} |
54 |
| - {{ with resources.Get "js/main.js" }} |
| 74 | + {{/* Production environment: Use IIFE for better compatibility */}} |
| 75 | + {{ $mainJS := resources.Get "js/main.js" }} |
| 76 | + {{ if $mainJS }} |
| 77 | + {{ $sharedParams := dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls }} |
| 78 | + |
55 | 79 | {{ $opts := dict
|
56 | 80 | "minify" hugo.IsProduction
|
57 |
| - "sourceMap" (cond hugo.IsProduction "" "external") |
| 81 | + "sourceMap" "" |
58 | 82 | "targetPath" "js/main.js"
|
59 |
| - "params" (dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls) |
| 83 | + "params" $sharedParams |
| 84 | + "format" "iife" |
| 85 | + "splitting" false |
| 86 | + "external" (slice "*") |
| 87 | + "define" (dict |
| 88 | + "process.env.NODE_ENV" "\"production\"" |
| 89 | + ) |
60 | 90 | }}
|
61 |
| - {{ with . | js.Build $opts }} |
| 91 | + |
| 92 | + {{ $processed := "" }} |
| 93 | + {{ with $mainJS }} |
| 94 | + {{ $processed = . | js.Build $opts }} |
| 95 | + {{ end }} |
| 96 | + |
| 97 | + {{ if $processed }} |
62 | 98 | {{ if hugo.IsProduction }}
|
63 |
| - {{ with . | fingerprint }} |
64 |
| - <script defer src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script> |
| 99 | + {{ $fingerprinted := $processed | fingerprint }} |
| 100 | + {{ if $fingerprinted }} |
| 101 | + <script defer src="{{ $fingerprinted.RelPermalink }}" integrity="{{ $fingerprinted.Data.Integrity }}" crossorigin="anonymous"></script> |
65 | 102 | {{ end }}
|
66 | 103 | {{ else }}
|
67 |
| - <script defer src="{{ .RelPermalink }}"></script> |
| 104 | + <script defer src="{{ $processed.RelPermalink }}"></script> |
68 | 105 | {{ end }}
|
69 | 106 | {{ end }}
|
70 | 107 | {{ end }}
|
|
0 commit comments