The code below fails the build with the hugo
command locally when the internet is switched off because it cannot access the remote resource. How to integrate resources.copy
to solve this issue?
{{- with site.Config.Services.GoogleAnalytics.ID }}
{{- if hugo.IsProduction}}
{{- $minimalAnalytics := "" }}
{{- $url := "https://cdn.jsdelivr.net/npm/@minimal-analytics/ga4/dist/index.js" }}
{{- with resources.GetRemote $url }}
{{- with .Err }}
{{- errorf "%s" . }}
{{- else }}
{{- $minimalAnalytics = . }}
{{- end }}
{{- else }}
{{- errorf "Unable to get remote resource %q" $url }}
{{- end }}
{{- $track := resources.Get "js/analytics/track.js" }}
{{- $opts := dict "params" (dict "trackingId" . ) }}
{{- $track = $track | js.Build $opts -}}
{{- $analytics := slice $track $minimalAnalytics | resources.Concat "js/analytics.js" | minify | fingerprint }}
<script src="{{ $analytics.RelPermalink }}" integrity="{{ $analytics.Data.Integrity }}" defer></script>
{{- end }}
{{- end -}}