analytics: fix Marlin endpoint URL double-encoding in head.html

Hugo's html/template JS-escapes string values inside <script> blocks.
Calling jsonify per-field produced quoted strings like "https://..."
which were then re-escaped, embedding literal quote characters in the
endpoint value passed to the SDK.

Fix by jsonifying the whole config dict at once and marking it safeJS
so html/template does not apply a second round of escaping.

Also extract the environment ternary out of the Marlin constructor call
for readability.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
David Karlsson
2026-05-22 15:42:49 +02:00
parent a0a179c056
commit 28ca826bf1
2 changed files with 4 additions and 9 deletions
+3 -4
View File
@@ -3,15 +3,14 @@ import { Marlin, Environment } from "@docker/marlin-sdk-web-public";
const config = window.__marlinConfig;
if (config && config.apiKey && config.endpoint) {
const environment =
config.environment === "staging" ? Environment.STAGING : Environment.PROD;
try {
window.marlin = new Marlin({
endpoint: config.endpoint,
apiKey: config.apiKey,
site: "docs",
environment:
config.environment === "staging"
? Environment.STAGING
: Environment.PROD,
environment,
});
} catch (err) {
console.warn("Marlin SDK init failed:", err);
+1 -5
View File
@@ -82,11 +82,7 @@
{{- end -}}
{{- if and $apiKey $endpoint -}}
<script>
window.__marlinConfig = {
apiKey: {{ $apiKey | jsonify }},
endpoint: {{ $endpoint | jsonify }},
environment: {{ $env | jsonify }}
};
window.__marlinConfig = {{ dict "apiKey" $apiKey "endpoint" $endpoint "environment" $env | jsonify | safeJS }};
</script>
{{- end -}}
{{- end -}}