hexo-wikitten 搭建

安装 Hexo

1
2
# npm install -g hexo-cli
yarn global add hexo-cli

初始化

1
2
3
4
5
6
7
8
9
10
11
mkdir wiki && cd wiki
hexo init

git clone https://github.com/zthxxx/hexo-theme-Wikitten.git themes/Wikitten

# npm i -S hexo-autonofollow hexo-directory-category hexo-generator-feed hexo-generator-json-content hexo-generator-sitemap
yarn add hexo-autonofollow hexo-directory-category hexo-generator-feed hexo-generator-json-content hexo-generator-sitemap

cp -rf themes/Wikitten/_source/* source/
cp -rf themes/Wikitten/_scaffolds/* scaffolds/
cp -f themes/Wikitten/_config.yml.example themes/Wikitten/_config.yml

主题配置

hexo 一般有两个配置文件需要修改,一个是主题相关的 (theme/<theme_name>/_config.yml),一个是站点相关的 (_config.yml)。

首先是主题相关的,这个大部分使用默认配置即可,主要修改需要修改的有profilehistory_control中关于个人信息的东西。

而站点相关的,则需要修改比较多东西:

  • 修改themeWikkten
  • 设置站点信息(如title,subtitle等)
  • 配置urlpermalink
  • 配置deploy,但是因为准备部署到vercel中,所以好像没太大必要配置。
  • 然后就是一些插件的配置了:
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
38
## Markdown
## https://github.com/hexojs/hexo-renderer-marked
marked:
gfm: true

## Plugins: https://hexo.io/plugins/
### JsonContent
jsonContent:
meta: false
pages:
title: true
date: true
path: true
text: true
posts:
title: true
date: true
path: true
text: true
tags: true
categories: true
ignore:
- 404.html

### Creat sitemap
sitemap:
path: sitemap.xml

### Adds nofollow attribute to all external links in your hexo blog posts automatically.
nofollow:
enable: true
exclude:
- wiki.codeand.fun

# 多级目录结构
auto_dir_categorize:
enable: true # options:true, false; default is true
force: true # options:true, false; default is false

部署到 vercel

创建github仓库,并把wiki相关文件push上去。

1
2
3
4
5
6
7
8
9
git init
git add .
# 把主题作为源文件上传,如果不删除的话,会是`submodule`的形式
rm theme/Wikkten/.git
# 删除`_config.yml`
sed -e '/_config.yml/d' theme/Wikkten/.gitignore
git commit -m "init wiki"
git remote add origin git@github.com:wuxiaobai24/wiki.git
git push -u origin master

然后在vercel中导入对应的仓库,并选择hexo作为环境即可,使用默认配置就能直接部署了。

如果需要配置自己域名的话,需要在vercel添加自己的域名,然后给域名添加一个 CNAME 类型执行cname.vercel-dns.com

如果你是用CloudFlare的话,还需要进行一些额外配置,具体细节可以看 vercel 给出的方案 - How do I use a Cloudflare domain with Vercel?
简单来将就是,将CloudFlare的 DNS 配置修改成不代理的,即“仅限DNS”。

跳过某些文件的渲染

在站点的_config.yml中有skip_render可以实现跳过渲染:

1
2
3
4
skip_render:
- "_posts/.obsidian/*"
- "_posts/.stfolder/*"
- "_posts/template/*"

文章加密

1
npm i -s hexo-blog-encrypt
1
2
3
4
5
6
7
8
# 密码
encrypt:
abstract: Here's something encrypted, password is required to continue reading.
message: Hey, password is required here.
tags:
- {name: Daily, password: password} # 对包含 Daily 标签的文件进行加密。
wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
wrong_hash_message: Oh, these decrypted content cannot be verified, but you can still have a look.