hexo初步部署日记

前言:

hexo是一款基于node.js的静态博客框架,可以快速生成静态网页托管在github上(最重要的是不用花钱)。

github官网

1. 安装node.js

下载地址

2. 安装git

下载地址

3. 安装hexo

这里需要管理员权限,在终端打开管理员cmd或者win+x打开管理员powershell

1
npm install -g hexo-cli

如果出现报错,输入下面代码(注意这是powershell时用,不是cmd)

1
Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned

4. 检查是否成功安装

1
2
3
4
5
node -v

npm -v

hexo -v

出现版本号即成功安装

5. 配置用户名和链接到你的邮箱

1
2
3
git config --global user.name "yourname"

git config --global user.email "youremail"

6. 创建ssh密钥

1
ssh-keygen -t rsa -C "youremail"

7. 添加ssh密钥到github

打开C:\Users\用户名.ssh\id_rsa.pub文件,复制里面的内容,打开github,点击右上角头像,点击settings,点击SSH and GPG keys,点击New SSH key,title任意,将刚刚复制的内容粘贴进key,点击Add SSH key

8. 测试是否连接成功

1
ssh -T git@github.com

如果出现

1
Hi yourname! You've successfully authenticated, but GitHub does not provide shell access.

即成功连接(注意要关掉加速器)

9. 创建仓库

仓库名为yourname.github.io,注意要勾选Initialize this repository with a README(添加一个md文件)

10. 配置hexo

创建一个文件夹,用于存放博客文件

打开文件夹,右键点击更多打开Git Bash Here,也可以用powershell不过需进入文件夹

如果使用powershell,输入

1
2
3
cd yourpath

Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned

接下来二者一致

输入

1
hexo init

或者

1
npx hexo init

11. 配置_config.yml

打开_config.yml文件,在底部1

1
2
3
4
deploy:
type: git
repo: https://github.com/yourname/yourname.github.io.git(你的仓库链接)
branch: main

注意格式

12. 生成静态文件

1
hexo generate

或者

1
hexo g

13. 本地预览

1
hexo server

或者

1
hexo s

打开浏览器,输入localhost:4000,即可看到你的博客

14. 部署

1
hexo deploy

或者

1
hexo d

出现

1
INFO  Deploy done: git

即部署成功

14. 打开博客

打开浏览器,输入yourname.github.io,即可看到你的博客(注意需要等待一段时间)

15. 更新博客

在source文件夹下新建一个md文件,用markdown语法写文章

或者

1
hexo new "filename"

写完后保存,打开终端,输入

1
2
3
4
5
hexo cl

hexo g

hexo d

即更新成功

最后,若是出现报错,请不要担心,可能是网络问题,多试几次即可