1.准备搭建环境
(1)安装适用于Windows系统的Git
https://git-scm.com/download/win
若无法下载,则下载并安装淘宝镜像版的Git
https://registry.npmmirror.com/binary.html?path=git-for-windows/
(2)安装适用于Windows系统的NodeJs环境(建议使用 Node.js 12.0 及以上版本)
https://nodejs.org/zh-cn/download
若无法下载,则下载并安装淘宝镜像版的NodeJs
https://registry.npmmirror.com/binary.html?path=node/
(3)安装适用于Windows系统的VSCode编译器
https://code.visualstudio.com/Download
注1:若安装淘宝镜像版nodejs,则输入命令时需用cnpm而非npm
注2:在Windows自带的PowerShell里输入node -v
和git version
查看NodeJs和Git是否安装成功
2.获取SSH公钥
(1)创建github账号
https://github.com/
(2)获取本地密钥
首先打开 Git Bash ,输入cd ~/.ssh
,再输入ls
,检查是否有 id_ 开头的名字,如果没有则可以创建SSH密钥
继续使用 Git Bash 输入ssh-keygen -t ed25519 -C "your_email@example.com"
一般不设置密码,就一直回车 (enter) 直到出现有图案出现
然后再次输入ls
,复制有以 id_ 开头 pub 结尾的名字,输入cat id_...pub
,将得到的SSH公钥内容复制下来
(3)将SSH公钥绑定gitHub
进入github个人页面,点击右上角的头像,在弹出界面找到设置一栏,点击设置再找到 SHH and GPG keys
点击 SHH and GPG keys ,将复制的SSH公钥内容填进下面方框中,再设置公钥名字并保存
注1:your_email@example.com替换为自己注册github账号所使用的邮箱
注2:id_…pub替换为自己复制的名字
3.安装Hexo
(1)安装 Hexo-CLI
打开 PowerShell 输入npm install -g hexo-cli
(2)绕过执行策略的限制
在 PowerShell 中输入powershell -ExecutionPolicy Bypass
(3)安装Hexo包并创建文件夹 package ( package 为文件夹名可修改)
在 PowerShell 中输入hexo init package
(4)进入文件夹 package
在 PowerShell* 中输入cd package
(5)再次安装一遍,确保所有的包都安装完成
在 PowerShell 中输入npm install
4.创建网站页面并运行服务器
(1)绕过执行策略的限制
在 PowerShell 中输入powershell -ExecutionPolicy Bypass
(2)生成静态网页文件
在 PowerShell 中输入hexo g
(3)运行本地服务器
在 PowerShell 中输入hexo s
在返回信息中我们可以得到 https://localhost:4000 这个端口,输入这个端口链接在浏览器中就能看到网页了
5.写作
(1)新建一篇文章 title ( title 为标题可修改)
在 PowerShell 中输入hexo new "title"
(2)再次生成静态网页文件
在 PowerShell 中输入hexo g
(3)再次运行本地服务器
在 PowerShell 中输入hexo s
6.部署网页在github上
(1)在github上创建新的仓库
点击github右上角的 加号(+) ,选择新建存储库,然后输入自己的项目名字,且在名字后面一定要加上
.github.io 后缀,还有README初始化也要勾上,最后点击创建即可
(2)获取SSH链接
点击刚刚创建的库上的 code ,选择 SSH ,复制 SSH 下面的内容
(3)安装插件在本地
在 PowerShell 中输入npm install hexo-deployer-git --save
(4)检查插件是否安装成功
在 PowerShell 中输入npm list hexo-deployer-git
(5)配置 _config.yml 文件
进入 package 文件夹,找到 _config.yml 件,选中它用VSCode打开,往下翻并找到
deploy: 和 type: ,在 type: 后面写上 git ,并换行写上 repo: ,再在 repo: 后面
粘贴上复制好的SSH链接并保存
(6)绕过执行策略的限制
在 PowerShell 中输入powershell -ExecutionPolicy Bypass
(7)将生成的网站部署到github仓库中
在 PowerShell 中输入hexo d
(8)改变部署仓库分支
打开 _config.yml 文件,在 repo: 下面写上 branch: ,在 branch: 后面写上想要的分支的名字并保存
(9)再次部署更新内容到github仓库中
在 PowerShell 中输入hexo d
(10)用github页面打开网站
在gitHub项目仓库页面的搜索栏下面有一个设置,点击设置并其在左下方找到 页面 一栏,点击页面就能看到
有 github.io 域名的链接,点击链接即可访问我们创建的网站
注:如果输入hexo d
遇到错误,则在输入其之前输入git config --global credential.helper wincred
参考资料:https://hexo.io/zh-cn/docs/
https://docs.github.com/zh/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent