R.A. Epigonos et al.

[git] gitを使ってコンテンツ管理する(CMS)

gitをバックエンドとしたCMSが欲しかったのだけど、githubのUser Page機能を使えば静的なページのコンテンツ管理が出来る。gitを使っているのでもちろん編集内容を後からチェックできる。

まずはgithubからレポジトリを作る。ただし、User Page機能を使うにはレポジトリのProject Nameが決まっていて、ユーザネームがaliceならalice.github.comというレポジトリを作らなければいけない。これだけでhttp://alice.github.com/にアクセスできるようになる。

あとは通常のレポジトリと同様にファイルを作ったりコンテンツを置いけばよい。レポジトリにファイルが何もない状態で有効になったサブドメインにアクセスすると以下の様に表示される。今回はプロジェクトのページを作るわけではないので、やればいいことはmasterブランチにpushすればいいことがわかる。あと、pushした後に変更が反映されるまで10分程度必要(gitレポジトリには即反映)ということも大事。

Page does not exist! Read the Full Documentation

Instructions for setting up username.github.com *

  Create a repo named username.github.com
  Push a `master` branch to GitHub and enjoy!

Instructions for setting up username.github.com/repo-name *

Caution: make your working directory clean before you do this (either stash or commit), otherwise this will lose any changes you've made to your project since the last commit.
  cd /path/to/repo-name
  git symbolic-ref HEAD refs/heads/gh-pages
  rm .git/index
  git clean -fdx
  echo "My GitHub Page" > index.html
  git add .
  git commit -a -m "First pages commit"
  git push origin gh-pages

WARNING: All pages (even those created on private repos) will be publicly viewable

* It may take up to 10 minutes to activate GitHub Pages for your account

今回は既存のgitレポジトリのpush先をUser Page用のレポジトリに変更することにする。まずは現在のリモートレポジトリの状態をチェックする。

$ cd /path/to/repo
$ git remote show github
Enter passphrase for key '/home/**************************************':
* remote github
  Fetch URL: git@github.com:**********/**********.git
  Push  URL: git@github.com:**********/**********.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (up to date)

User Page用のリモートレポジトリをaddする。

$ git remote add github2 git@github.com:**********/**********.github.com.git
$ git remote show github2
Enter passphrase for key '/home/**************************************':
* remote github2
  Fetch URL: git@github.com:**********/**********.github.com.git
  Push  URL: git@github.com:**********/**********.github.com.git
  HEAD branch: (unknown)

github2にpushするとブランチを指定しろといわれるので、masterブランチを指定する。

$ git push github2
Enter passphrase for key '/home/**************************************':
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
error: failed to push some refs to 'git@github.com:**********/**********.github.com.git'
$ git push github2
github/master   HEAD            master
$ git push github2 master
Enter passphrase for key '/home/**************************************':
Counting objects: 71, done.
Compressing objects: 100% (66/66), done.
Writing objects: 100% (71/71), 25.67 KiB, done.
Total 71 (delta 21), reused 0 (delta 0)
To git@github.com:**********/**********.github.com.git
 * [new branch]      master -> master

内容の変更記録は継承され、gitを使っているので変更は全て記録され辿れるようになっている。注意書きにあったように10分程度待ってからチェックする。正しくアップロードされていることがわかる。広告はない。静的なページを作る場合はこの方法が決定版なのかもしれない。例えばdoxygenとか静的なhtmlファイルを吐き出すツールを使うことで。

リファレンス

  1. GitHub Pages - Home
  2. git symbolic-ref HEAD refs/heads/gh-pages - Google 検索
  3. GithubのProject Pagesを作る手順を調べてみた。もしくはgitで空ブランチを作る方法を調べてみた。 - kanonjiの日記
  4. GitHub 上に ページを作成する | Tanablog
  5. git - How do I publish to <me>.github.com? - Stack Overflow
  6. Doxygen を github-pages にあげるのをお気楽にやる方法 - TokuLog 改メ tokuhirom’s blog

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2009-11-05T15:54:50+09:00
  2. Modified: 2009-11-05T15:54:50+09:00
  3. Generated: 2023-08-27T23:09:13+09:00