惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Troy Hunt's Blog
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta
F
Full Disclosure
Recorded Future
Recorded Future
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
博客园_首页
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
H
Hacker News: Front Page
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
博客园 - 司徒正美
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security
Cloudbric
Cloudbric
PCI Perspectives
PCI Perspectives
有赞技术团队
有赞技术团队
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
TaoSecurity Blog
TaoSecurity Blog
L
Lohrmann on Cybersecurity
量子位
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tailwind CSS Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
P
Proofpoint News Feed
N
News and Events Feed by Topic
罗磊的独立博客
T
Threat Research - Cisco Blogs
Schneier on Security
Schneier on Security
T
Tor Project blog
IT之家
IT之家
M
MIT News - Artificial intelligence
S
Security @ Cisco Blogs
O
OpenAI News
AI
AI
S
Securelist
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
月光博客
月光博客
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题

AsyncX

V3 博客重构 第三期-用Notion进行网页收藏/订阅管理/阅读数据查看 第二期-Vitepress配制指南 使用MCSManager搭建泰拉瑞亚服务器 额外技能-如何穿手串 [更新]首考PTE的一些问题/快速入门 重构博客,底层换成Astro时候遇到的问题 熵,生命 如何使用Mac玩双人成行 解决手柄无法在Macbook玩星露谷的问题 什么在阻止我们走向主观来说更好的生活? 雅思首考的一些感受 如何听更好音质的歌 苏州三天行 毕业,以及短期的安排 近日&首阳 第一期-Beancount使用体验 在MacOS配制Rime(鼠须管)输入法 更换主力浏览器为Arc浏览器 语言规范可以帮你更好得到答案 删掉抖音,重拾RSS 简单注册ChatGPT的方法 2023年,一些回顾 让你的MacBook更顺手一点 第一次养猫发现的一些事 绑架代替购买了一只小猫 数字藏品? 近些天和对于科幻的一些看法 如何配置一个静态博客的工作流
为hexo博客添加黑暗模式(使用darkmode.js)
AsyncX · 2023-03-28 · via AsyncX

20230408更新.更换博客主题,本文教程无变化.

最近总在晚上写一些东西,突然想起来博客还没有黑暗模式.我的博客用的是vexo主题,去翻了一下vexo的github:https://github.com/yanm1ng/hexo-theme-vexo … 本文主要为hexo vexo主题添加一个可以切换的黑色/夜间模式。本文介绍如何实现按钮来切换,包括如何在代码部分也切换夜间模式。

安装

跟据darkmode.js 官网的描述,在网页的head引入

<script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js"></script> 
<script>
  function addDarkmodeWidget() {
    new Darkmode().showWidget();
  }
  window.addEventListener('load', addDarkmodeWidget);
</script>

ps:由于国内使用jsdelivr并不稳定,我将博客的所有文件都放在了github,并通过netlify加速.

效果

你可能会发现到上面那步,效果和我的并不一样,字体仍然是黑色或者标签的边框和文章代码框是白色. 这时候就需要对颜色微调.

优化

前言

darkmode.js被激活的时候,会在body上添加一个.darkmode--activated的类,如果我们把上面没有暗黑化的样式添加到css里1,就可以实现自己需要的效果. 我使用的主题是vexo,部分文件结构如下所示

├── _config.styl
├── _partial
│   ├── about.styl
│   ├── archive.styl
│   ├── catalog.styl
│   ├── footer.styl
│   ├── header.styl
│   ├── markdown.styl
│   ├── pager.styl
│   ├── project.styl
│   └── tags.styl
├── layout.ejs
└── style.styl

我这里仅使用了通过修改css来改变前端样式,仅供参考.

修改style.styl

这是我的优化,把tag和header的背景透明化.具体原理就是当添加暗黑的类属性后我的这些设置会覆盖原来设置的color/background等属性,就可以做到调整暗黑模式的颜色,当关闭暗黑模式时,仅这些颜色属性取消,就可以恢复正常的样子. 当然也可以有额外的设置,比如增大加粗暗黑模式的字体,修改暗黑模式的页面属性等.

  1. hexo博客next主题添加夜间模式(Dark Mode)