Skip to content

Commit

Permalink
update Layout
Browse files Browse the repository at this point in the history
  • Loading branch information
amish1188 committed Jan 21, 2025
1 parent 370b088 commit 0088936
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions doc-site/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://vitepress.dev/guide/custom-theme
import { h } from 'vue';
import { h, watch } from 'vue';
import { useData } from 'vitepress';
import DefaultTheme from 'vitepress/theme';
import './style.css';
Expand All @@ -24,21 +24,30 @@ export default {
const { currentTheme } = useCurrentTheme();

// Hente rikig tema
if (currentTheme.value === Theme.NVE) {
document.documentElement.classList.remove('varsom');
document.documentElement.classList.remove('varsom_darkmode');
document.documentElement.classList.add('nve');
} else {
document.documentElement.classList.remove('nve');
document.documentElement.classList.remove('nve_darkmode');
document.documentElement.classList.add('varsom');
}
const applyTheme = () => {
if (currentTheme.value === Theme.NVE) {
document.documentElement.classList.remove('varsom');
document.documentElement.classList.remove('varsom_darkmode');
document.documentElement.classList.add('nve');
} else {
document.documentElement.classList.remove('nve');
document.documentElement.classList.remove('nve_darkmode');
document.documentElement.classList.add('varsom');
}

// Setter darkmode må sikkert trigge det en gang til når jeg bytter tema
if (isDark.value) {
document.documentElement.classList.add(`${currentTheme.value}_darkmode`);
} else {
document.documentElement.classList.remove(`${currentTheme.value}_darkmode`);
}
};
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
applyTheme();

// Setter darkmode må sikkert trigge det en gang til når jeg bytter tema
if (isDark.value) {
document.documentElement.classList.add(`${currentTheme.value}_darkmode`);
} else {
document.documentElement.classList.remove(`${currentTheme.value}_darkmode`);
watch([isDark, currentTheme], () => {
applyTheme();
});
}
return h(DefaultTheme.Layout, null, {});
},
Expand Down

0 comments on commit 0088936

Please sign in to comment.