Hexo同步语雀文章一

创建 Hexo 博客

已经有 Hexo 博客的可以跳过。如果你是 Jekyll ,也可以跳过。

  • 安装 Node.js
  • 安装 Hexo 脚手架
1
2
3
4
5
npm install -g hexo-cli
hexo init blog
cd blog
npm install or yarn install
hexo server

安装语雀文章下载插件

yuque-hexo 是一个 Node.js 环境下的语雀下载器,使用 npm 安装

  • 安装 yuque-hexo
  • 注册语雀,创建知识库,获得你的个人路径和知识库的名字,比如我的博客的知识库是 :https://www.yuque.com/fangcao/api
  • 在 Hexo 博客的目录下面的 package.json 中,进行下面的配置
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
39
{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"hexo": {
"version": "3.8.0"
},
"dependencies": {
"hexo": "^3.8.0",
"hexo-generator-archive": "^0.1.5",
"hexo-generator-category": "^0.1.3",
"hexo-generator-index": "^0.2.1",
"hexo-generator-tag": "^0.2.0",
"hexo-renderer-ejs": "^0.3.1",
"hexo-renderer-marked": "^1.0.1",
"hexo-renderer-stylus": "^0.3.3",
"hexo-server": "^0.3.3"
},
"yuqueConfig": {
"baseUrl": "https://www.yuque.com/api/v2",
"login": "fangcao",
"repo": "api",
"mdNameFormat": "title",
"postPath": "source/_posts/yuque",
"token": "放上自己的语雀token"
},
"scripts": {
"clean": "hexo clean",
"clean:yuque": "DEBUG=yuque-hexo.* yuque-hexo clean",
"deploy": "hexo deploy",
"publish": "npm run clean && npm run deploy",
"dev": "hexo s",
"sync": "DEBUG=yuque-hexo.* yuque-hexo sync",
"reset": "npm run clean:yuque && npm run sync"
},
"devDependencies": {
"yuque-hexo": "^1.6.1"
}
}
参数名 含义 默认值
postPath 文档同步后生成的路径 source/_posts/yuque
cachePath 文档下载缓存文件 yuque.json
mdNameFormat 文件名命名方式 (title / slug) title
adapter 文档生成格式 (hexo/markdown) hexo
concurrency 下载文章并发数 5
baseUrl 语雀 API 地址 -
login 语雀 login (group) -
repo 语雀仓库短名称 -
onlyPublished 只展示已经发布的文章
  • 如果不是 Hexo 博客,则需要按照上面的文件保存一个 package.json 到博客目录,并且配置 postPath 为正确的文章目录
  • 同步文章
1
yuque-hexo sync
  • 语雀同步过来的文章会生成两部分文件;
    • yuque.json: 从语雀 API 拉取的数据
    • source/_posts/yuque/*.md: 生成的 md 文件
  • 支持配置 front-matter, 语雀编辑器编写示例如下:
  • 语雀编辑器示例,可参考hexo的终极玩法

配置GitHub pages

首先需要一个GitHub账号
然后可以
具体可参照官方教程

改变主题

这是官方的主题网站
将主题clone到你的theme,在配置文件中

将theme改变为你下载的主题名称
然后编译,运行,发布。

使用next主题的可以参考官方网址

配置Travis CI

之前也有不少文章用不同的方法解决上述的问题,例如利用 Dropbox 同步或者利用 Github 的 Webhooks 进行自动部署。这些方法需要付出一定的成本,因为都需要利用到一台 VPS 去完成。而今有一个更加简单而且免费的方法去完成 hexo 的自动部署,就是利用 Travis CI。

重点来了,详细步骤可参考用 Travis CI 自动部署 hexo手把手教你Travis CI,作者已经说的比较详细。
需要注意的一点是:在package.json中增加depoly的命令行语句,防止travis在自动执行到npm run deploy这一步的时候报找不到该script的错。

1
2
3
"scripts": {
"deploy": "hexo clean && hexo g -d"
},

上述代码加在dependencies同级即可。

查看TravisCi https://travis-ci.org/fangcao7618/fangcao7618.github.io

主题:

主题选择:next 主题
主题二:https://hexo.io/themes/

https://theme-next.org/

例子:https://www.jinrishici.com/