For A Breath I Tarry

I am better than me

Hexo+Git安装配置(Mac)

前提条件

安装Homebrew

1.ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"有时候网络不太好,要多试几次。
2.添加环境变量 echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
3.查看安装情况 brew doctor

安装Xcode(非必须)

官方文档说可能会碰到一些编译问题,最好装一个。到App Store下载安装,有点大有点慢。

安装Nodejs

brew install node

Git

安装Git

brew install git

配置Git

1.申请github账号
2.建立github仓库,比如username.github.io这种
3.ssh key配置,非必须
a.检查ssh key是否存在 cd ~/.ssh
b.没有的话生成 ssh-keygen -t rsa -C "xxx@xxx.com"
c.在github页面添加ssh key,Account Settings->SSH Public Keys->Add another key,保存
d.测试连接 ssh -T git@github.com
4.个人信息设置 git config --global user.name "username"
git config --global user.email "xxx@xxx.com"

Hexo

安装Hexo

npm install -g hexo-cli

配置Hexo

blog是文件夹的名字,可以改别的。
hexo init blog
cd blog
npm install
整个网站的配置在_config.yml里面。
配置说明

基本用法

hexo new "new-post"
hexo generate
hexo server
可以访问http://localhost:4000/查看页面了。Ctrl+C停止。
运行hexo clean清理缓存文件。
配置了git之后用hexo deploy推送到github上。
其他命令

Hexo推送到Git

安装工具 npm install hexo-deployer-git --save
在_config.yml中修改

deploy:
type: git
repo: https://github.com/username/username.github.io.git
branch: master

Hexo配置多说

Hexo默认的评论用的disqus,国内就别想了,用多说代替。
1.在_config.yml中添加多说的配置:
duoshuo_shortname: 你站点的short_name
http://duoshuo.com 点击我要安装,注册多说二级域名。去掉 .duoshuo.com剩下的部分就是short_name。

2.如果用的默认的landscape模板,按教程修改themes\landscape\layout_partial\article.ejs。其他的模板,有的在类似的位置,有的有单独的comment.ejs文件。
Hexo使用多说教程

3.视模板不同,除了教程中的代码外,有的还需要修改链接到评论的地方

添加自定义页面

hexo new page "about"
到source/about/index.md编辑此页面的内容。
在themes/当前主题/_config.yml中,添加

menu:
Home: /
Archives: archives/
About: about/