一开始只准备在Github上建站,后来发现墙壁实在是太厚,偶然发现可以将hexo同时部署到Github和GitCafe,于是开始搞事儿。刚注册完GitCafe就发现它居然已经被Coding包养了,无奈又去注册了Coding。开始部署发现hexo已经升级到了3.0,找到的教程普遍都是2.0的,有些细节不太实用,再加上bash实在是不熟,搞了有点时间,所以决定部署完成第一篇就记录一下部署过程。

部署环境

操作系统OS X EL Capitan 10.11.4
Node.jsnode-v4.4.2.pkg
Homebrew: 安装git用的,这里就不介绍了
git: 安装hexo会用到,也不介绍了

安装Node

我下载的是node-v4.4.2.pkg安装包直接安装即可。
安装完成后进入终端输入

1
$ npm

提示以下内容就是OK了。

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
Usage: npm <command>

where <command> is one of:
access, add-user, adduser, apihelp, author, bin, bugs, c,
cache, completion, config, ddp, dedupe, deprecate, dist-tag,
dist-tags, docs, edit, explore, faq, find, find-dupes, get,
help, help-search, home, i, info, init, install, issues, la,
link, list, ll, ln, login, logout, ls, outdated, owner,
pack, ping, prefix, prune, publish, r, rb, rebuild, remove,
repo, restart, rm, root, run-script, s, se, search, set,
show, shrinkwrap, star, stars, start, stop, t, tag, team,
test, tst, un, uninstall, unlink, unpublish, unstar, up,
update, upgrade, v, version, view, whoami

npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm faq commonly asked questions
npm help <term> search for help on <term>
npm help npm involved overview

Specify configs in the ini-formatted file:
/Users/Ethan/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@2.15.0 /usr/local/lib/node_modules/npm

安装hexo

根据hexo官方文档直接终端输入以下命令即可

1
2
3
4
5
$ npm install -g hexo-cli
$ hexo init blog
$ cd blog
$ npm install
$ hexo server

打开本地服务器预览(点击访问 http://localhost:4000 ,就可以看到了你的blog了)
之后你可以将blog文件夹放到任何你想放的地方,如果之后部署有问题请使用超级权限sudo

配置hexo

安装rss支持

执行如下命令:

1
npm install hexo-generator-feed --save

安装sitemap支持

执行如下命令:

1
npm install hexo-generator-sitemap --save

安装其他插件

1
2
3
4
5
npm install hexo-generator-index --save
npm install hexo-generator-archive --save
npm install hexo-generator-category --save
npm install hexo-generator-tag --save
npm install hexo-deployer-git --save

注册Github和Coding

在自己Github创建一个新的repository。比如我的Github账号是ethanjuenchu,那么我应该创建的repository名字应该是ethanjunechu.github.io
Coding与Github类似就不啰嗦了。

修改_config.yml文件

_config.yml位于blog文件夹的根目录,里面是你blog的一些基本配置,我的配置修改如下:

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Hexo Configuration
# # Docs: http://hexo.io/docs/configuration.html
# # Source: https://github.com/hexojs/hexo/

# Site
title: ESERIES
subtitle:
description: 不精独乐
author: Ethan
language: zh-CN
timezone:

# URL
# # If your site is put in a subdirectory
# # set url as 'http://yoursite.com/child' and root as '/child/'
url: http://ethanjunechu.coding.me
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
enable: true
line_number: true
auto_detect: true
tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Date / Time format
# # Hexo uses Moment.js to parse and display date
# # You can customize the date format as defined in
# # http://momentjs.com/docs/# /displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
# # Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page


# Extensions
# # Plugins: http://hexo.io/plugins/

index_generator:
per_page: 10 ## 首页默认10篇文章标题 如果值为0不分页

archive_generator:
per_page: 10 ## 归档页面默认10篇文章标题
yearly: true ## 生成年视图
monthly: true ## 生成月视图

tag_generator:
per_page: 10 ## 标签分类页面默认10篇文章

category_generator:
per_page: 10 ### 分类页面默认10篇文章

sitemap:
path: sitemap.xml

feed:
type: atom
path: atom.xml
limit: 20

duoshuo_shortname: ## 这里填写你的多说的短网址
# # Themes: http://hexo.io/themes/
theme: apollo ## 主题的名称,我用的是apollo,默认的是landscape

# Deployment
# # Docs: http://hexo.io/docs/deployment.html
deploy:
type: git
repo:
github: https://github.com/ethanjunechu/ethanjunechu.github.io.git
coding: https://git.coding.net/ethanjunechu/ethanjunechu.git
branch: master

这里面基本都有注解,说一下最后的deploy(部署)分别为你的Github和Coding的发布链接,与上一步你注册的账号的repository相对应。

部署

这是最后一步,进入你的终端,进入你的blog文件夹

1
$ hexo d -g

之后会分别叫你输入Github和Coding的密码。

其他问题

发布失败有可能是隐藏文件引起的,需要删除OS X下面的隐藏文件.DS_tore。
主题文件就放进themes文件夹,在_config.yml里面启用就行了。
发布成功,web显示extends partial/layout block container include mixins/post +posts() block pagination include mixins/paginator +home() block copyright include partial/copyright
执行下面的命令后再重新发布

1
npm install --save hexo-renderer-jade hexo-generator-feed hexo-generator-sitemap hexo-browsersync hexo-generator-archive