文章目录
  1. 1. 在Windows下中WSL快速搭建hexo
    1. 1.1. 安装Git
    2. 1.2. 安装Node.Js
    3. 1.3. 安装hexo
    4. 1.4. githu生成公钥
    5. 1.5. 测试
  2. 2. 在WSL下快速搭建hexo
  3. 3. 一台PC配置配置多个git博客
  4. 4. 其它

福原爱

在Windows下中WSL快速搭建hexo

安装Git

登入Git官网下载即可
git官网

安装Node.Js

Node.js官网

安装hexo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$ npm install -g hexo
> dtrace-provider@0.6.0 install C:\Users\takethat\AppData\Roaming\npm\node_modules\hexo\node_modules\hexo-log\node_modules\bunyan\node_modules\dtrace-provider
> node scripts/install.js
> hexo-util@0.6.0 postinstall C:\Users\takethat\AppData\Roaming\npm\node_modules\hexo\node_modules\hexo-util
> npm run build:highlight
> hexo-util@0.6.0 build:highlight C:\Users\takethat\AppData\Roaming\npm\node_modules\hexo\node_modules\hexo-util
> node scripts/build_highlight_alias.js > highlight_alias.json
npm WARN optional dep failed, continuing fsevents@1.0.12
npm WARN optional dep failed, continuing fsevents@1.0.12
C:\Users\takethat\AppData\Roaming\npm\hexo -> C:\Users\takethat\AppData\Roaming\npm\node_modules\hexo\bin\hexo
hexo@3.2.2 C:\Users\takethat\AppData\Roaming\npm\node_modules\hexo
├── abbrev@1.0.9
├── pretty-hrtime@1.0.2
├── hexo-front-matter@0.2.3
├── archy@1.0.0
├── titlecase@1.1.2
├── text-table@0.2.0
├── tildify@1.2.0 (os-homedir@1.0.1)
├── moment-timezone@0.5.4
├── hexo-i18n@0.2.1 (sprintf-js@1.0.3)
├── bluebird@3.4.1
├── strip-indent@1.0.1 (get-stdin@4.0.1)
├── chalk@1.1.3 (supports-color@2.0.0, escape-string-regexp@1.0.5, ansi-styles@2.2.1, has-ansi@2.0.0, strip-ansi@3.0.1)
├── swig-extras@0.0.1 (markdown@0.5.0)
├── minimatch@3.0.2 (brace-expansion@1.1.5)
├── hexo-cli@1.0.2 (object-assign@4.1.0, minimist@1.2.0)
├── js-yaml@3.6.1 (esprima@2.7.2, argparse@1.0.7)
├── moment@2.13.0
├── lodash@4.13.1
├── swig@1.4.2 (optimist@0.6.1, uglify-js@2.4.24)
├── hexo-log@0.1.2 (bunyan@1.8.1)
├── hexo-util@0.6.0 (striptags@2.1.1, html-entities@1.2.0, highlight.js@9.5.0, camel-case@3.0.0, cross-spawn@4.0.0)
├── cheerio@0.20.0 (entities@1.1.1, dom-serializer@0.1.0, css-select@1.2.0, htmlparser2@3.8.3, jsdom@7.2.2)
├── warehouse@2.2.0 (graceful-fs@4.1.4, is-plain-object@2.0.1, JSONStream@1.1.3, cuid@1.3.8)
├── hexo-fs@0.1.6 (escape-string-regexp@1.0.5, graceful-fs@4.1.4, chokidar@1.6.0)
└── nunjucks@2.4.2 (asap@2.0.4, yargs@3.32.0, chokidar@1.6.0)

安装必要的插件:

1
$ npm install hexo-deployer-git --save

其他操作

更换bash的HOME路径,以及登入跳转路径

修改D:\Program\Git\etc\profile

1
2
3
4
5
6
# normalize HOME to unix path
HOME="D:/github/home"
HOME="$(cd "$HOME" ; pwd)"

export PATH="$HOME/bin:$PATH"
cd D:/github/hexo-blog

githu生成公钥

1
$ ssh-keygen

在网页上添加公钥

1
$ ssh -T git@git.coding.net

测试

1
$ ssh -T git@github.com

调试github:

1
$ ssh -T -v git@github.com

调试:git.coding.net

1
$ ssh -vT git@git.coding.net

**注意如果公钥存储位置不是默认位置**则SSH配置也应该更改

修改D:\Program\Git\etc\ssh\ssh_config

1
2
3
4
5
#   StrictHostKeyChecking ask
IdentityFile D:/github/home/.ssh/identity
IdentityFile D:/github/home/.ssh/id_rsa
IdentityFile D:/github/home/.ssh/id_dsa
# Port 22

在WSL下快速搭建hexo

1.

官网下载对应的node版本Linux Binaries (x86/x64)并拷贝到wsl环境中
解压到当前文件夹

1
# root@t470p:/usr/local/src# tar xvf node-v8.11.2-linux-x64.tar.xz
  1. 建立软连接,变为全局
1
# ln -s /usr/local/src/node-v8.11.2-linux-x64/bin/npm /usr/local/bin/ 
1
# ln -s /usr/local/src/node-v8.11.2-linux-x64/bin/node /usr/local/bin/  
  • 检查下是否连接成功

    1
    2
    3
    关掉终端再登入
    root@t470p:/home# node -v
    v8.9.4
  • 换淘宝源(永久),并查看是否更换成功

    1
    2
    3
    root@t470p:/home# npm config set registry https://registry.npm.taobao.org
    root@t470p:/home# npm config get registry
    https://registry.npm.taobao.org/
  1. 安装hexo
    1
    # sudo npm install -g hexo

    注意这里必须加sudo不然会报错

  • 同样的给hexo加上软连接

    1
    root@t470p:/home/takethat/node-v8.9.4-linux-x64/lib/node_modules/hexo/bin# ln -s /home/takethat/node-v8.9.4-linux-x64/lib/node_modules/hexo/bin/hexo /usr/local/bin/

    注意添加全局软连接一定要打完整绝对路径

  • 安装必要的插件:

    1
    $ sudo npm install hexo-deployer-git --save

    这个可以不安装,因为安装会报错

