我的Hexo博客搭好了05 - 更换Hexo主题

19 阅读4分钟

文章系列导航

  1. 第01篇 - 选择困难症发作
  2. 第02篇 - 搭建过程之:披荆斩棘,晋级啦!
  3. 第03篇 - 搭建过程之:一路踩坑
  4. 第04篇 - 备份Hexo博客的源码目录,上传到Gitee仓库
  5. 第05篇 - 更换Hexo主题
  6. 第06篇 - 怎么给文章分类、打标签、展示目录
  7. 第07篇 - 怎么制作/about/、/categories/、/tags/页面
  8. 第08篇 - 让世界找到我——SEO大冒险(站点地图制作和提交)
  9. 第09篇 - 添加统计字数和阅读时长的插件
  10. 第10篇 - 怎么插入图片和视频
  11. 第11篇 - 怎么创建文章系列导航
  12. 第12篇 - 自动提交URL到搜索引擎(IndexNow + Google Search Console)
  13. 持续更新中...

1 换成NexT主题

访问 Hexo主题官网,挑选喜欢的主题,按照其说明进行安装和配置,能瞬间改变博客外观。

Hexo默认的主题是 landscape,我换成了Hexo最流行的主题之一,叫做 hexo-theme-next。

我的Hexo项目目录名称为 hexo_blog。执行以下操作:

# 进入 Hexo 项目目录
cd hexo_blog

# 克隆主题到 themes 目录
git clone https://github.com/theme-next/hexo-theme-next themes/next

# 如果要克隆指定版本,则添加 --branch 参数
git clone --branch v8.0.0 https://github.com/theme-next/hexo-theme-next themes/next

# 删除themes/next/目录下的 .git 文件夹,防止与hexo_blog目录所属的git仓库冲突
rm -rf .git/

2 配置NexT主题

2.1 修改主配置文件

进入 Hexo博客项目根目录,打开 _config.yml,修改如下配置项:


# 主题设置为 next
theme: next

# Site. 站点配置
# 你的博客标题
title: Witt的博客
# 博客副标题
subtitle: ''
# 博客描述
description: ''
# 关键词
keywords:
# 你的名字
author: Witt
# 语言
language: zh-CN
# 时区
timezone: 'Asia/Shanghai'

2.2 进入到 hexo_blog/themes/next 目录,编辑 _config.yml 文件,根据主题说明进行配置。

里面本来也有一些默认配置项,我根据自己的喜好进行了修改。具体修改的项如下:

# 自定义样式文件路径,我新建了一个 styles.styl 文件,用于存放自定义的CSS样式代码
custom_file_path:
  style: source/_data/styles.styl

# Sidebar Position. 侧边栏位置,默认是左侧,我改为了右侧。侧边栏包含了分类、标签、归档、站点地图、文章目录等内容。
sidebar:
  position: right

# 展示自定义导航菜单,因为要展示这个,我新建了 source/about/index.md、source/categories/index.md、source/tags/index.md 这些文件,后面详细说明
menu:
  # 首页
  home: / || fa fa-home
  # 关于我
  about: /about/ || fa fa-user
  # 标签页面
  tags: /tags/ || fa fa-tags
  # 分类页面
  categories: /categories/ || fa fa-th
  # 归档文章页面
  archives: /archives/ || fa fa-archive
  # 站点地图页面
  sitemap: /sitemap.xml || fa fa-sitemap

# Social Links. 社交链接,我添加了 GitHub 和 Gitee 这两个平台的链接。
# Usage: `Key: permalink || icon`
# Key is the link label showing to end users.
# Value before `||` delimiter is the target permalink, value after `||` delimiter is the name of Font Awesome icon.
social:
  GitHub: https://github.com/wittzh || fab fa-github
  Gitee: https://gitee.com/mediocrep || fab

3 更换成其他主题

方法和更换NexT主题类似,比如更换为 fluid 主题,步骤如下:

# 进入 Hexo 项目目录
cd hexo_blog

# 克隆主题到 themes 目录
git clone https://github.com/fluid-dev/hexo-theme-fluid themes/fluid

# 删除themes/fluid/目录下的 .git 文件夹,防止与hexo_blog目录所属的git仓库冲突
rm -rf .git/