Hexo+Next主题美化博客
前言
有了前面那篇如何搭建博客的文章介绍指导,我们现在可以很容易的搭建博客了,不过既然是属于自己的博客网站,自然也就想让其更加美观,Hexo 博客支持很多主题风格,官网 https://hexo.io/themes/ 截止目前拥370个不同风格的主题,下面介绍一下Hexo博客的主题美化操作。
Next 主题 https://theme-next.js.org/ 是为 Hexo 打造的一款高品质优雅主题,支持非常多的外部插件和功能选项。我目前使用的是 NexT.Gemini V8.12.3 版本,下面我会介绍关于 Next 8 主题的基本安装配置和界面美化。
安装
确保你已经安装了Hexo 并成功地创建了一个站点,因为以下文档要求你在站点根目录(blog_folder)下操作。
安装 Next 主题
安装 Hexo 主题的2种方式:
打开终端,切换到 Hexo 站点根目录,通过 npm 安装 Next 主题:
1
2$ cd blog_folder
$ npm install hexo-theme-next打开终端,切换到 Hexo 站点根目录,使用 git下载 Next 主题的源代码:
1
2$ cd blog_folder
$ git clone https://github.com/next-theme/hexo-theme-next themes/next
升级 Next 主题
Next 主题的新版本每月发布一次,请在更新主题前阅读发布说明,可以使用以下命令更新Next主题:
通过npm安装最新版本:
1
2$ cd hexo-site
$ npm install hexo-theme-next@latest或者更新到最新的主分支:
1
2
3$ cd blog_folder
$ cd themes/next
$ git pull origin master
配置
通过修改配置文件可以直接修改主题样式Git
配置文件
在安装 Hexo 和 Next 之后,你可能会发现有两个配置文件被 Hexo 使用,它们都被称为 _config.yml:
第一个在站点根目录 blog_folder下,它包含了Hexo的配置。
第二个在主题根目录下(例如:thems/next/_config. yml 或 node_modules/hexo-theme-next/_config.yml)。它由 Next 提供,包含主题的配置。
让我们把第一个文件叫做 Hexo配置文件,把第二个文件叫做 Next 配置文件。
注意:npm方式安装主题,默认配置文件在node_modules/hexo-theme-next/_config.yml,git方式安装主题,默认配置文件在themes/next/_config.yml
但是,不建议直接修改主题配置文件,因为通过git或npm升级下一个版本主题时,配置文件会被覆盖,那如何解决这个问题呢?
- 请确保你使用的是 Hexo 5.0或更高版本。
- 在站点的根目录下创建一个配置文件:_config.next.yml。
- 将所需的Next主题选项从NexT配置文件复制到此配置文件。
如果是第一次安装 Next,则使用以下命令复制整个NexT配置文件即可:
1 | # Installed through npm |
以后所有配置只需要更改站点根目录下的_config.yml和 _config.next.yml两个配置文件就可以了,升级Next时也不会受影响。
Hexo 基本配置
更改站点根目录下的 _config.yml 文件
站点基本配置
1
2
3
4
5
6
7
8
9
10
11
12# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site # 站点配置
title: Shalling's Blog # 网站标题
subtitle: '新时代农民工' # 网站副标题
description: 'Stay hungry,Stay foolish.' # 网站描述
keywords:
author: Shalling Zhang # 作者昵称
language: zh-CN # 显示语言
timezone: 'Asia/Shanghai' # 所在时区启用 Next 主题
1
2
3
4
5# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
#theme: landscape # 禁用默认主题
theme: next # 启用next主题更改 Hexo 配置文件后,需要重新生成站点文件,新的主题样式才能生效。
1
2
3
4$ cd ~/blog_folder
$ hexo clean
$ hexo generate
$ hexo server
Hexo is running at http://localhost:4000/ . Press Ctrl+C to stop.
Next 基本配置
更改站点根目录下的 _config.next.yml 文件
主题风格方案配置
Next主题自带4种不同的风格方案,取消哪个方案名称前面的#注释,即采用该方案
1
2
3
4
5
6
7
8
9# ---------------------------------------------------------------
# Scheme Settings
# ---------------------------------------------------------------
# Schemes # 主题方案(Muse、Mist、Pisces、Gemini 共4种,可任选1种)
#scheme: Muse
#scheme: Mist
#scheme: Pisces
scheme: Gemini # 采用 Gemini 方案开启夜间模式
夜间模式没有独立切换开关,会跟随系统主题自动切换显示效果
1
2# Dark Mode
darkmode: true # true开启,false关闭自定义网站图标
在站点根目录下的source目录新建_uploads文件夹用于存放站点图片资源
1
2
3
4
5
6
7
8
9
10favicon:
# small: /images/favicon-16x16-next.png
# medium: /images/favicon-32x32-next.png
# apple_touch_icon: /images/apple-touch-icon-next.png
# safari_pinned_tab: /images/logo.svg
small: /uploads/favicon-16x16-next.png # 网站图标路径
medium: /uploads/favicon-32x32-next.png # 网站图标路径
apple_touch_icon: /uploads/apple-touch-icon-next.png
safari_pinned_tab: /uploads/logo.svg
#android_manifest: /manifest.json配置 “知识共享国际许可协议”
1
2
3
4
5
6
7
8
9
10
11
12# Creative Commons 4.0 International License.
# See: https://creativecommons.org/about/cclicenses/
creative_commons:
# Available values: by | by-nc | by-nc-nd | by-nc-sa | by-nd | by-sa | cc-zero
license: by-nc-sa # license 值
# Available values: big | small
size: small # 显示大小
sidebar: true # 侧边栏是否显示
post: true # 文章是否显示
# You can set a language value if you prefer a translated version of CC license, e.g. deed.zh
# CC licenses are available in 39 languages, you can find the specific and correct abbreviation you need on https://creativecommons.org
language: deed.zh # 中文配置网站菜单栏
新增加菜单项,需要新增加对应的页面,
首先,取消 about、tags、categories前面的#注释符号
1
2
3
4
5
6
7
8
9menu:
home: / || fa fa-home # 首页
about: /about/ || fa fa-user # 关于
tags: /tags/ || fa fa-tags # 标签
categories: /categories/ || fa fa-th # 分类
archives: /archives/ || fa fa-archive # 归档
#schedule: /schedule/ || fa fa-calendar
#sitemap: /sitemap.xml || fa fa-sitemap
#commonweal: /404/ || fa fa-heartbeat其次,新增about、tags、categories页面
1
2
3$ hexo new page about # 新增 about 页面
$ hexo new page tags # 新增 tags 页面
$ hexo new page categories # 新增 categories 页面在站点根目录source/_posts/下会生成tags、categories、about三个文件夹,每个文件夹中都有一个index.md文件,接下来分别修改每个文件内容。
标签页
1
2
3
4
5---
title: 标签
date: 2022-08-19 11:06:30
type: tags
---分类页
1
2
3
4
5---
title: 分类
date: 2022-08-19 11:06:43
type: categories
---关于页
1
2
3
4
5---
title: 关于
date: 2022-08-19 11:06:23
type: about
---侧边栏位置
1
2
3
4sidebar:
# Sidebar Position.
# position: left # 页面左侧
position: right # 页面右侧更改网站默认头像
1
2
3
4
5
6
7
8avatar:
# Replace the default image and set the url here.
#url: /images/avatar.gif
url: /uploads/avatar.png # 头像图片位置
# If true, the avatar will be displayed in circle.
rounded: false # true 头像外边框显示圆形
# If true, the avatar will be rotated with the cursor.
rotated: false # 鼠标悬浮,图片旋转配置社交链接图标
1
2
3social:
GitHub: https://github.com/shallingzhang || fab fa-github
E-Mail: mailto:2026355878@qq.com || fa fa-envelope配置脚标显示:
Powered by Hexo & Next 信息是否显示
1
2# Powered by Hexo & NexT,true or false to display.
powered: true # false 不显示备案信息
1
2
3
4
5
6
7
8
9
10# Beian ICP and gongan information for Chinese users. See: https://beian.miit.gov.cn, http://www.beian.gov.cn
beian:
enable: false # true 开启显示
icp: 京ICP备 1234567890号-1
# The digit in the num of gongan beian.
gongan_id: 1234567890
# The full num of gongan beian.
gongan_num: 京公网安备 1234567890号
# The icon for gongan beian. See: http://www.beian.gov.cn/portal/download
gongan_icon_url: /uploads/beian.png
插件
hexo-deployer-git
插件说明
1 | # 一键部署功能:让你只需一条命令就能将Hexo网站部署到GitHub服务器上。 |
安装插件
1 | $ npm install hexo-deployer-git --save |
修改配置
1 | $ cd ~/blog_folder |
hexo-generator-searchdb
插件说明
1 | # 搜索数据生成插件:能够生成一个搜索索引文件,该文件包含你的文章的所有必要数据,你可以用这些数据为你的博客编写一个本地搜索引擎。 |
安装插件
1 | $ npm install hexo-generator-searchdb --save |
修改配置
1 | $ cd ~/blog_folder |
hexo-word-counter
插件说明
1 | # 在 Hexo 博客站点中统计文章的符号个数和阅读时间 |
安装插件
1 | $ npm install hexo-word-counter --save |
修改配置
1 | $ cd ~/blog_folder |
美化
看板娘
安装插件
1 | $ npm install --save hexo-helper-live2d |
安装模型
1 | $ npm install --save live2d-widget-model-z16 |
配置显示
请向 Hexo 的 _config.yml 文件或主题的 _config.next.yml 文件中添加配置.
1 | live2d: |
可用模型列表
1 | live2d-widget-model-chitose |
卸载模型
1 | $ npm uninstall live2d-widget-model-z16 |
页面圆角与顶部边距
在站点根目录下的source文件夹中创建_data文件夹,用于存放自定义页面内容
1 | $ mkdir ~/blog_folder/source/_data |
配置 /source/_data/variables.styl ,默认没有,需要新建 variables.styl
1 | // 页面圆角设置 |
配置 /source/_data/styles.styl ,默认没有,需要新建 styles.styl
1 | /* 顶部边距 */ |
修改主题配置文件 _config.next.yml,开启自定义页面相关配置
1 | custom_file_path: |
背景图片
自定义背景图片,需要现将自己喜欢的图片(建议大小 200K 以内)放在 source/uploads目录下,并重命名为 background
然后配置 source/_data/ styles.styl
1 | // 添加背景图片 |
页面透明度
配置 source/_data/ styles.styl
1 | //博客内容透明化 0-1 |
页面加载进度条
修改主题配置文件 _config.next.yml
1 | # Progress bar in the top during page loading. |
背景动画:随机丝带
修改主题配置文件 _config.next.yml
1 | # Canvas ribbon |
站点访问统计
修改主题配置文件 _config.next.yml
1 | # Show Views / Visitors of the website / page with busuanzi. |
字体
修改主题配置文件 _config.next.yml
1 | # --------------------------------------------------------------- |
配置 source/_data/ styles.styl 文件,自定义字体:
1 | /************************* 字体设置 ************************/ |
鼠标
安装fireworks点击特效动画
1 | npm install next-theme/hexo-next-fireworks # Fireworks animation for NexT. |
代码块
修改主题配置文件 _config.next.yml
1 | codeblock: |
粒子钟
修改主题配置文件 _config.next.yml
1 | custom_file_path: |
新建侧边栏粒子钟配置文件 source/_data/sidebar.njk,添加如下代码:
1 | <div style=""> |
编辑 source/_data/styles.styl 样式文件,添加如下代码:
1 | // 粒子时钟样式 |
雪花飞舞
新建 blog_folder/node_modules/hexo-theme-next/source/js/snow.js文件,添加如下代码:
1 | /* 雪花飞舞 */ |
新建 source/_data/body-end.styl 样式文件,添加如下代码:
1 | <!-- 引入jQuery --> |
修改主题配置文件 _config.next.yml,开启自定义页面相关配置
1 | custom_file_path: |
雪花样式二:snow2.js ,引用方法和snow.js 一致
1 | /*样式二:无齿轮雪花*/ |
站点运行时间
新建页脚配置文件 source/_data/footer.njk,添加如下代码:
1 | <!-- 站点运行时间 --> |
修改主题配置文件 _config.next.yml , 启用自定义页脚样式文件。
1 | custom_file_path: |
参考站点
https://vkali.com/categories/Hexo/