hexoとgithubページでブログを構築したので,手順をメモ。
githubページに公開するときに少し迷ったので,その点を重点的に。

目次

  1. 環境
  2. Hexoをインストール
  3. blogの作成
  4. github に Github Pagesのリポジトリを作成
  5. SSH公開鍵の登録
  6. フォルダをgithub上のリポジトリに紐付け
  7. ファイルをアップロード
  8. Hexo コマンド

環境

  • Windows8.1
  • node.js v0.10.33
  • npm v1.4.28.
  • hexo v2.8.3

Windows8.1にnode.jsをインストールして環境を構築。
その後hexoをコマンドプロプントでインストール。

Hexoをインストール

コマンドプロプントもしくはGitBashで,下記コマンドを実行

1
$ npm install -g hexo

これで,hexoの環境ができあがる。

1
$ hexo -v

で,バージョンが表示されれば成功

blogの作成

コンソールでblogを作りたいフォルダに移動して,以下のコマンドを実行

1
$ hexo init BLOGNAME

これで,BLOGNAMEというフォルダができるので移動

1
2
$ cd BLOGNAME
$ npm install

これでブログが作成されたので,ローカルサーバーを立ち上げ確認

1
$ hexo server

で立ち上げ,http://localhost:4000で確認

github に Github Pagesのリポジトリを作成

new repositoryから,Repository nameを「username.github.io」にして作成。
usernameを一致させないと,失敗するっぽい。

SSH公開鍵の登録

SSHキーを作成して,ローカルとgithubアカウントを紐付ける。
コンソールで作っていくが,GitBashで作った方がうまくいくみたい。
コマンドは以下の通り

1
2
3
4
5
$ cd ~/.ssh
$ ssh-keygen
ssh-kygen
Generating public/private rsa key pair.
(以下略)

途中でパスワードを設定するか聞かれるが,特に設定したくない場合は空白のままenter。

.sshフォルダにid_rsaとid_rsa.pubというファイルがあれば成功。
id_rsa.pubが公開鍵になるので,メモ帳などで開いて内容をコピー。
Account settings > SSH keys > Add SSH key で先程コピーした内容を貼付け。
登録成功の画面が現われたら登録完了

フォルダをgithub上のリポジトリに紐付け

ローカルのblogフォルダとGithbuPagesリポジトリと紐付けるため以下のコマンドを実行

1
2
3
4
$ touch README.md
$ echo "hello github.io!!" > index.html
$ git init
$ git remote add origin git@github.com:/username.github.io.git

ファイルをアップロード

下記のコマンドを実行して,ファイルをアップロード

1
2
3
$ git add .
$ git commit -m "first commit"
$ git push origin master

成功すれば,http://username.github.ioに公開されているはず。

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
Commands:
clean Removed generated files and cache.
config Get or set configurations.
deploy Deploy your website.
generate Generate static files.
help Get help on a command.
init Create a new Hexo folder.
list List the information of the site
migrate Migrate your site from other system to Hexo.
new Create a new post.
publish Moves a draft post from _drafts to _posts folder.
render Render files with renderer plugins.
server Start the server.
version Display version information.

Global Options:
--config Specify config file instead of using _config.yml
--cwd Specify the CWD
--debug Display all verbose messages in the terminal
--draft Display draft posts
--safe Disable all plugins and scripts
--silent Hide output on console

For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/