File tree Expand file tree Collapse file tree 4 files changed +15
-0
lines changed
Expand file tree Collapse file tree 4 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,7 @@ export class Page {
167167 title,
168168 enableSearch : this . siteConfig . enableSearch ,
169169 codeTheme : this . siteConfig . style . codeTheme ,
170+ darkMode : this . siteConfig . darkMode ,
170171 } ;
171172 }
172173
Original file line number Diff line number Diff line change 11<!DOCTYPE html>
22<html >
33<head >
4+ {% if darkMode %}
45 <script >
56 (function () {
7+ window .__MARKBIND_DARK_MODE__ = true ;
68 const storageKey = ' markbind-theme' ;
79 const darkTheme = ' dark' ;
810 const lightTheme = ' light' ;
2729 window .__MARKBIND_THEME__ = resolvedTheme;
2830 }());
2931 </script >
32+ {% endif %}
3033 {%- if asset .headTop %}
3134 {%- for headContent in asset .headTop %}
3235 {{ headContent }}
8386<script src =" {{ asset.vue }}" ></script >
8487<script src =" {{ asset.markBindJs }}" ></script >
8588<script src =" {{ asset.pageVueRenderJs }}" ></script >
89+ {% if darkMode %}
8690<script >
8791 document .body .setAttribute (' data-code-theme' , window .__MARKBIND_THEME__ || ' {{ codeTheme }}' );
8892 </script >
93+ {% endif %}
8994<script >
9095 {% if enableSearch % }MarkBind .setupWithSearch (){% else % }MarkBind .setup (){% endif % }
9196 </script >
Original file line number Diff line number Diff line change @@ -64,6 +64,8 @@ export class SiteConfig {
6464
6565 plantumlCheck : boolean ;
6666
67+ darkMode : boolean ;
68+
6769 /**
6870 * @param siteConfigJson The raw json read from the site configuration file
6971 * @param cliBaseUrl As read from the --baseUrl option
@@ -103,6 +105,8 @@ export class SiteConfig {
103105 // TODO this should probably be in pluginsContext
104106 this . plantumlCheck = siteConfigJson . plantumlCheck !== undefined
105107 ? siteConfigJson . plantumlCheck : true ; // check PlantUML's prerequisite by default
108+
109+ this . darkMode = siteConfigJson . darkMode === true ;
106110 }
107111
108112 /**
Original file line number Diff line number Diff line change 11<template >
22 <button
3+ v-if =" enabled"
34 type =" button"
45 class =" btn btn-sm btn-outline-secondary dark-mode-toggle"
56 :aria-label =" buttonLabel"
@@ -50,6 +51,7 @@ function isStoredTheme(theme) {
5051export default {
5152 data () {
5253 return {
54+ enabled: typeof window !== ' undefined' && window .__MARKBIND_DARK_MODE__ === true ,
5355 resolvedTheme: LIGHT_THEME ,
5456 themePreference: null ,
5557 mediaQueryList: null ,
@@ -63,6 +65,9 @@ export default {
6365 },
6466 },
6567 mounted () {
68+ if (! this .enabled ) {
69+ return ;
70+ }
6671 this .themePreference = this .getStoredThemePreference ();
6772 this .applyTheme (this .themePreference );
6873
You can’t perform that action at this time.
0 commit comments