cherish's blog
隻言片語・於此匯聚!
Hexo Deployed To Github

购得owye.cc域名一个。
又没有现成的服务器(主要是穷),为了能让新买的域名派上用场。准备在github上搭建一个静态博客,然后将域名用上。

那就愉快的开始吧!

安装环境

1.Windows10

所需软件
1.有一个github账户
2.系统中安装git 官网地址:https://git-scm.com/downloads
3.系统中安装node.js 官网地址:https://nodejs.org/en/

如何安装这里就不再赘述,安装完成以后再控制台分别git --versionnode -v两条命令即可看到是否安装成功。

C:\Users\Admin>git --version
git version 2.28.0.windows.1

C:\Users\Admin>node -v
v12.18.3

C:\Users\Admin>

安装 Hexo

所有必备的应用程序安装完成后,即可使用 npm 安装 Hexo。如下:

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop
$ npm install -g hexo-cli

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop
$ npm install -g hexo-cli
C:\Users\Admin\AppData\Roaming\npm\hexo -> C:\Users\Admin\AppData\Roaming\npm\node_modules\hexo-cli\bin\hexo
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules\hexo-cli\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ hexo-cli@4.2.0
added 61 packages from 315 contributors in 44.422s

如上图表示已经成功安装Hexo

创建blog文件夹

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop
$ mkdir blog

进入blog文件夹

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop
$ cd blog
Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop/blog
$

初始化blog文件夹

$ hexo init

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop/blog
$ hexo init

INFO  Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
INFO  Install dependencies
added 183 packages from 420 contributors and audited 189 packages in 28.498s

8 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

INFO  Start blogging with Hexo!

安装依赖

$ hexo install

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop/blog
$ hexo install
INFO  Validating config
Usage: hexo <command>

Commands:
  clean     Remove generated files and cache.
  config    Get or set configurations.
  deploy    Deploy your website.
  generate  Generate static files.
  help      Get help on a command.
  init      Create a new Hexo folder.
  list      List the information of the site
  migrate   Migrate your site from other system to Hexo.
  new       Create a new post.
  publish   Moves a draft post from _drafts to _posts folder.
  render    Render files with renderer plugins.
  server    Start the server.
  version   Display version information.

Global Options:
  --config  Specify config file instead of using _config.yml
  --cwd     Specify the CWD
  --debug   Display all verbose messages in the terminal
  --draft   Display draft posts
  --safe    Disable all plugins and scripts
  --silent  Hide output on console

For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/

安装插件

$ npm install hexo-deployer-git --save

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop/blog
$ npm install hexo-deployer-git --save
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ hexo-deployer-git@2.1.0
added 34 packages from 337 contributors and audited 218 packages in 24.583s

在github中新建一个仓库,格式为yourname.github.io

注意:yourname 要和Github的名字一致,不然创建好仓库后仓库Settings中没有Github Pages。(下图由于手误创建项目时写成了blog.github.io,正确的写法是codesbull.github.io)

复制仓库地址,如下图:

用编辑器将blog文件夹中的_config.yml配置文件打开添加以下红色方框中的信息(链接改成刚才自己复制的链接),保存即可。
如下图:

部署hexo到github中

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop/blog
$ hexo g -d

可能会遇到以下错误:

/

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'Admin@DESKTOP-CEI4IR8.(none)')
FATAL {
  err: Error: Spawn failed
      at ChildProcess.<anonymous> (C:\Users\Admin\Desktop\blog\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:51:21)
      at ChildProcess.emit (events.js:315:20)
      at ChildProcess.cp.emit (C:\Users\Admin\Desktop\blog\node_modules\cross-spawn\lib\enoent.js:34:29)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) {
    code: 128
  }
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html

只需要运行以下两条命令即可(邮箱和名字改成自己github的即可)

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

如下面是我自己的两条命令:

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop/blog
$ git config --global user.email "cndevs@gmail.com"

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop/blog
$ git config --global user.name "codesbull"

再次部署hexo到github

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop/blog
$ hexo g -d

此时可能会出现以下github登录界面,输入自己的github账户和密码即可。如下图:

最后的结果如下:

Enumerating objects: 43, done.
Counting objects: 100% (43/43), done.
Delta compression using up to 8 threads
Compressing objects: 100% (35/35), done.
Writing objects: 100% (43/43), 507.47 KiB | 12.08 MiB/s, done.
Total 43 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3), done.
To https://github.com/codesbull/blog.github.io.git
 + 00f5d4a...fa2bd2c HEAD -> master (forced update)
Branch 'master' set up to track remote branch 'master' from 'https://github.com/codesbull/blog.github.io.git'.
INFO  Deploy done: git

Admin@DESKTOP-CEI4IR8 MINGW64 ~/Desktop/blog
$

至此,Hexo部署到github就完成了。

虽然部署成功,但是貌似现在国内屏蔽了Github Pages。真是...

域名没用上...

后续使用gitee来搭建Hexo...,希望能用上owye.cc这个新域名吧!