Dockerコンテナ上でHexoを導入してGithubPagesにデプロイする〜③デプロイ編〜

目次

  1. Gitの設定
  2. _config.ymlの設定

こんにちは。karintomania(twitter)です。
めんどくさそうなデプロイですが、
Hexoならコマンド一発で楽勝です。

Gitの設定

デプロイにはGitを使うので、
設定を済ませてしまいましょう。
以下のコマンドでユーザ設定をします。

1
2
/app/test # git config --global user.name "Your Name"
/app/test # git config --global user.email "you@example.com"

_config.ymlの設定

_config.ymlの設定をします。
その前に、対象リポジトリのURLを調べておきましょう。
GithubでWebサイト用に作成したリポジトリの Clone or Downloadボタンをクリックすると、
コミット用URLが表示されます。
コミット用URL

URLを取得したら_config.ymlを以下のように編集します。

_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: https://{githubのusername}.github.io/{リポジトリ名}/
root: /{リポジトリ名}/
permalink: :year/:month/:day/:title/
permalink_defaults:
pretty_urls:
trailing_index: true # Set to false to remove trailing index.html from permalinks


# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: {先ほど取得したURLをここに貼り付ける}
branch: gh-pages

設定ができたら以下のコマンドでデプロイします。

1
/app/test # hexo deploy

デプロイできたらGithubPagesへアクセスして確認してみましょう。
https://{githubのusername}.github.io/{リポジトリ名}/

できたでしょうか。
これでサイトができました!!おめでとうございます。

ちなみにこのやり方だと、gh-pagesブランチに公開用ソースを格納して、
Masterブランチは使用しません。
なので、Masterブランチに下書きも含めたフォルダ全体を管理するリポジトリにしてしまうのがいいのかなと思います。