fix: themes broken when localStorage has invalid theme id stored
This commit is contained in:
parent
684bb78897
commit
4a330ae36f
1 changed files with 5 additions and 1 deletions
|
|
@ -289,6 +289,10 @@ function playground_text(playground, hidden = true) {
|
||||||
var themeToggleButton = document.getElementById('theme-toggle');
|
var themeToggleButton = document.getElementById('theme-toggle');
|
||||||
var themePopup = document.getElementById('theme-list');
|
var themePopup = document.getElementById('theme-list');
|
||||||
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
|
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
|
||||||
|
var themeIds = [];
|
||||||
|
themePopup.querySelectorAll('button.theme').forEach(function (el) {
|
||||||
|
themeIds.push(el.id);
|
||||||
|
});
|
||||||
var stylesheets = {
|
var stylesheets = {
|
||||||
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
|
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
|
||||||
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
|
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
|
||||||
|
|
@ -317,7 +321,7 @@ function playground_text(playground, hidden = true) {
|
||||||
function get_theme() {
|
function get_theme() {
|
||||||
var theme;
|
var theme;
|
||||||
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
|
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
|
||||||
if (theme === null || theme === undefined) {
|
if (theme === null || theme === undefined || !themeIds.includes(theme)) {
|
||||||
return default_theme;
|
return default_theme;
|
||||||
} else {
|
} else {
|
||||||
return theme;
|
return theme;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue