在Windows下快速搭建hexo
总阅读次
在Windows下中WSL快速搭建hexo
安装Git
登入Git官网下载即可
git官网
安装Node.Js
安装hexo
1 | $ npm install -g hexo |
安装必要的插件:
1 | $ npm install hexo-deployer-git --save |
其他操作
更换bash的HOME路径,以及登入跳转路径
修改D:\Program\Git\etc\profile
1 | # normalize HOME to unix path |
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 | # StrictHostKeyChecking ask |
在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 | # 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
3root@t470p:/home# npm config set registry https://registry.npm.taobao.org
root@t470p:/home# npm config get registry
https://registry.npm.taobao.org/
- 安装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 | deploy: |
这种配置需要输入帐号和密码
免帐号/密码登入:
1 | deploy: |
一台PC配置配置多个git博客
- 生成另一个博客账户的公钥
1
$ ssh-keygen -t rsa -C "your-email-address"
存储key的时候,不要覆盖现有的id_rsa,使用一个新的名字,比如id_rsa_lifespring
如下:
1 | takethat@acer_v5573g MINGW32 /c/Users/takethat/.ssh |
并在对应的git账户添加SSH公钥
把该key加到ssh agent上。由于不是使用默认的.ssh/id_rsa,所以你需要显示告诉ssh agent你的新key的位置
1
$ ssh-add ~/.ssh/id_rsa_lifespring
配置.ssh/config设置host别名
1
vi .ssh/config
- 加上以下内容
1
2
3
4
5
6
7
8
9Host 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
- 修改hexo的_config.yml和另外一个博客
1
2
3
4
5
6deploy:
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
6deploy:
type: git
repo:
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 | DEL /F /A /Q \\?\%1 |
将想要删除的文件拖进这个.bat文件即可删除
可能会报错
1 | 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
2root@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