Github 配置 点击这里打开 github ,登陆自己的账号(没有的自行注册)。如下图:
创建仓库 注意:部署 hexo 的仓库名必须以 .github.io
结尾。因为仓库名就是你今后访问部署在 github 上的 hexo 的域名地址
1.登陆之后,点击右上角 +
号,在下拉菜单中点击 New repository
,如下图:
2.在弹出的 Create a new repository
页面中输入 Repository name
(比如我这里输入的为hexo.github.io
),然后勾选上 Initialize this repository with
下面的 Add a README file
,最后点击地下的 Create repository
。如图:
3.仓库创建好后,会自动进入到仓库页面,此时,我们可以点点击绿色的 <> Code
按钮,获取仓库的地址(比如我这里的仓库地址为:https://github.com/leazhi/hexo.github.io.git),如下图:
导入公钥 创建密钥对 1.在本地执行 ssh-keygen
命令,生成密钥对。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 $ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/veazhi/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/veazhi/.ssh/id_rsa Your public key has been saved in /home/veazhi/.ssh/id_rsa.pub The key fingerprint is: SHA256:gTlJsj9X7oHA+PGzubiJwSy7ah2BHwehvYLvhhmEReg veazhi@vm001-ubuntu2204 The key's randomart image is: +---[RSA 3072]----+ | o..o . | |. +. * + | |oo..+ O . . | |oE o.+ = = | |o...+ + S o | |...= o = . | | ++ = o . | |oo.+ o o . | |oo+.. +.. | +----[SHA256]-----+
2.查看公钥文件 /home/veazhi/.ssh/id_rsa.pub
的内容(这个内容就是后面我们要导入到 github上的密钥内容):
1 2 $ cat /home/veazhi/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCxi8aiJffjfDj2Qksc/qfCnhvqlgSsr/ih1YE3Nf9WZUpk22IAGYNFAtBBFu+KWsOmaiIpJymAiDVZdbd/WqOOI/dyn0C0rsvXt4GMrSKeVSl5K+Jx36TMKdnJ0cgMwk6fylBUky9/UMbtWoIENi5/DmX77BuczPNstb5z/zumXmh3Yi+4dnG8L1MWYLiMfSyE1tuYcPWx9V962GqcTyoN5Zrk36vfiGRJdUWuex70NHxakk4LAkmX6buNqlFlHpAkAM/3iJ2f6k6voyeEPvoSy0dNeyUyw/Y/MO+tfyz//3E9BcpHv9V1RBn0HJxnjWTRPtKKhDt+ynLHlTEjkfvM9iI39yeBS1NJ87IggDhqR1d8RyTWKSMEeH8F/7tBwwt8gpvfwVVCD6oOmyg97puGox5kqx+Sa+66/D2OL+LJsmAVG+yR5PSrwxsnK6vuRKO+aOF4Cx/y1kXfi/S6cQYPJFaBMa//qguirlWU9fnW8yg3PeZrvbUH1liJEQ5/WFM= veazhi@vm001-ubuntu2204
github 导入公钥 1.点击 github 右上角图像图标,如下图:
2.在弹出的个人属性列表中点击 Settings
,如图:
3.接着,在左侧菜单栏中点击 SSH and GPG keys
,然后在右侧的 SSH keys
属性栏下点击绿色的 New SSH key
。如图:
4.接下来,在 Add new SSH key
页面将上面获取到的公钥内容复制到 Key
框中,至于 Title
根据自己的想法自定义即可!最后,点击 Add SSH key
,如下图:
hexo 部署 在部署 hexo 之前,先确保本机有 nodejs 环境。
hexo 安装 1.将上面创建的 github 仓库克隆到本地:
1 2 3 4 5 6 $ git clone https://github.com/leazhi/hexo.github.io.git Cloning into 'hexo.github.io' ... remote: Enumerating objects: 3, done . remote: Counting objects: 100% (3/3), done . remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (3/3), done .
2.进入项目目录:
3.执行命令 npm install hexo-cli -g
安装 hexo:
1 2 3 4 5 6 $ npm install hexo-cli -g added 53 packages in 4s 14 packages are looking for funding run `npm fund` for details
4.初始化 hexo 站点目录:
1 2 3 4 $ hexo init blog INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git INFO Install dependencies INFO Start blogging with Hexo!
5.进入初始化目录:
6.执行命令,安装:
1 2 3 4 5 6 7 8 $ npm install added 1 package, and audited 227 packages in 538ms 23 packages are looking for funding run `npm fund` for details found 0 vulnerabilities
7.执行命令,安装 hexo-deployer-git
插件:
1 2 3 4 5 6 7 8 $ npm install hexo-deployer-git --save added 9 packages, and audited 236 packages in 1s 29 packages are looking for funding run `npm fund` for details found 0 vulnerabilities
hexo 配置 编辑 blog
目录下的 _config.yml
文件,找到最后的 # Deployment
属性配置,修改成如下:
1 2 3 4 deploy: type: git repository: https://github.com/leazhi/hexo.github.io branch: main
保存退出!
hexo 部署 执行下面的命令进行部署:
1 2 3 $ hexo clean $ hexo generate $ hexo deploy
注意:执行完部署命令后,不要立马去使用你的仓库名(hexo.github.io)访问你的 hexo 项目,此时是无法访问的。因为 github 需要时间进行处理响应!大概30s 到 1分钟去访问试试看。如果还不行,请根据上述步骤仔细排查!!
参考文献 关于如何自定义域名及配置 SSL 都可以参考下面的这篇文章
Hexo + Butterfly 建站指南(二)部署至个人站点或 GitHub Pages