From 0726c2263f8fb4a084847bae95cdce82c32762c3 Mon Sep 17 00:00:00 2001 From: ImCaO Date: Mon, 28 Feb 2022 09:48:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=BA=E7=9C=81=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layout/includes/head.pug | 4 +++- scripts/helpers/inject_head_js.js | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/layout/includes/head.pug b/layout/includes/head.pug index 16133ee..3f9e95b 100644 --- a/layout/includes/head.pug +++ b/layout/includes/head.pug @@ -16,7 +16,9 @@ - else pageKeywords = Array.isArray(config.keywords) ? (config.keywords).join(','): ([]).join(',') || config.keywords - var pageAuthor = config.email ? config.author + ',' + config.email : config.author - var pageCopyright = config.copyright || config.author -- var themeColor = theme.display_mode === 'dark' ? theme.theme_color.meta_theme_color_dark : theme.theme_color.meta_theme_color_light +- var themeColorLight = theme.theme_color && theme.theme_color.enable && theme.theme_color.meta_theme_color_light || '#ffffff' +- var themeColorDark = theme.theme_color && theme.theme_color.enable && theme.theme_color.meta_theme_color_dark || '#0d0d0d' +- var themeColor = theme.display_mode === 'dark' ? themeColorDark : themeColorLight meta(charset='UTF-8') meta(http-equiv="X-UA-Compatible" content="IE=edge") diff --git a/scripts/helpers/inject_head_js.js b/scripts/helpers/inject_head_js.js index 8760fb9..9c845d4 100644 --- a/scripts/helpers/inject_head_js.js +++ b/scripts/helpers/inject_head_js.js @@ -9,6 +9,8 @@ hexo.extend.helper.register('inject_head_js', function () { const { darkmode, aside } = this.theme const { theme_color } = hexo.theme.config + const themeColorLight = theme_color && theme_color.enable && theme_color.meta_theme_color_light || '#ffffff' + const themeColorDark = theme_color && theme_color.enable && theme_color.meta_theme_color_dark || '#0d0d0d' const localStore = ` win.saveToLocal = { @@ -64,13 +66,13 @@ hexo.extend.helper.register('inject_head_js', function () { win.activateDarkMode = function () { document.documentElement.setAttribute('data-theme', 'dark') if (document.querySelector('meta[name="theme-color"]') !== null) { - document.querySelector('meta[name="theme-color"]').setAttribute('content', '${theme_color.meta_theme_color_dark}') + document.querySelector('meta[name="theme-color"]').setAttribute('content', '${themeColorDark}') } } win.activateLightMode = function () { document.documentElement.setAttribute('data-theme', 'light') if (document.querySelector('meta[name="theme-color"]') !== null) { - document.querySelector('meta[name="theme-color"]').setAttribute('content', '${theme_color.meta_theme_color_light}') + document.querySelector('meta[name="theme-color"]').setAttribute('content', '${themeColorLight}') } } const t = saveToLocal.get('theme')