建置Hexo

初始設定

Hexo的官方網站,根據官方網站可以有基本的設定,但官方的介面不太好看,所以接下來要使用別人寫好的Theme。

使用的是NexT,該主題很貼心的提供了很多相關的設定說明,比如:增加Tag增加DISQUS增加MathJax

NexT

這邊需要注意的是,因為之後要用到travis自動化deploy。NexT為獨立的git repo,若無特殊設定,並不會將其檔案下載下來,導致travis的自動化部署失敗(找不到theme檔案)。有兩種方法:

1.

1
2
rm themes/next/.gitignore
rm -r themes/next/.git

將NexT的git刪除,使其全部使用同一個git repo

2.
先fork NexT,並在此repo客製化後,將此repo視為submodule(請使用https的連結,避免權限問題):

1
git submodule add https://your/custom/repo

之後於travis指令執行

1
2
git submodule init
git submodule update

即可以載入主題檔案。

MathJax使用方法

1
2
3
$$ Block $$
\\(inline\\)

DISQUS

增加DISQUS時若要在local預覽,到_config.yml將url更改成localhost:4000(參考)。

可以看這個網址
且可以直接使用hexo-generator-search

NexT文字大小

大致上設定完成之後,另外更改NexT的文字大小。在:

1
themes/next/source/css/_variable/custom.styl

可以修改相關的設定:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 正文字體大小
$font-size-base = 18px
$font-size-headings-base = 28px
$table-font-size = 18px
// 代碼字體大小
$code-font-size = 17px
$btn-default-font-size = 18px
$logo-font-size = 24px
$subtitle-font-size = 17px
$read-more-font-size = 18px
$site-description-font-size = 18px

匯入Blogger的文章

只能用RSS

1
npm install hexo-migrator-rss --save

匯入

1
hexo migrate rss "http://annotationandnote.blogspot.com/feeds/posts/default?alt=rss&max-results=1000000"

遇到個問題

1
unknown block tag: load

是文章中有個

1
{% load %}

這種東西,將其包在code block即可。

部署到Github

我使用的方式是用repo的gh-pages。

1
npm install hexo-deployer-git --save

_config.yml:

1
2
3
4
deploy:
type: git
repo: git@github.com:xxx/xxx.git
branch: gh-pages

1
2
url: https://xxx.github.io/xxx/
root: /xxx/

command:

1
2
hexo g
hexo deploy

使用Travis自動部署

參考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
language: node_js
node_js:
- node
before_install:
# Decrypt the private key
- openssl aes-256-cbc -K $xxx_key -iv $xxx_iv
-in .travis/xxx.enc -out ~/.ssh/id_rsa
-d
# Set the permission of the key
- chmod 600 ~/.ssh/id_rsa
# Start SSH agent
- eval $(ssh-agent)
# Add the private key to the system
- ssh-add ~/.ssh/id_rsa
# Copy SSH config
- cp .travis/ssh_config ~/.ssh/config
# Set Git config
- git config --global user.name "jackklpan"
- git config --global user.email jackklpan@gmail.com
# Install Hexo
- npm install hexo -g
# Clone the repository, 產生的檔案會放置於.deploy_git,將其clone下來使commit一致,避免git force update
- git clone --branch gh-pages https://github.com/jackklpan/hexo-blog.git .deploy_git
script:
- git submodule init # 用于更新主题,需要指定到自己的repo,否则会clone最新NexT主题,客製化的部分會消失
- git submodule update
- hexo generate
- hexo deploy
branches:
only:
- master