利用 Hexo + Github Pages 搭建免费博客 - 上传云端(二)

在上一篇教程,我们已经成功把网站运行起来了。那么,怎样才能把网站上传到云端?
(建议:最好两个都注册,后面我会说明为什么)
Github 主页

Github 教程

注册账号

打开 Github 官网 ,在主页就有注册的地方
依次输入用户名,邮箱,密码,点击Sign up for Github
Github 主页

选择免费方案,点击Continue
注册页面 1

除非你以后想当程序员,否则就直接点skip this step
注册页面 2

打开你的邮箱,点击Verify email address验证邮箱
邮箱页面

创建仓库

Q:什么是仓库
A:简单来说,就是一个用来储存代码的网盘,不过比网盘要高级

进入 Github 首页 ,点击右边的New repositoriy
Github 首页

Repository name一栏填你的用户名.github.io,否则后面就无法上传
点击Create repository
(由于我已经创建过同名的,所以按钮是灰色的)
仓库创建页面

配置 SSH Key

打开 Git,输入

1
2
git config --global user.email "注册时的邮箱"
git config --global user.name "注册时的用户名"

Git

输入下面的命令生成 Key

1
ssh-keygen -t rsa -C "注册时的邮箱"

Git 会提示你输入一个目录来存放 Key 文件,直接回车表示括号里的路径
Git

输入一个密码,也可以不设密码,直接回车
Git

再输一遍密码,之前没有就回车
Git

进入存放 Key 文件的目录,打开id_rsa.pub文件(用文本编辑器,也可以用记事本),复制里面的内容
id_rsa.pub 文件

进入 Github 的 SSH Keys 设置页面,点击New SSH key
SSH Keys 设置页面

Title里随便输一个标题,Key里粘贴你刚刚复制的 Key,然后点击Add SSH Key
SSH Keys 设置页面

然后它会让你输入密码,输入后直接回车
输入密码

配置本地 Git

进入你的仓库,点击SSH按钮,复制
SSH 地址

打开站点配置文件,找到Deployment一栏,按照下面修改

1
2
3
4
deploy:
type: git
repo: git@github.com:用户名/刚刚复制的地址
branch: master

例如,我的是:

1
2
3
4
deploy:
type: git
repo: git@github.com:XcantloadX/xcantloadx.top.git
branch: master

在博客根目录打开 Git,输入命令

1
hexo deploy //可简写为 hexo d

如果出现ERROR Deployer not found: git,运行

1
npm install hexo-deployer-git --save

第一次上传会出现提示,输入yes回车即可
提示

如果没有出现像下面一样的提示,就说明上传成功,你可以去你的用户名.github.io看看效果

1
2
3
4
5
6
7
Please make sure you have the correct access rights and the repository exists.
at ChildProcess.<anonymous> (C:\Users\Administrator\Desktop\1\Desktop\XcantloadX - 副本\node_modules\hexo-util\lib\spawn.js:37:17)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at ChildProcess.cp.emit (C:\Users\Administrator\Desktop\1\Desktop\XcantloadX - 副本\node_modules\cross-spawn\lib\enoent.js:40:29)
at maybeClose (internal/child_process.js:925:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

Coding

访问 Coding 官网,由于 Coding 是中文的,注册账号的过程我就不截图了

注册好后,访问 https://coding.net/user,点击右上角的`+`,选择项目
新建项目菜单

项目名称、公不公开随意,填写完后点击创建项目
填写信息

按照图中顺序添加 Key (仍然是上次生成的)
添加 Key

输入密码并确认
输入密码

打开你新建的项目,复制 SSH 地址
复制地址

打开站点配置文件,找到Deployment一栏,按照下面修改

1
2
3
4
5
6
deploy:
type: git
repo:
github: git@github.com:XcantloadX/xcantloadx.top.git
coding: 刚刚复制的地址
branch: master

Notepad++

hexo d即可,若无错误提示,表明配置成功,可以去https://用户名.coding.me/项目名查看效果