用Hexo建立个人博客并部署到Github
关于如何配置hexo并部署到GitHub pages。
用Hexo建立个人博客并部署到Github
如何在GitHub上部署Hexo博客
安装环境和创建仓库
- 下载安装Node.js、Git和VScode
https://nodejs.org/zh-cn https://git-scm.com/ https://code.visualstudio.com
- Win+R打开cmd,依次输入以下内容查看版本号
1 2 3
node -v npm -v git --version
- 输入以下更换镜像并全局安装hexo
1 2
npm config set registry https://registry.npmmirror.com npm install hexo-cli -g
- 或者使用临时方式不污染全局
1
npm install --registry https://registry.npmmirror.com hexo-cli -g
- 或者使用临时方式不污染全局
- 进入GitHub登录,点击 new 新建仓库,仓库名是自己的账号名,状态公开
初始化博客
- 建立博客文件夹,进入右键点击 Git Bash,输入以下进行初始化
1
hexo init
- 生成静态文件
1
hexo g
- 启动本地服务器
1
hexo s
- 打开浏览器,输入以下进入博客
localhost:4000
创建SSH-key
- 在桌面点击右键 Open Git Bash,输入
1 2
ssh-keygen -t rsa -C "注册邮箱" 按四下回车
-
打开此电脑,进入 C盘 → 用户 → 用户名 →.ssh,用记事本打开id_rsa.pub
-
全选并复制 SSH key
-
回到GitHub,点击 头像 → 设置 → SSH and GPG keys → New SSH key
-
Title任意,粘贴SSH key填入,点击添加
- 回到桌面,右键 Open Git Bash,输入以下查看是否添加成功
1 2
ssh -T git@github.com 出现提示后输入yes
部署到GitHub
-
部署之前可使用Steam++进行加速
- 进入博客文件夹,打开_config.yml,最底部改成以下
1 2 3 4
deploy: type: git repo: git@github.com:用户名/用户名.github.io.git branch: main
- 注意冒号和链接之间有一个空格!
- 在博客文件夹打开 Git Bash,安装hexo的部署工具,输入
1
npm install hexo-deployer-git --save
- 添加GitHub的用户名和邮箱
1 2
git config --global user.email "注册邮箱" git config --global user.name "用户名"
- 输入以下生成静态文件和部署
1 2
hexo g hexo d
-
在弹出的对话框中选择浏览器登录,登录GitHub账户
- 等待GitHub pages部署完成,看到两个绿色的勾即表示成功
This post is licensed under
CC BY 4.0
by the author.