1.1 环境依赖与初始化
Hexo CLI 安装:
bashnpm install hexo-cli -g
项目初始化:
bashhexo init <project-name>
cd <project-name>
npm install
此步骤创建了一个标准的、包含默认主题 landscape 的Hexo项目。
1.2 主题集成:Butterfly
选择理由: Butterfly 主题拥有极其丰富的配置项、活跃的社区和强大的扩展性,是实现高度定制化视觉效果的最佳选择。
安装:
bash# 从GitHub克隆最新稳定版主题
git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
启用: 修改 Hexo 主配置文件 (_config.yml) 的 theme 字段:
theme: butterfly
安装渲染器: Butterfly 的模板和样式依赖 pug 和 stylus。
bashnpm install hexo-renderer-pug hexo-renderer-stylus --save
创建主题配置文件: 将 themes/butterfly/_config.yml 复制到项目根目录,重命名为 _config.butterfly.yml,以实现配置与主题的分离。
1.3 核心插件安装
npm install hexo-tag-aplayer --save (即使我们最终用注入法,安装此插件也能解决一些依赖问题)npm install hexo-wordcount --save
npm install hexo-generator-searchdb --save至此,一个功能基础、可运行的 Butterfly 博客搭建完成。
第二部分:视觉特效与环境优化 (装修工程)
2.1 “罗德岛UI”视觉风格植入
_config.butterfly.yml):
dark_mode: enable: truedisplay_mode: dark (设为默认)_config.butterfly.yml -> theme_color):
#F09022),链接和强调色 (paginator) 使用科技蓝 (#00BFFF)。_config.butterfly.yml -> font):
Exo 2。
font_link: "https://fonts.googleapis.com/...
font_family: "'Exo 2', sans-serif"2.2 玻璃拟态 (Glassmorphism) 效果实现
原理: 通过全局背景图 + 半透明模糊前景实现。
步骤:
在 _config.butterfly.yml 中设置一个全局背景图:
background: url(/img/ark-background-blur.jpg)
创建自定义样式表 source/css/custom.css。
在 _config.butterfly.yml 的 inject.head 中注入此CSS文件。
在 custom.css 中,强制主内容容器 #body-wrap 背景透明,让 body 背景图得以显现。这是最关键的一步,解决了“一片漆黑”的问题。
css[data-theme="dark"] #body-wrap { background: transparent !important; }
在 custom.css 中,为所有卡片元素 (.card-widget, #recent-posts > .recent-post-item 等) 添加半透明背景、背景模糊 (backdrop-filter) 和边缘高光样式。
2.3 动态与交互特效
_config.butterfly.yml -> subtitle):
enable: true, effect: true。sub: 列表中写入明日方舟风格的短语,如“你好,博士。”_config.butterfly.yml -> canvas_nest):
enable: true,并将 color 设置为主题橙黄色。_config.butterfly.yml -> preloader):
enable: true,选择 source: 2 (Pace.js 进度条),更具科技感。_config.butterfly.yml -> pjax): enable: true。class="no-destroy",防止其在页面切换时被销毁。2.4 代码块高级美化
切换渲染器: 弃用默认的 highlight.js,改为功能更强大、样式更稳定的 PrismJS。
_config.yml 中,设置 highlight: enable: false,并开启 prismjs: enable: true。主题与样式 (_config.butterfly.yml -> code_blocks):
macStyle: true,实现带有仿 macOS 红绿灯按钮的头部。theme,如 darker (旧版) 或 tomorrow/a11y-dark (新版)。解决换行问题: 在 custom.css 中添加强制换行规则,以解决超长代码行(如 wget URL)无法自动换行的问题。
csspre, code { white-space: pre-wrap !important; word-break: break-all !important; }
2.5 可选趣味性插件
全局吸底音乐播放器 (APlayer):
通过 _config.yml 中开启 aplayer: { meting: true, asset_inject: false }。
在 _config.butterfly.yml 中开启 aplayerInject: { enable: true, per_page: false }。
最终在 inject.bottom 中,使用官方文档推荐的 <div class="aplayer no-destroy"...> 语法,并配置歌单ID。
本文作者:张龙龙
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!