在不同机器上配置部署hexo

将学习平台从Windows转移到ubuntu上后,需要重新配置hexo,但和重头配置有所区别。虽然,将Windows的磁盘擦干净前,我已经把数据全转移到移动硬盘上,可以用拷贝的方式在ubuntu上重新部署hexo, 但是这种方法相对手动,且既然用了github pages, 就通过实践github来部署。

查阅后得到两种比较通用的hexo发布github的方式,

  1. 重新create a repo, 将静态文件push上去。
  2. 利用git branch的特性,将静态和部署文件放在一个repo的两个branch中。
    这里我选择了后者。

检查git:

$ git --version

$ sudo apt-get install git-core

安装npm(node package manager):

$ npm --version

$ sudo apt-get install npm

安装node-legacy
装node-legacy原因

$ sudo apt-get install nodejs-legacy

安装nvm
nvm和npm一样是node的包的管理工具

$ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh

安装 Node.js

Node.js是一个能够在服务器端运行JavaScript的开放源代码、跨平台JavaScript运行环境。Node.js由Node.js基金会持有和维护,并与Linux基金会有合作关系。Node.js采用Google开发的V8运行代码,使用事件驱动、非阻塞和异步输入输出模型等技术来提高性能,可优化应用程序的传输量和规模。这些技术通常用于数据密集的事实应用程序。
visit node.js for more information

$ nvm install 4

安装 hexo

$ npm install hexo-cli -g

$ npm install hexo -g

配置git

查看:

$ ls -al ~/.ssh
ls: cannot access /home/tim/.ssh: No such file or directory

生成:

$ ssh-keygen -t rsa -b 4096 -C "timtingwei@hotmail.com"

确认:

$ ssh-agent -s

添加:

$ ssh-add ~/.ssh/id_rsa

在github中添加SHH KEY

$ clip < cat ~/.ssh/id_rsa.pub

并在github setting中添加shh key

$ ssh -T git@github.com
Hi timtingwei! You've successfully authenticated, but GitHub does not provide shell access.

利用git branch在不同机器上部署hexo
CrazyMilk的知乎回答

  1. 创建repo, timtingwei.github.io;
  2. 创建master和hexo两个分支,hexo用于存放静态文件, master用于部署;
  3. repo setting 中设置hexo为默认分支;
  4. git clone git@github.com:timtingwei/timtingwei.github.io.git 拷贝repo;
  5. npm install hexo、hexo init、npm install 和 npm install hexo-deployer-git –save(此时当前分支应显示为hexo);如果在不同机器上不需要hexo init;
  6. 修改_config.yml的deploy::branch参数为master;
  7. 依次执行 git add., git commit -m “…”, git push origin hexo 提交相关文件;
  8. 执行hexo g -d 生成并部署到github上
  9. 日常改动:依次7,8.

以上配置完成后, hexo s没反应

$ hexo server
INFO Start processing

hexo 3.0把服务器独立成个别模块,必须安装hexo-server才能使用。

$ npm install hexo-server --save

$ hexo server

安装后, 仍旧没有反应。

考虑用静态模式, 服务器只处理public文件夹内的文件,而不处理文件变动。先要执行hexo generate

$ hexo generate
$ hexo server -s
INFO Start processing
INFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.

refweb:
https://zh.wikipedia.org/wiki/Node.js
http://www.jianshu.com/p/24cb74aeb0a3
https://www.zhihu.com/question/21193762
https://hexo.io/zh-cn/docs/server.html
https://stackoverflow.com/questions/21168141/cannot-install-packages-using-node-package-manager-in-ubuntu