mirror of
https://github.com/docker/docs.git
synced 2026-06-19 07:35:16 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -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 -}}
|
||||
|
||||
Reference in New Issue
Block a user