Hexo创建自己的Blog(一)

77 阅读1分钟

场景

使用Hexo和GitHub Page创建自己的博客。

创建GitHub Page

GitHub会自动识别被命名为your-user-name.github.io的Repository为GitHub Page。 在Repository中添加index.html,其中的内容会被自动设定成主页的内容。

另外,刚被创建的GitHub Page可能要等一会才能看到。

创建个人Token

为了将本地的内容发布到GitHub Page,需要申请一个GitHub Personal Access Token。 参照下面的文档进行生成,并暂存。

docs.github.com/cn/authenti…

安装Hexo

参照Hexo官方网站。

hexo.io/zh-cn/

Hexo需要使用nodejs环境,所以要事先安装nodejs。

nodejs.org/en/

初始化Hexo

参照下面的文档初始化Hexo。

hexo.io/zh-cn/docs/…

安装 hexo-deployer-git

最好使用最新版的node和npm,否则容易发生异常

npm install hexo-deployer-git --save

配置_config.yml文件

配置Hexo的_config.yml文件,在最后添加以下内容。

deploy:
  type: git
  repo: https://github.com/your-user-name/your-user-name.github.io
  branch: main
  token: 刚才暂存的Token

将Hexo发布到GitHub

在当前工程路径下执行以下命令。

hexo clean && hexo deploy

参考

hexo.io/zh-cn/docs/…