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

推荐订阅源

A
Arctic Wolf
博客园 - 聂微东
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
小众软件
小众软件
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
L
LangChain Blog
A
About on SuperTechFans
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
T
The Blog of Author Tim Ferriss
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
Know Your Adversary
Know Your Adversary
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Palo Alto Networks Blog
Scott Helme
Scott Helme
S
Secure Thoughts
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
H
Heimdal Security Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Help Net Security
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
G
Google Developers Blog
博客园 - Franky
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
Kaspersky official blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tenable Blog
Google Online Security Blog
Google Online Security Blog
PCI Perspectives
PCI Perspectives

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)