diff --git a/components/Header.vue b/components/Header.vue index 19b36c3..1ef4e79 100644 --- a/components/Header.vue +++ b/components/Header.vue @@ -26,12 +26,11 @@ import SearchBox from '@SearchBox' export default { - components: { SearchBox }, + components: { SearchBox } } diff --git a/components/ThemeToggle.vue b/components/ThemeToggle.vue new file mode 100644 index 0000000..7bfc2e8 --- /dev/null +++ b/components/ThemeToggle.vue @@ -0,0 +1,44 @@ + + + + + diff --git a/components/Toc.vue b/components/Toc.vue index a980767..f879e16 100644 --- a/components/Toc.vue +++ b/components/Toc.vue @@ -157,7 +157,7 @@ a display: block; - color: #2c3e50; + color: var(--text--link); width: 100%; box-sizing: border-box; font-size: 12px; @@ -169,14 +169,14 @@ white-space: nowrap; &.active - border-left-color: $accentColor; + border-left-color: var(--text--link--lighten); a - color: $accentColor; + color: var(--text--link--lighten); &:hover a - color: $accentColor; + color: var(--text--link--lighten); for i in range(3, 6) .vuepress-toc-h{i} a diff --git a/components/util.js b/components/util.js index 613a489..e78ee70 100644 --- a/components/util.js +++ b/components/util.js @@ -2,6 +2,18 @@ export const hashRE = /#.*$/ export const extRE = /\.(md|html)$/ export const endingSlashRE = /\/$/ export const outboundRE = /^(https?:|mailto:|tel:)/ +export const darkThemeKey = 'ui-dark-theme' +export const darkTheme = { + 'background': '#282c35', + 'code--background': '#373c49', + 'text': '#fff', + 'text--code': '#fff', + 'text--mask': 'rgba(255, 255, 255, 0.84)', + 'text--mask2': 'rgba(255, 255, 255, 0.54)', + 'text--link': '#ffa7c4', + 'text--link--lighten': '#d23669', + 'title': '#8a278c' +} export function normalize (path) { return decodeURI(path) @@ -21,6 +33,15 @@ export function isTel (path) { return /^tel:/.test(path) } +export function initTheme() { + const isDark = window.localStorage.getItem(darkThemeKey) === 'true' || false + const style = window.document.body.style + Object.keys(darkTheme).forEach(key => { + isDark && style.setProperty(`--${key}`, darkTheme[key]) + !isDark && style.removeProperty(`--${key}`) + }) +} + export function ensureExt (path) { if (isExternal(path)) { return path diff --git a/global-components/BaseListLayout.vue b/global-components/BaseListLayout.vue index 6af0b7a..cda7ccb 100644 --- a/global-components/BaseListLayout.vue +++ b/global-components/BaseListLayout.vue @@ -1,11 +1,16 @@ - diff --git a/layouts/FrontmatterKey.vue b/layouts/FrontmatterKey.vue index 071037a..b5e2a92 100644 --- a/layouts/FrontmatterKey.vue +++ b/layouts/FrontmatterKey.vue @@ -3,3 +3,13 @@ + + diff --git a/layouts/GlobalLayout.vue b/layouts/GlobalLayout.vue index 9dd285a..1bb831b 100644 --- a/layouts/GlobalLayout.vue +++ b/layouts/GlobalLayout.vue @@ -14,6 +14,7 @@ import Header from '@theme/components/Header.vue' import MobileHeader from '@theme/components/MobileHeader.vue' import Footer from '@theme/components/Footer.vue' + import {initTheme} from '../components/util' export default { components: { @@ -30,14 +31,35 @@ }, mounted() { - this.$router.afterEach(()=>{ + initTheme() + this.$router.afterEach(() => { this.isMobileHeaderOpen = false }) } } + + + diff --git a/layouts/Post.vue b/layouts/Post.vue index b70c986..1f9c440 100644 --- a/layouts/Post.vue +++ b/layouts/Post.vue @@ -11,30 +11,36 @@ diff --git a/package.json b/package.json index 84d5411..0774cc3 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "@vuepress/plugin-pwa": "1.0.0", "@vuepress/plugin-search": "1.0.0", "remove-markdown": "^0.3.0", - "vue-feather-icons": "^4.21.0" + "vue-feather-icons": "^4.21.0", + "vue-js-toggle-button": "^1.3.3" }, "devDependencies": { "conventional-changelog-cli": "^2.0.1", diff --git a/styles/code.styl b/styles/code.styl index 8d3c1d1..5854ede 100644 --- a/styles/code.styl +++ b/styles/code.styl @@ -1,6 +1,6 @@ {$contentClass} code - color lighten($textColor, 20%) + color var(--text--link) padding 0.1rem 0.4rem margin 0.1rem font-size 0.85em @@ -21,14 +21,14 @@ border-radius 6px overflow auto code - color #fff + color var(--text--code) padding 0 background-color transparent border-radius 0 div[class*="language-"] position relative - background-color $codeBgColor + background-color var(--code--background) border-radius 6px .highlight-lines user-select none @@ -95,7 +95,7 @@ div[class*="language-"] height 100% border-radius 6px 0 0 6px border-right 1px solid rgba(0, 0, 0, 66%) - background-color $codeBgColor + background-color var(--code--background) for lang in $codeLang diff --git a/styles/index.styl b/styles/index.styl index 5fa0348..48686da 100644 --- a/styles/index.styl +++ b/styles/index.styl @@ -10,15 +10,15 @@ html, body padding 0 margin 0 - background-color #fff + background-color var(--background) body font-family -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif -webkit-font-smoothing antialiased -moz-osx-font-smoothing grayscale font-size 16px - color $textColor - background-color #FFF + color var(--title) + background-color var(--background) .page padding-left $sidebarWidth @@ -30,7 +30,7 @@ body left 0 right 0 height $navbarHeight - background-color #fff + background-color var(--background) box-sizing border-box border-bottom 1px solid $borderColor @@ -45,7 +45,7 @@ body .sidebar font-size 16px - background-color #fff + background-color var(--background) width $sidebarWidth position fixed z-index 10 @@ -81,14 +81,14 @@ body a font-weight 500 - color $accentColor + color var(--text--link) text-decoration underline &:hover - color darken($accentColor, 20%) + color var(--text--link--lighten) p a code font-weight 400 - color $accentColor + color var(--text--link--lighten) kbd background #eee @@ -99,8 +99,8 @@ kbd blockquote font-size .9rem - color darken($accentColor, 50%) - border-left: 3px solid $accentColor; + color var(--text--link--lighten) + border-left: 3px solid var(--text--link--lighten); margin 0.5rem 0 padding .25rem 0 .25rem 1rem diff --git a/yarn.lock b/yarn.lock index 6866b81..2a90416 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8204,6 +8204,11 @@ vue-i18n@^8.11.2: resolved "https://registry.yarnpkg.com/vue-i18n/-/vue-i18n-8.15.0.tgz#9b11ef8e7a124f67cdf788c8c90a81f3606240ed" integrity sha512-juJ/avAP39bOMycC+qQDLJ8U9z9LtLF/9PsRoJLBSfsYZo9bqYntyyX5QPicwlb1emJKjgxhZ3YofHiQcXBu0Q== +vue-js-toggle-button@^1.3.3: + version "1.3.3" + resolved "https://registry.yarnpkg.com/vue-js-toggle-button/-/vue-js-toggle-button-1.3.3.tgz#d603089039e41d45e607355ad2e0478c6a52aceb" + integrity sha512-0b920oztgK+1SqlYF26MPiT28hAieL5aAQE7u21XEym5ryfzD4EMer4hLkgDC/1sWsCHb22GvV+t1Kb4AI6QFw== + vue-loader@^15.7.1: version "15.7.1" resolved "https://registry.yarnpkg.com/vue-loader/-/vue-loader-15.7.1.tgz#6ccacd4122aa80f69baaac08ff295a62e3aefcfd"