Skip to content

Commit 5d30e32

Browse files
author
committed
Deployed f00cd62 with MkDocs version: 1.6.1
1 parent 18fa70e commit 5d30e32

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

assets/topbar.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,26 @@
297297
all versioned subdirectories. Without this the browser scopes it to the
298298
current version path (e.g. /v3.1.14/) and the banner reappears on every
299299
other version. Runs immediately so it beats Material's consent check. */
300-
var consentMatch = document.cookie.match(/(?:^|;\s*)__md_consent=([^;]*)/);
301-
if (consentMatch) {
302-
document.cookie = '__md_consent=' + consentMatch[1] + '; path=/; SameSite=Lax';
300+
/* Propagate mkdocs-material consent across versioned subdirectories.
301+
Each version stores consent in localStorage under its own base-path key
302+
(e.g. /utPLSQL/develop/.__consent). Copy a non-empty consent from any
303+
other version into the current version's key before Material checks it. */
304+
var baseEl = document.querySelector('base');
305+
if (baseEl) {
306+
var CONSENT_SUFFIX = '.__consent';
307+
var currentConsentKey = new URL(baseEl.href).pathname + CONSENT_SUFFIX;
308+
if (!localStorage.getItem(currentConsentKey)) {
309+
for (var i = 0; i < localStorage.length; i++) {
310+
var k = localStorage.key(i);
311+
if (k && k !== currentConsentKey && k.endsWith(CONSENT_SUFFIX)) {
312+
var val = localStorage.getItem(k);
313+
if (val && val !== '{}') {
314+
localStorage.setItem(currentConsentKey, val);
315+
break;
316+
}
317+
}
318+
}
319+
}
303320
}
304321

305322
/* Hide Material's built-in header controls immediately to prevent a flash

0 commit comments

Comments
 (0)