- 野良翻訳したSphinxドキュメントをGitHub Pagesを使って公開したい
master
ブランチはfork元のままにしておきたいmaster
ブランチのdoc
フォルダを公開する機能は使えない想定
- 翻訳作業は
trans-ja
ブランチで行う - 翻訳後ビルドしたHTML等を
gh-pages
ブランチに登録し公開する
sphinx-ghp-test
リポジトリでテストmaster
ブランチにはビルド結果ファイル(HTML等)は登録しない- 実際は
trans-ja
ブランチとなる想定
- 実際は
gh-pages
ブランチにはビルド結果ファイルのみ登録する
-
GitHub上でリポジトリを作成
sphinx-ghp-test
-
ローカルにclone
git clone git@github.com:number09/sphinx-ghp-test.git
- 現在のディレクトリに
sphinx-ghp-test
のディレクトリが作成される
-
sphinx-ghp-test
ディレクトリへ移動cd sphinx-ghp-test
- 現在のブランチ:master
-
プロジェクト用の仮想環境を
python3 -m venv (任意の名前)
で作成するvenv
という名前にするpython3 -m venv venv
-
仮想環境に入った上で、
pip
コマンドでSphinxをインストールするsource venv/bin/activate
pip install sphinx
-
sphinx-quickstart
コマンドでSphinxの初期ファイルを生成する- sphinxのバージョンは1.8.4を使用
- 以下はデフォルトから変更した項目
- 言語は"ja"を指定
- ドキュメント名、作成者は任意
- .nojekyllファイルを作成する
- ビルドしたHTMLをGithub Pagesで正しく表示するために必要
make.bat
ファイルは作成しない
- 以下はデフォルトから変更した項目
- sphinxのバージョンは1.8.4を使用
-
仮想環境の
venv
ディレクトリは管理しないので.gitignore
に記述touch .gitignore
でファイルを生成.gitignore
ファイルにvenv
を追記
-
一旦
.gitignore
ファイルだけcommit & pushしておくgit add .gitignore
git commit -m"add .gitignore"
git push
-
空っぽの
gh-pages
ブランチを作成 & チェックアウトするgit checkout --orphan gh-pages
- 通常のブランチ作成は、現在のブランチを元に作成するが、
--orphan
を付けることで、過去の歴史の無いブランチが作成出来る
- 通常のブランチ作成は、現在のブランチを元に作成するが、
- 上記コマンドで、現在のブランチが
gh-pages
に変更になっている - ただしまだ
git branch
してもブランチ一覧に表示されない状態
-
gh-pages
ブランチに空のREADME.md
ファイルだけコミットする。何でもいいので一度コミットが必要- 現在の状態を確認
git status
On branch gh-pages No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: .gitignore new file: Makefile new file: conf.py new file: index.rst
- 4つのファイルがステージされているので、アンステージする(コミット待ち状態を取り消す)
git rm --cached $(git ls-files)
- 再確認
git status
On branch gh-pages No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) .gitignore Makefile conf.py index.rst nothing added to commit but untracked files present (use "git add" to track)
- ファイル作成 & コミット
touch README.md
git add README.md
git commit -m"create gh-pages branch"
- 確認
git branch
* gh-pages master
gh-pages
ブランチをリモートリポジトリ(GitHub)へpushgit push -u origin HEAD
- 現在の状態を確認
-
master
ブランチでの作業に戻るgit checkout -f master
-f
でローカルファイルに変更があっても、master
の内容で強制上書きする
- この時点でのディレクトリの中身(ls)
Makefile conf.py index.rst venv/
-
_build/html
ディレクトリはビルドしたHTML等が出力されるフォルダ
このディレクトリにgh-pages
ブランチの内容を展開するgit submodule add -b gh-pages git@github.com:number09/sphinx-ghp-test.git _build/html
- 注意1
gh-pages
ブランチがあり、ファイルを一度コミットしている必要がある - 注意2 指定したディレクトリ(この場合
_build/html
)が無い状態で上記コマンドを実行する- ディレクトリがあると
already exists
といわれてエラーになる
- ディレクトリがあると
- 注意1
- この時点で、
build/html
ディレクトリにREADME.md
ファイル(gh-pagesの内容)が作成されている
-
状態を確認
git status
On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: .gitmodules new file: _build/html
.gitmodules
ファイルが作成されているのでコミットする
_build
ディレクトリがステージされているのでアンステージし、バージョン管理外にするgit reset _build/html
git commit -m"add .gitmodules"
git push
.gitignore
ファイルに_build
を追記git add .gitignore
git commit -m"update .gitignore"
git push
-
Sphinxドキュメントをビルドする
make html
_build/html
ディレクトリ(README.md
ファイルがある位置)に出力される
-
master
ブランチの状態確認git status
On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean
- ビルドしたファイルが出力されたが、
_build
ディレクトリはバージョン管理外になっている為(?)
変更なしとされる
- ビルドしたファイルが出力されたが、
-
_build/html
ディレクトリ内でgh-pages
ブランチの状態確認cd _build/html
git status
Your branch is up to date with 'origin/gh-pages'. Untracked files: (use "git add <file>..." to include in what will be committed) .buildinfo .nojekyll _sources/ _static/ genindex.html index.html objects.inv search.html searchindex.js venv/ nothing added to commit but untracked files present (use "git add" to track)
-
サイトで公開したいファイルを
gh-pages
ブランチにcommit & pushするgit add .buildinfo .nojekyll _sources _static genindex.html index.html objects.inv search.html searchindex.js
git commit -m"build html"
git push
-
GitHub Pagesでは、https://number09.github.io/sphinx-ghp-test/ で表示出来る