环境:nodejs,git

nodejs换淘宝源

1
npm config set registry https://registry.npm.taobao.org

安装Hexo

1
npm install -g hexo-cli

创建Github仓库

将Repository名称改为”[用户名].github.io”,仓库的可见权限必须为public

安装git

git配置用户名和邮箱

1
2
git config --global user.name "[用户名]"
git config --global user.email "[邮箱]"

用户名随意,邮箱使用github的邮箱

查看配置

1
git config -l

生成SSH公钥,用来链接Github

1
ssh-keygen -t rsa -C "邮箱地址"

运行完成后打开C盘的用户文件夹的.ssh文件夹,打开里面的id_rsa.pub文件,复制到github中添加SSH key

测试是否连接到Github

1
ssh -T git@github.com

接着选择一个文件夹运行以下命令初始化hexo博客

1
2
3
hexo init [项目名]
cd [项目名]
npm i

初始化之后,项目文件夹有如下的结构

node_modules:依赖包

scaffaolds:生成文章的模板

source:用来存放文章

themes:主题

.npmignore:发布时忽略的文件(可忽略)

_config.landscape.yml:主题的配置文件

_config.yaml:总体的配置文件

package.json:项目名称、描述、版本和开发等信息

将hexo部署到Github:

安装依赖

1
npm install hexo-deployer-git --save

配置config.yml文件

将最后几行替换成这个

1
2
3
4
deploy:
type: git
repository: git@github.com:[github名称]/[github名称].github.io.git
branch: main

接着hexo三联

1
2
3
hexo clean
hexo g
hexo d