doc: make theme consistent across api and other docs · nodejs/node@2f13db4 · GitHub
Skip to content

Commit 2f13db4

Browse files
demakoffRafaelGSS
authored andcommitted
doc: make theme consistent across api and other docs
Since website based on 2 different repos, there was an inconsistency in theme selection, so we had 2 independant theme props. Now only one stored in local storage is a single source of truth PR-URL: #50877 Reviewed-By: Claudio Wunder <cwunder@gnome.org> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
1 parent e59268a commit 2f13db4

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

BUILDING.md

Lines changed: 6 additions & 0 deletions

doc/api_assets/api.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
{
44
function setupTheme() {
5-
const kCustomPreference = 'customDarkTheme';
6-
const userSettings = sessionStorage.getItem(kCustomPreference);
5+
const storedTheme = localStorage.getItem('theme');
76
const themeToggleButton = document.getElementById('theme-toggle-btn');
87

9-
if (userSettings === null && window.matchMedia) {
8+
// Follow operating system theme preference
9+
if (storedTheme === null && window.matchMedia) {
1010
const mq = window.matchMedia('(prefers-color-scheme: dark)');
1111

1212
if ('onchange' in mq) {
@@ -28,16 +28,16 @@
2828
if (mq.matches) {
2929
document.documentElement.classList.add('dark-mode');
3030
}
31-
} else if (userSettings === 'true') {
31+
} else if (storedTheme === 'dark') {
3232
document.documentElement.classList.add('dark-mode');
3333
}
3434

3535
if (themeToggleButton) {
3636
themeToggleButton.hidden = false;
3737
themeToggleButton.addEventListener('click', function() {
38-
sessionStorage.setItem(
39-
kCustomPreference,
40-
document.documentElement.classList.toggle('dark-mode'),
38+
localStorage.setItem(
39+
'theme',
40+
document.documentElement.classList.toggle('dark-mode') ? 'dark' : 'light',
4141
);
4242
});
4343
}

doc/contributing/collaborator-guide.md

Lines changed: 4 additions & 3 deletions

0 commit comments

Comments
 (0)