安装,建立和启动Hexo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 全局安装hexo-cli
npm install -g hexo-cli
# 安装插件
npm install hexo-renderer-ejs --save
npm install hexo-renderer-stylus --save
npm install hexo-renderer-marked --save
# 建立Hexo工程,并cd到博客目录里,安装相应的包
hexo init blog
cd blog
npm install
# 生成静态文件,public文件夹
hexo generate
# 启动Hexo
hexo server

修改主题(Fan)

https://hexo.io/themes/

https://github.com/fan-lv/Fan

1
2
3
4
5
6
7
8
9
10
11
12
13
# 拉取选择的主题
git clone https://github.com/fan-lv/Fan.git themes/Fan
# _config.yml中修改主题
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: Fan
# 更新主题
cd themes\Fan
git pull
# 安装依赖
npm install --save hexo-renderer-pug hexo-renderer-stylus
npm install --save hexo-generator-feed hexo-generator-sitemap hexo-generator-archive hexo-browsersync

文章(Markdown 文件)设置


1
2
3
4
5
6
7
8
9
10
11
12
13
# 标题
title: xxx
# 作者
author: xxx
# 标签
tags:
- xxx
# 分类
categories:
- xxx
date: xxx
# 支持置顶
top: 1

部署到GitHub

打开blog目录下的_config.yml配置文件,改如下配置

1
2
3
4
5
6
7
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repo:
github: https://github.com/guobq/guobq.github.io
branch: master
1
2
3
4
# 安装插件
npm install --save hexo-deployer-git
# 部署到github
hexo deploy

Comments

_config.yml配置


1
2
3
4
5
6
7
8
9
10
11
12
13
# comments
comments:
gitment:
enable: true
owner: 'guobq'
repo: 'https://github.com/guobq/k8s'
client_id: 'a91e9ec426714f54a397'
client_secret: '614ed1b11be02220c9a08cd1e8c3fda3195d60a4'

# 可以自由配置 valine 的其他配置项(参考链接 https://valine.js.org/configuration.html)
valine:
appId: '8xUuEcUoXahLwm69LVK1eumF-gzGzoHsz'
appKey: 'NDF5dcJsxuEHHBOLlda7Y07b'

Gitment

获取client_id,client_secret

1.打开https://github.com/settings/developers

2.New OAuth APP

1
2
3
4
5
6
Homepage URL:
https://guobq.github.io/
#开发就是本地的地址加端口,生产就不用说了
Authorization callback URL:
https://guobq.github.io/
#开发就是本地的回调,这个概念不理解的话去学一下Oauth

3.生成Client ID,CLient Secret

Valine

LeanCloud的应用中得到的appId.

https://leancloud.cn/

登录或注册 LeanCloud, 进入控制台后点击左下角创建应用

进入刚刚创建的应用,选择左下角的设置>应用Key,然后就能看到你的APP ID和APP Key了

注册 Algolia账户,创建新的 Index,记下 index name

安装扩展

1
npm install hexo-algolia --save

修改 Algolia 搜索 ACL(访问控制列表) 默认的 Search-Only API Key 不能修改,需要在 All API Keys -> New API Key

勾选 ACLs: search addObject deleteObject listIndexes deletelndex

执行安装

1
2
3
export HEXO_ALGOLIA_INDEXING_KEY=New API Key
# 刷新索引
hexo algolia

获取 Key,更新站点根目录配置

1
2
3
4
algolia:
applicationID: 'Application ID'
apiKey: 'New API Key'
indexName: 'index name'
1
2
3
4
5
# algolia
algolia:
applicationID: '8ICB0LL54F'
apiKey: 'b6e01221a0e1bdb34d69e088b9bd39d8'
indexName: 'blog'

主题配置下开启 Algolia_search

1
2
3
4
algolia_search:
enable: true
hits:
per_page: 10

打开分类,标签,关于

切换到主目录

1
2
3
hexo new page categories
hexo new page tags
hexo new page about

./source/categories,tags,about目录下,会生成index.md

categories/index.md

1
2
3
4
5
layout: layout_single
title: 分类
date: 2020-09-09
type: categories
comments: false

tags/index.md

1
2
3
4
title: tags
date: 2020-09-09
type: "tags"
comments: false

about/index.md

自定义

生成永久文章链接

1.安装

插件源码地址: hexo-abbrlink

1
npm install hexo-abbrlink --save

可能会出现依赖,依据提示安装即可。

2.配置

修改博客根目录配置文件 _config.ymlpermalink

1
2
3
4
5
# permalink: :year/:month/:day/:title/
permalink: p/:abbrlink.html # p 是自定义的前缀
abbrlink:
alg: crc32 #算法: crc16(default) and crc32
rep: hex #进制: dec(default) and hex

不同算法和进制生成不同的格式:

1
2
3
4
5
6
7
8
crc16 & hex
66c8
crc16 & dec
65535
crc32 & hex
8ddf18fb
crc32 & dec
123456789

3.验证

先清理下本地的文件 hexo clean,然后重新生成 hexo g,启动博客 hexo s。该插件会在每篇文章的开头增加内容:

1
abbrlink: df27ccfb

这个字符串就是这篇文章的唯一标识,无论修改标题还是发布文章都不会改变。

参考

https://hexo.io/

https://valine.js.org/

https://blog.csdn.net/u011116672/article/details/51160742

https://blog.csdn.net/weixin_43870742/article/details/102004099

https://blog.csdn.net/qq_42595443/article/details/82466442?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight

https://www.dazhuanlan.com/2019/11/03/5dbeaac238b49/?__cf_chl_jschl_tk__=53c7e61c6cb87976027ff79b485e7bc157d29a40-1602087870-0-AUbOpkBUnGVqTiIPnn1W8j-mk4RiIIk1-VQEcAnnN1JciituXSOs_o7b-405C3oJBLMXE-meOUymlyBwQ0f4jh7Cy3lAeQEblSmezSNOjfACC7iyIoYjP_ZSr0g2rpL-u8U6LeS93EJquJ0jbM7CYuks8Uk2vE6dnkMjTmaEA4peQcMPbE75lqujsB1Ax6lBPIa4dVYUD4iMoLE2BN6E-jVmJqJOb3X4SbtKRwSXMZP0-cPVpi46NOcvpSLgIr5vDKxDJHUd6PPgbsxy6Q-ywtneDqnTqZofb4wjdp-_FJaw_Z-cOWTnRWeFLEngd33Olg