diff --git a/_config.yml b/_config.yml index 3fea2ad..68b25a1 100644 --- a/_config.yml +++ b/_config.yml @@ -471,6 +471,8 @@ site_verification: # blockquote_padding_color: "#49b1f5" # blockquote_background_color: "#49b1f5" # scrollbar_color: "#49b1f5" +# meta_theme_color_light: "ffffff" +# meta_theme_color_dark: "#0d0d0d" # The top_img settings of home page # default: top img - full screen, site info - middle (默認top_img全屏,site_info在中間) diff --git a/layout/includes/head.pug b/layout/includes/head.pug index 5c7c397..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' ? '#0d0d0d' : '#ffffff' +- 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 8da1179..9c845d4 100644 --- a/scripts/helpers/inject_head_js.js +++ b/scripts/helpers/inject_head_js.js @@ -8,6 +8,10 @@ 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 = { set: function setWithExpiry(key, value, ttl) { @@ -62,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', '#0d0d0d') + 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', '#ffffff') + document.querySelector('meta[name="theme-color"]').setAttribute('content', '${themeColorLight}') } } const t = saveToLocal.get('theme')