配置github仓库地址:

1
2
3
4
5
6
deploy:
type: git
repo: https://github.com/vivatakethat/vivatakethat.github.io.git
branch: master
# coding:
# git@id_rsa.git.coding.net:vivatakethat/vivatakethat.git,coding-pages

这种配置需要输入帐号和密码

免帐号/密码登入:

1
2
3
4
deploy:
type: git
repo: git@github.com:vivatakethat/vivatakethat.github.io.git
branch: master

一台PC配置配置多个git博客

  1. 生成另一个博客账户的公钥
    1
    $ ssh-keygen -t rsa -C "your-email-address"

    存储key的时候,不要覆盖现有的id_rsa,使用一个新的名字,比如id_rsa_lifespring

如下:

1
2
3
takethat@acer_v5573g MINGW32 /c/Users/takethat/.ssh
$ ls
config id_rsa id_rsa.pub id_rsa_lifespring id_rsa_lifespring.pub known_hosts

并在对应的git账户添加SSH公钥

  1. 把该key加到ssh agent上。由于不是使用默认的.ssh/id_rsa,所以你需要显示告诉ssh agent你的新key的位置

    1
    $ ssh-add ~/.ssh/id_rsa_lifespring
  2. 配置.ssh/config设置host别名

    1
    $ vi .ssh/config
  • 加上以下内容
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Host id_rsa.git.coding.net
    HostName git.coding.net
    User vivatakethat
    IdentityFile /C/Users/takethat/.ssh/id_rsa

    Host id_rsa_lifespring.git.coding.net
    HostName git.coding.net
    User lifespring
    IdentityFile /C/Users/takethat/.ssh/id_rsa_lifespring
  1. 修改hexo的_config.yml
    1
    2
    3
    4
    5
    6
    deploy:
    type: git
    repo:
    coding:
    git@id_rsa.git.coding.net:vivatakethat/vivatakethat.git,coding-pages
    message: Takethat的自留地Updated:{{ now("YYYY-MM-DD HH:mm:ss") }}
    和另外一个博客
    1
    2
    3
    4
    5
    6
    deploy:
    type: git
    repo:
    # github: git@github.com:vivatakethat/vivatakethat.github.io.git,master
    coding: git@id_rsa_lifespring.git.coding.net:lifespring/lifespring.git,coding-pages
    message: Takethat的自留地Updated:{{ now("YYYY-MM-DD HH:mm:ss") }}

即可

其它

hexo博文分类数和标签数显示不正确?

  • 先移除博客根目录下的.deploy_git文件夹和 db.json文件,然后清理下 public 目录下的categories 和 tags 两个文件夹里的文件,然后重新部署静态博客:

hexo clean #清除缓存
hexo g #生成静态网页
hexo s #启动服务预览
hexo d #开始部署

可能会有些文件无法删除提示,文件不存在
请在任意目录新建一个de.bat文件其内容为

1
2
DEL /F /A /Q \\?\%1
RD /S /Q \\?\%1

将想要删除的文件拖进这个.bat文件即可删除

可能会报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
fatal: Not a git repository (or any of the parent directories): .git
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/do cs/troubleshooting.html
Error: fatal: Not a git repository (or any of the parent directories): .git

at ChildProcess.<anonymous> (D:\github\hexo-blog\node_modules\hexo-deployer- git\node_modules\hexo-util\lib\spawn.js:37:17)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at ChildProcess.cp.emit (D:\github\hexo-blog\node_modules\cross-spawn-async\ lib\enoent.js:37:29)
at maybeClose (internal/child_process.js:827:16)
at Socket.<anonymous> (internal/child_process.js:319:11)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at Pipe._onclose (net.js:486:12)
FATAL fatal: Not a git repository (or any of the parent directories): .git

Error: fatal: Not a git repository (or any of the parent directories): .git

重新装一下插件

1
$ npm install hexo-deployer-git --save
  • 报错 but GitHub does not provide shell access.
    1
    2
    root@acer:/mnt/t5/github/hexo-blog# ssh -T git@github.com
    Hi vivatakethat! You've successfully authenticated, but GitHub does not provide shell access.

解决方法:
设置Git的user name和email

git config –global user.name “yourname”
git config –global user.email “youremail”
生成SSH密钥

查看是否已经有了ssh密钥:cd ~/.ssh
如果没有密钥则不会有此文件夹,有则备份删除
生存密钥:
ssh-keygen -t rsa -C “haiyan.xu.vip@gmail.com
按3个回车,密码为空。
Your identification has been saved in /home/tekkub/.ssh/id_rsa.
Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
The key fingerprint is:
………………
最后得到了两个文件:id_rsa和id_rsa.pub

可参考文章

文章目录
  1. 1. 在Windows下中WSL快速搭建hexo
    1. 1.1. 安装Git
    2. 1.2. 安装Node.Js
    3. 1.3. 安装hexo
    4. 1.4. githu生成公钥
    5. 1.5. 测试
  2. 2. 在WSL下快速搭建hexo
  3. 3. 一台PC配置配置多个git博客
  4. 4. 其它