4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python製静的HTMLジェネレータのPelicanでGitHub Pagesを公開する方法

Last updated at Posted at 2016-12-10

Python製静的HTMLジェネレータのPelicanでGitHub Pagesを公開する方法

概要

GitHub Pagesの公開にあたり、Python製の静的HTMLジェネレータのPelicanを使ってページを作成した。
公開にあたってハマったところがあったので忘備録として手順をメモする。
細かな手順は下記参考サイトが詳しいため大変参考になったため、そちらを元に作業するとよい。

1. 環境

  • Python2.7.8
  • Pelican3.7.0
  • pipインストール済
  • GitHubアカウント取得済

2. 手順の概要

  1. pelicanのインストール
  2. ghp-importのインストール
  3. GitHub Pagesのプロジェクトの作成
  4. ローカルリポジトリの作成
  5. pelican-quickestart実行
  6. pelican-quickestartの入力
  7. 記事の作成
  8. 記事の確認
  9. GitHub Pagesへ公開
  10. masterブランチのpush

3. 詳細手順

3-1. pelicanのインストール

# pip install pelican

3-2. ghp-importのインストール

# pip install ghp-import

3-3. GitHub Pagesのプロジェクトの作成

GitHub Pagesのページからリポジトリを作成する。
ユーザ用とプロジェクト用の2種類あるが、今回はユーザ用で作成した。

3-4. ローカルリポジトリの作成

リポジトリをcloneする。

# git clone <リポジトリURL>

3-5. pelican-quickestart実行

# pelican-quickstart

3-6. pelican-quickstartの入力

> Where do you want to create your new web site? [.]
> What will be the title of this web site? yusukew62 blog
> Who will be the author of this web site? yusukew62
> What will be the default language of this web site? [en] ja
> Do you want to specify a URL prefix? e.g., http://example.com   (Y/n) Y
> What is your URL prefix? (see above example; no trailing slash) http://yusukew62.github.io
> Do you want to enable article pagination? (Y/n) Y
> How many articles per page do you want? [10]
> What is your time zone? [Europe/Paris] Asia/Tokyo
> Do you want to generate a Fabfile/Makefile to automate generation and publishing? (Y/n) Y
> Do you want an auto-reload & simpleHTTP script to assist with theme and site development? (Y/n) Y
> Do you want to upload your website using FTP? (y/N) N
> Do you want to upload your website using SSH? (y/N) N
> Do you want to upload your website using Dropbox? (y/N) N
> Do you want to upload your website using S3? (y/N) N
> Do you want to upload your website using Rackspace Cloud Files? (y/N) N
> Do you want to upload your website using GitHub Pages? (y/N) y
> Is this your personal page (username.github.io)? (y/N) y
Done. Your new project is available at /root/testpelican

3-7. 記事の作成

pelican-quickstartが完了すると、以下のファイルが作成される。

Makefile  content  develop_server.sh  fabfile.py  output  pelicanconf.py  publishconf.py

contentディレクトの下に投稿する記事を作成する。
今回はより Pythonらしく reStructuredTextで記事を作成した。
Markdownで作成する場合は、pipからMarkdownを入れておくこと。

# vi content/20161210.rst

記事の例


First Post By Pelican
#####################

:date: 2016-12-08 12:00
:modified: 2016-12-10 14:40
:tags: Python, Pelican
:category: Python
:authors: yusukew62
:summary: first post by pelican

.. code-block:: python

    print "Hello World"

3-8. 記事の確認

htmlファイルを生成する。

# make html

表示を確認する。

# make serve

ブラウザで 上記実行ホストのIPアドレスへポート 8000で接続する。

3-9. GitHub Pagesへ公開

GitHub Pagesで公開するファイルを gh-pagesブランチへ出力する。

# ghp-import output

生成された htmlファイルをローカルリポジトリへ追加する。

# git add output/
# git commit -m 'Added all created html files'

gh-pagesブランチのファイル一式を、リモートリポジトリのmasterブランチへ公開する

# git push -f origin gh-pages:master

少し時間を置いてからページが更新されていることを確認する。

3-10. masterブランチのpush

gh-pagesブランチには、contentディレクトリやpelicanの設定ファイル(*.py)等は含まれないので、別ブランチを切ってpushしておく。
ここでは masterから sourceというブランチとして作成し、リモートリポジトリへ上げている。
※ masterブランチをリモートリポジトリへpushすると masterブランチのREADME.mdとなどが開されてしまう。

# git branch source
# git push origin source

ブラウザからアクセスして確認

http://<ユーザ名>.github.io

4. 参考

以下のサイトを参考にしました。
Pelican + Markdown + GitHub Pagesで管理するブログの作り方

4
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?