0%

从WordPress迁移到hexo

从WordPress迁移到hexo啦!

自定义css样式

修改博客根目录下的source/_data/styles.styl文件,增加网格背景:

1
2
3
4
5
6
7
8
9
body {
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACFJREFUeNpiZGBg4GegAsBlCD8TqSYNQg2Mo6FEBAAIMACdPABtrSW/IQAAAABJRU5ErkJggg==");
background-repeat: repeat;
background-attachment: fixed;
-webkit-font-smoothing: antialiased;
text-shadow: 1px 1px 1px rgba(0,0,0,.04);
min-height: 100vh;
margin: 0
}

next 主题

增加阅读进度条

修改主题配置文件_config.yml:

1
2
3
4
5
6
7
# Reading progress bar
reading_progress:
enable: true
# Available values: top | bottom
position: top
color: "#37c6c0"
height: 3px

开启版权声明

新版的next和老版开启声明不一样,对着网上许多教程做发现大部分都是过时的,在此记录一下。

更改themes下的主题配置文件_config.yml:

1
2
3
4
5
6
7
8
9
10
11
12
13
links:
Title: https://yoursite.com

# Creative Commons 4.0 International License.
# See: https://creativecommons.org/share-your-work/licensing-types-examples
# Available values of license: by | by-nc | by-nc-nd | by-nc-sa | by-nd | by-sa | zero
# 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
creative_commons:
license: by-nc-sa # 设置多种版权声明
sidebar: false # 博客主页左侧栏是否显示版权声明标记
post: true # 是否开启版权声明
language:

记得改hexo的配置文件_config.yml:

1
2
3
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com

启用mermaid

参考[1]

常用命令

1
2
3
4
5
6
7
8
9
10
# 不要用anaconda自带的pandoc
$ hexo n "博客名称" => hexo new "博客名称" #这两个都是创建新文章,前者是简写模式
$ hexo n draft "博客名称" => hexo new draft "博客名称" #创建草稿
$ hexo p => hexo publish
$ hexo p draft => hexo publish draft #发布草稿,_drafts/xx -> _posts/xx
$ hexo g => hexo generate #生成
$ hexo s => hexo server #启动服务预览
$ hexo d => hexo deploy #部署
$ hexo s --draft # 预览草稿
$ hexo clean && hexo generate && hexo server --debug

增加kindle页

使用muzi502/kindle项目生成网页 该项目的运行命令如下:

1
2
3
python3 kindle.py
github_poster json --json_file date.json --year 2021 --me kindleReading --background-color '#222222'
mv OUT_FOLDER/json.svg date.svg
修改style/css/custom.css的返回键按钮,末尾增加以下内容:
1
2
3
4
5
6
7
.go-back{
position:fixed;
right:2vw;
bottom:3vh;
z-index:5;
border-radius:50%
}
然后在hexo根目录下的source文件夹下新建kindle文件夹,并将上边项目的以下文件拷贝到其中:style,books,index.html,date.svg.

最后修改hexo根目录下的themes/next/_config.yaml,新增kindle一行:

1
2
3
4
5
6
7
8
9
10
menu:
home: / || home
#about: /about/ || user
#tags: /tags/ || tags
#categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat
kindle: /kindle/ || book
可以修改页面的展示文字,比如首字母大写,需要在themes/next/languages/default.yml配置:
1
2
3
4
5
6
7
8
9
10
11
menu:
home: Home
archives: Archives
categories: Categories
tags: Tags
about: About
search: Search
schedule: Schedule
sitemap: Sitemap
commonweal: Commonweal 404
kindle: Kindle

换开发环境,迁移到WSL

从之前的mac环境,迁移到WSL里,需要重新安装以下hexo环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
sudo apt update && sudo apt upgrade -y


sudo apt install -y git curl wget build-essential


# 安装 Node.js 和 npm
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs

# 安装 Hexo CLI, 可以通过@4.3.1指定版本
sudo npm install -g hexo-cli@4.3.1

# 项目本身已存在,需要cd 到你的项目目录,该目录有下面这些目录
_config.yml node_modules/ package.json scaffolds/ source/ themes/

# 在该目录执行
npm install


# 遇到了highlight.js 9.18.5 版本停止维护的问题
npm install highlight.js@10.7.2 --save

npm list highlight.js # 运行后发现还有9.8.15

npm audit fix --force # 强行纠正

hexo clean

hexo generate

hexo server

hexo deploy

# 安装github_poster
pip3 install -U 'github_poster[all]'

Reference

[1] https://alltobenice.gitee.io/2021/03/06/BlogOpt/NexT%E4%B8%BB%E9%A2%98%E4%BC%98%E5%8C%96/