1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-24 07:30:12 +01:00

Fixed base path in storage helpers not updated for instant loading

This commit is contained in:
squidfunk 2021-12-05 11:37:21 +01:00
parent 6c9ffe0bda
commit 632eff2e19
2 changed files with 8 additions and 15 deletions

View File

@ -1,4 +1,4 @@
{#- {#-
This file was automatically generated - do not edit This file was automatically generated - do not edit
-#} -#}
<script>function __md_scope(e,t,_){return new URL(_||(t===localStorage?"{{ config.extra.scope | d(base_url) }}":"{{ base_url }}"),location).pathname+"."+e}function __md_get(e,t=localStorage,_){return JSON.parse(t.getItem(__md_scope(e,t,_)))}function __md_set(e,t,_=localStorage,o){try{_.setItem(__md_scope(e,_,o),JSON.stringify(t))}catch(e){}}</script> <script>__md_scope=new URL("{{ config.extra.scope | d(base_url) }}",location),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>

View File

@ -26,25 +26,18 @@
--> -->
<script> <script>
/* Prepend the base path to the given key to ensure uniqueness */ /* Compute base path once to integrate with instant loading */
function __md_scope(key, storage, base) { __md_scope = new URL("{{ config.extra.scope | d(base_url) }}", location)
var prefix = new URL(base || (
storage === localStorage
? "{{ config.extra.scope | d(base_url) }}"
: "{{ base_url }}"
), location)
return prefix.pathname + "." + key
}
/* Fetch the value for a key from the given storage */ /* Fetch the value for a key from the given storage */
function __md_get(key, storage = localStorage, base) { __md_get = (key, storage = localStorage, scope = __md_scope) => (
return JSON.parse(storage.getItem(__md_scope(key, storage, base))) JSON.parse(storage.getItem(scope.pathname + "." + key))
} )
/* Persist a key-value pair in the given storage */ /* Persist a key-value pair in the given storage */
function __md_set(key, value, storage = localStorage, base) { __md_set = (key, value, storage = localStorage, scope = __md_scope) => {
try { try {
storage.setItem(__md_scope(key, storage, base), JSON.stringify(value)) storage.setItem(scope.pathname + "." + key, JSON.stringify(value))
} catch (err) { } catch (err) {
/* Uncritical, just swallow */ /* Uncritical, just swallow */
} }