少女祈祷中...

迁移hexo的step by step 浓缩记录

关于hexo和reimu

反复折腾了好几次了, 感觉安装包都下过不少于十遍了. 现在就总结一个浓缩精华版放在这里, 彻底解决所有报错!

详细的版本可参考 https://zhuanlan.zhihu.com/p/60578464

首先:

1
npm install -g hexo-cli

初始化

1
2
hexo init      # 初始化
npm install # 安装组件

github托管

1
npm install hexo-deployer-git --save
1
2
3
4
deploy:
type: git
repository: git@github.com:用户名/用户名.github.io.git
branch: main

[!attention]
此处分支应当为main而不是master, 否则无法正常显示.


reimu主题

使用指南: https://d-sketon.github.io/20230707/hexo-theme-reimu-guide/
github仓库: https://github.com/D-Sketon/hexo-theme-reimu

使用git clone下来. 别的方法不好改设置

1
git clone git@github.com:D-Sketon/hexo-theme-reimu.git

一. 外层_config.yml
需要更改的内容为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Site
title: Hexo
subtitle: ''
description: ''
keywords:
author: John Doe
language: en
timezone: ''

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://example.com
permalink: :year/:month/:day/:title/
permalink_defaults:
pretty_urls:
trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
trailing_html: true # Set to false to remove trailing '.html' from permalinks

此处更改 title, author, language:(zh)
https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes#zh
以及url(设置为博客网站首页网址)

(外层设置中更改语言选项好像不会起效果, )

1
2
3
4
5
6
7
8
9
10

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: hexo-theme-reimu

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: ''

extension改为需要的主题, deploy按照上面的github要求改.

(其余选项的含义可参考 https://hexo.io/zh-cn/docs/configuration )

完成上面一步后, 网站应当能够正常出现reimu主题

二. about, friend
about内容是一个md文件, 写自己想写的东西即可;

friend文件夹中, index.md 内需要留下

1
{% friendsLink friend/_data.yml %}

来生成卡片.

_data.yml里则需要填写友链的资料. (资料里头像的填写还不太容易.)

1
2
3
4
- name: D-Sketon
url: https://d-sketon.github.io/
desc: 一个车万人
image: https://d-sketon.github.io/avatar/avatar.webp

两个文件正常放到外层source下

完成上面一步后, 网站应当能够正常显示about和friend界面.

三. avatar, 封面

更换自己的头像和头图
头像: 正常按照指引设定_data/avater文件夹
默认封面: 正常按照指引设定_data/covers文件夹
文章封面: 采用/image/...的方式即可, 将图片文件放在外层的source/images下. 具体封面在.md文件中给出.
头图: 设定好内层设置, 并将需要的banner放在内层的source/images

同时, 在内层的config文件中修改相关内容

完成上面一步后, 网站应当能够正常显示想要的头像, 头图, 封面.

四. 数学公式:

数学公式基于 Katex,请安装 hexo-renderer-markdown-it-plus

1
2
npm uninstall hexo-renderer-marked --save  
npm install hexo-renderer-markdown-it-plus --save

在内层 _config_yml 中将 math.enable 改为 true

1
2
math:  
enable: true

五. social, widget边栏.
把之前设置里的内容应用到新的设置文件

五. valine评论系统
把之前设置里的内容应用到新的设置文件

七. 导入之前的文章.

在之前的page以及导入的过程中, 发现把文章放进去之后就会报各种错误.
现在试试还会不会报错.

  • 从hello world开始, 分批导入之前的文章, 测试是否会出现问题.
  • 如果出现问题了, 定位到具体出问题的文章,

完成这一步后, 所有的文章应当都可以正常显示! 迁移完成


需要注意的点:

  1. 记得自己每一步都改了些什么, 并仔细观察改动带来的变换. 乱改一气的行为只会导致昏头
  2. 迁移网站之前, 一定要把自己的本地文件夹变成压缩包然后备份起来. 不要相信网盘的自动备份
  3. 老老实实一点一点地改设置文件. ctrl C, ctrl V 一时爽. 带来的后果是灾难性的.