
「Pelican」は、Python製静的サイトジェネレータです。
「reStructuredText」「Markdown」「AsciiDoc」といったマークアップ言語を用いて、
好きなエディタでコンテンツを記載し、作成したコンテンツを付属のCLIツールで手軽に公開する事ができます。
似たようなツールとして、Ruby製の Jekyll や Octopress、 Middlemanが有名ですが、なんとなく「Python製の静的サイトジェネレーターが無いかなー」と探していたところ出会ったのがPelicanでした。
- Pelicanと出会った瞬間
触ってみて、Pelicanの良い所は「Pythonさえあれば動く!(ぴゅあぱいそん!)」「シンプル!」「動作が軽快!」ってところなのかもしれませんが、まぁ、とりあえず 名前がかっこいい って事で使い始めました。
(ロゴは適当ですが・・・)
ちなみに「Pelican」という名前の由来はフランス語で「notebook」を意味する「calepin」という単語の言葉遊びとの事
Why the name “Pelican”?
“Pelican” is an anagram for calepin, which means “notebook” in French. 😉
とりあえず1日程度触った程度ですが、Pelicanを使ってMarkdownで記事を書き、 GitHub Pages へブログを公開するところまでの手順を紹介します。
対象環境
今回の手順は下記環境で動作を確認しています。
- Mac OS X 10.9 (Mavericks)
- HomeBrew 0.9.5
- pyenv 0.4.0-20131217
- pyenv-virtualenv v20130622
- Python 2.7.6
- pelican 3.3.0
GitHub Pages の設定
まずは先に公開するGitHub Pagesの設定を行います。
Github Pages には 「ユーザサイト または オーガナイゼーションサイト」と「プロジェクトサイト」の2種類があります。
ユーザサイトはアカウントに1つだけ作れる Github Pages です。オーガナイゼーションサイトも同様にオーガナイゼーションに1つだけ作れる Github Pagesです。
プロジェクトサイトはリポジトリ用のページ作成をする機能で、リポジトリごとに作れる GitHub Pages です。
今回は、ブログでの利用を想定しているので、ユーザーサイトで設定を進めます。
ユーザーサイトの場合、URLは http://[アカウント名].github.io
になります。
自分の場合はアカウント名が ysaotome
なので ysaotome.github.io
がリポジトリ名で、 http://ysaotome.github.io
がサイトのURLになります。
リポジトリ作成
- GitHubの Create a New Repository サイトへアクセス
Repository name
に[アカウント名].github.io
を入力してCreate repository
をクリックします

- 無事公開用リポジトリが作成されました

環境準備
Pelicanを利用するためには、gitやgcc,makeと言ったコマンドが必要となりますが、購入状態のMac OS X には含まれないため、追加で Command Line Tools が必要となります。
Command Line Tools をインストール
Xcode がインストール済みの場合
- アプリケーション -> ユーティリティ ->
Terminal.app
(以下 ターミナル)を起動しコマンドを実行
% xcode-select --install
- 確認のダイアログが表示されるので
Install
をクリック

- ターミナルに下記の通り表示されればインストール完了です
% xcode-select --install
xcode-select: note: install requested for command line developer tools
Xcode が未インストールの場合
Xcodeは数GBの容量を消費するので、OS XやiOS向けの開発をしない場合は、あまり容量を消費しない Command Line Tools だけをインストールすれば大丈夫です。
- Apple Developerサイト へアクセス
- Developer IDを持っていない場合は新規登録が必要です。
- サイトにアクセスしたら、中断の 「Command Line Tools (OS X Mavericks) for Xcode」 をクリックして表示されたdmgファイルをダウンロード

- ダウンロードしたdmgファイルをマウントして中身の 「Command Line Tools (OS X 10.9).pkg」 をクリックしてインストーラを起動

- あとは表示にしたがってセットアップ完了です
パッケージマネージャ(Homebrew) をインストール
これからインストールしていくツール群を手軽にインストール・更新出来る様に、Mac OS X用のパケージマネージャである HomeBrew をインストールします。
- ターミナルからインストールコマンドを実行
% ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
Press ENTER to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /usr/local
WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.
To proceed, enter your password, or type Ctrl-C to abort.
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local
==> Downloading and installing Homebrew...
remote: Counting objects: 144562, done.
remote: Compressing objects: 100% (47392/47392), done.
remote: Total 144562 (delta 102348), reused 137052 (delta 96105)
Receiving objects: 100% (144562/144562), 21.40 MiB | 385.00 KiB/s, done.
Resolving deltas: 100% (102348/102348), done.
From https://github.com/Homebrew/homebrew
* [new branch] master -> origin/master
HEAD is now at e7dbfdd wxwidgets 3.0.0.0
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help
- ターミナルで
brew doctor
コマンドを実行し、下記の通り表示されればインストール完了です
% brew doctor
Your system is ready to brew.
- ついでに便利なツールをインストールします
% brew install zsh git vim wget
python管理ツール(pyenv) + 拡張パッケージ管理ツール(virtualenv) をインストール
Pythonのツールはpip
コマンドやeasy_install
コマンドを使って、便利な拡張パッケージをインストールしながら使う事が多いです。
今回利用するPelican自体もこの後、pip
コマンドでセットアップしますし、Pelican自体いろいろな拡張パッケージに依存しています。
ただ、いろいろな拡張パッケージを入れているうちに、どれが本当に必要なパッケージだったのかわからなくなったりします、
そんな時に、拡張パッケージを環境(フォルダ)毎に分離してくれる pyenv + virtualenv の組み合わせが便利です。
- pyenv も virtualenv も HomeBrew がインストール済みであればコマンド一発でインストールできます
% brew install pyenv-virtualenv pyenv
==> Installing pyenv-virtualenv dependency: pyenv
==> Downloading https://github.com/yyuu/pyenv/archive/v0.4.0-20131217.tar.gz
######################################################################## 100.0%
==> Caveats
To enable shims and autocompletion add to your profile:
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
To use Homebrew's directories rather than ~/.pyenv add to your profile:
export PYENV_ROOT=/usr/local/opt/pyenv
==> Summary
🍺 /usr/local/Cellar/pyenv/20131217: 200 files, 2.2M, built in 5 seconds
==> Installing pyenv-virtualenv
==> Downloading https://github.com/yyuu/pyenv-virtualenv/archive/v20130622.tar.gz
######################################################################## 100.0%
==> ./install.sh
🍺 /usr/local/Cellar/pyenv-virtualenv/20130622: 6 files, 36K, built in 3 seconds
- 初期設定を実施
% cat << _PYENVCONF_ >>~/.bashrc
if which pyenv > /dev/null; then
export PYENV_ROOT="\${HOME}/.pyenv"
export PATH=\${PYENV_ROOT}/shims:\${PATH}
eval "\$(pyenv init -)";
fi
_PYENVCONF_
% exec $SHELL -l
- 動作確認としてインストール可能なpythonのバージョン一覧を表示
pyenv install -l
コマンドで現在インストール可能なPythoのバージョン一覧を表示できます
% pyenv install -l
Available versions:
2.4
2.4.1
2.4.2
2.4.3
2.4.4
.....省略.....
stackless-2.7.2
stackless-3.2-dev
stackless-3.2.2
stackless-3.3-dev
stackless-dev
- pyenvでpython 2.7.6 をインストール
- 先ほど
pyenv install -l
で確認した内容を使ってpyenv install [hoge]
[hoge]に指定したバージョンのPythonをインストールする事ができます
- 先ほど
% pyenv install 2.7.6
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Downloading Python-2.7.6.tgz...
-> http://yyuu.github.io/pythons/1d8728eb0dfcac72a0fd99c17ec7f386
Installing Python-2.7.6...
Installed Python-2.7.6 to /Users/ysaotome/.pyenv/versions/2.7.6
Downloading setuptools-2.0.tar.gz...
-> https://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.tar.gz
Installing setuptools-2.0...
Installed setuptools-2.0 to /Users/ysaotome/.pyenv/versions/2.7.6
Downloading pip-1.4.1.tar.gz...
-> https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz
Installing pip-1.4.1...
Installed pip-1.4.1 to /Users/ysaotome/.pyenv/versions/2.7.6
- インストール結果を確認
pyenv versions
コマンドで現在システムにインストール済みのPython一覧と現在有効になっているPythonのバージョンを確認できます(* が付いているのが現在利用中のもの)
% pyenv versions
* system (set by /Users/ysaotome/.pyenv/version)
2.7.6
Pelican をインストール
まずは、pyenv + virtualenv で Pelican用の環境を作ります。
- 適当にPelican用のフォルダを作成
$ mkdir ~/Pelican-Blog
- Pelican専用環境を作成
pyenv virtualenv 2.7.6 [hoge]
コマンドで[hoge]という名前でPython 2.7.6の独立した環境事を作成します。
% cd ~/Pelican-Blog
% pyenv virtualenv 2.7.6 Pelican-Blog-276
New python executable in /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/python
Installing Setuptools..............................................................................................................................................................................................................................done.
Installing Pip.....................................................................................................................................................................................................................................................................................................................................done.
- 作成した環境をフォルダ配下で利用可能にする
pyenv local [hoge]
コマンドで[hoge]という名前の環境を今いるフォルダ配下で利用可能にします
% pyenv local Pelican-Blog-276
- 設定の確認
- 設定はフォルダ内部の
.python-version
を開くと確認できます pyenv versions
コマンドでも確認できます( * がついているのが現在利用中のもの)
- 設定はフォルダ内部の
% cat .python-version
Pelican-Blog-276
%
% pyenv versions
system
2.7.6
* Pelican-Blog-276 (set by /Users/ysaotome/Pelican-Blog/.python-version)
ディレクトリ配下にPelican専用のPython環境を作る事が出来ました。
ここまで来るとPelicanのインストールは簡単です
- Pythonの拡張パッケージ管理コマンド
pip
を使ってPelicanをインストール
% pip install pelican
Downloading/unpacking pelican
Downloading pelican-3.3.tar.gz (195kB): 195kB downloaded
Running setup.py egg_info for package pelican
Downloading/unpacking feedgenerator>=1.6 (from pelican)
Downloading feedgenerator-1.7.tar.gz
Running setup.py egg_info for package feedgenerator
warning: no files found matching '*' under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
Downloading/unpacking jinja2>=2.7 (from pelican)
Downloading Jinja2-2.7.1.tar.gz (377kB): 377kB downloaded
Running setup.py egg_info for package jinja2
warning: no files found matching '*' under directory 'custom_fixers'
warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: no previously-included files matching '*.pyc' found under directory 'jinja2'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'jinja2'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
Downloading/unpacking pygments (from pelican)
Downloading Pygments-1.6.tar.gz (1.4MB): 1.4MB downloaded
Running setup.py egg_info for package pygments
Downloading/unpacking docutils (from pelican)
Downloading docutils-0.11.tar.gz (1.6MB): 1.6MB downloaded
Running setup.py egg_info for package docutils
warning: no files found matching 'MANIFEST'
warning: no files found matching '*' under directory 'extras'
warning: no previously-included files matching '.cvsignore' found under directory '*'
warning: no previously-included files matching '*.pyc' found under directory '*'
warning: no previously-included files matching '*~' found under directory '*'
warning: no previously-included files matching '.DS_Store' found under directory '*'
Downloading/unpacking pytz>=0a (from pelican)
Downloading pytz-2013.9.tar.bz2 (159kB): 159kB downloaded
Running setup.py egg_info for package pytz
warning: no files found matching '*.pot' under directory 'pytz'
warning: no previously-included files found matching 'test_zdump.py'
Downloading/unpacking blinker (from pelican)
Downloading blinker-1.3.tar.gz (91kB): 91kB downloaded
Running setup.py egg_info for package blinker
Downloading/unpacking unidecode (from pelican)
Downloading Unidecode-0.04.14.tar.gz (200kB): 200kB downloaded
Running setup.py egg_info for package unidecode
Downloading/unpacking six (from pelican)
Downloading six-1.4.1.tar.gz
Running setup.py egg_info for package six
Downloading/unpacking markupsafe (from jinja2>=2.7->pelican)
Downloading MarkupSafe-0.18.tar.gz
Running setup.py egg_info for package markupsafe
Installing collected packages: pelican, feedgenerator, jinja2, pygments, docutils, pytz, blinker, unidecode, six, markupsafe
Running setup.py install for pelican
Installing pelican script to /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin
Installing pelican-import script to /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin
Installing pelican-quickstart script to /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin
Installing pelican-themes script to /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin
Running setup.py install for feedgenerator
warning: no files found matching '*' under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
Running setup.py install for jinja2
warning: no files found matching '*' under directory 'custom_fixers'
warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: no previously-included files matching '*.pyc' found under directory 'jinja2'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'jinja2'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
Running setup.py install for pygments
Installing pygmentize script to /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin
Running setup.py install for docutils
changing mode of build/scripts-2.7/rst2html.py from 644 to 755
changing mode of build/scripts-2.7/rst2s5.py from 644 to 755
changing mode of build/scripts-2.7/rst2latex.py from 644 to 755
changing mode of build/scripts-2.7/rst2xetex.py from 644 to 755
changing mode of build/scripts-2.7/rst2man.py from 644 to 755
changing mode of build/scripts-2.7/rst2xml.py from 644 to 755
changing mode of build/scripts-2.7/rst2pseudoxml.py from 644 to 755
changing mode of build/scripts-2.7/rstpep2html.py from 644 to 755
changing mode of build/scripts-2.7/rst2odt.py from 644 to 755
changing mode of build/scripts-2.7/rst2odt_prepstyles.py from 644 to 755
warning: no files found matching 'MANIFEST'
warning: no files found matching '*' under directory 'extras'
warning: no previously-included files matching '.cvsignore' found under directory '*'
warning: no previously-included files matching '*.pyc' found under directory '*'
warning: no previously-included files matching '*~' found under directory '*'
warning: no previously-included files matching '.DS_Store' found under directory '*'
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/rst2html.py to 755
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/rst2latex.py to 755
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/rst2man.py to 755
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/rst2odt.py to 755
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/rst2odt_prepstyles.py to 755
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/rst2pseudoxml.py to 755
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/rst2s5.py to 755
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/rst2xetex.py to 755
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/rst2xml.py to 755
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/rstpep2html.py to 755
Running setup.py install for pytz
warning: no files found matching '*.pot' under directory 'pytz'
warning: no previously-included files found matching 'test_zdump.py'
Running setup.py install for blinker
Running setup.py install for unidecode
Running setup.py install for six
Running setup.py install for markupsafe
building 'markupsafe._speedups' extension
/usr/bin/gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/ysaotome/.pyenv/versions/2.7.6/include/python2.7 -c markupsafe/_speedups.c -o build/temp.macosx-10.4-x86_64-2.7/markupsafe/_speedups.o
/usr/bin/gcc -bundle -undefined dynamic_lookup -L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/ysaotome/.pyenv/versions/2.7.6/lib build/temp.macosx-10.4-x86_64-2.7/markupsafe/_speedups.o -o build/lib.macosx-10.4-x86_64-2.7/markupsafe/_speedups.so
Successfully installed pelican feedgenerator jinja2 pygments docutils pytz blinker unidecode six markupsafe
Cleaning up...
- 今回は
Markdown
記法を使って記事を書くので markdawnパッケージもインストール
% pip install Markdown
Downloading/unpacking Markdown
Downloading Markdown-2.3.1.tar.gz (267kB): 267kB downloaded
Running setup.py egg_info for package Markdown
Installing collected packages: Markdown
Running setup.py install for Markdown
changing mode of build/scripts-2.7/markdown_py from 644 to 755
Converting docs/authors.txt -> build/docs/authors.html
Converting docs/change_log.txt -> build/docs/change_log.html
Converting docs/cli.txt -> build/docs/cli.html
Converting docs/index.txt -> build/docs/index.html
Converting docs/install.txt -> build/docs/install.html
Converting docs/reference.txt -> build/docs/reference.html
Converting docs/release-2.0.1.txt -> build/docs/release-2.0.1.html
Converting docs/release-2.0.2.txt -> build/docs/release-2.0.2.html
Converting docs/release-2.0.txt -> build/docs/release-2.0.html
Converting docs/release-2.1.0.txt -> build/docs/release-2.1.0.html
Converting docs/release-2.1.1.txt -> build/docs/release-2.1.1.html
Converting docs/release-2.2.0.txt -> build/docs/release-2.2.0.html
Converting docs/release-2.2.1.txt -> build/docs/release-2.2.1.html
Converting docs/release-2.3.txt -> build/docs/release-2.3.html
Converting docs/siteindex.txt -> build/docs/siteindex.html
Converting docs/test_suite.txt -> build/docs/test_suite.html
Converting docs/extensions/abbreviations.txt -> build/docs/extensions/abbreviations.html
Converting docs/extensions/admonition.txt -> build/docs/extensions/admonition.html
Converting docs/extensions/api.txt -> build/docs/extensions/api.html
Converting docs/extensions/attr_list.txt -> build/docs/extensions/attr_list.html
Converting docs/extensions/code_hilite.txt -> build/docs/extensions/code_hilite.html
Converting docs/extensions/definition_lists.txt -> build/docs/extensions/definition_lists.html
Converting docs/extensions/extra.txt -> build/docs/extensions/extra.html
Converting docs/extensions/fenced_code_blocks.txt -> build/docs/extensions/fenced_code_blocks.html
Converting docs/extensions/footnotes.txt -> build/docs/extensions/footnotes.html
Converting docs/extensions/header_id.txt -> build/docs/extensions/header_id.html
Converting docs/extensions/index.txt -> build/docs/extensions/index.html
Converting docs/extensions/meta_data.txt -> build/docs/extensions/meta_data.html
Converting docs/extensions/nl2br.txt -> build/docs/extensions/nl2br.html
Converting docs/extensions/sane_lists.txt -> build/docs/extensions/sane_lists.html
Converting docs/extensions/smart_strong.txt -> build/docs/extensions/smart_strong.html
Converting docs/extensions/tables.txt -> build/docs/extensions/tables.html
Converting docs/extensions/toc.txt -> build/docs/extensions/toc.html
Converting docs/extensions/wikilinks.txt -> build/docs/extensions/wikilinks.html
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/markdown_py to 755
Successfully installed Markdown
Cleaning up...
- 後ほと使うGitHub Pagesへの公開操作をいい感じに実施してくれる
ghp-import
パッケージもインストール
% pip install ghp-import
Downloading/unpacking ghp-import
Downloading ghp-import-0.3.2.tar.gz
Running setup.py egg_info for package ghp-import
Installing collected packages: ghp-import
Running setup.py install for ghp-import
changing mode of build/scripts-2.7/ghp-import from 644 to 755
changing mode of /Users/ysaotome/.pyenv/versions/Pelican-Blog-276/bin/ghp-import to 755
Successfully installed ghp-import
Cleaning up...
- インストール結果を確認
- 現在インストール済みの拡張パッケージは
pip list
コマンドで確認できます
- 現在インストール済みの拡張パッケージは
% pip list
blinker (1.3)
docutils (0.11)
feedgenerator (1.7)
ghp-import (0.3.2)
Jinja2 (2.7.1)
Markdown (2.3.1)
MarkupSafe (0.18)
pelican (3.3)
pip (1.4.1)
Pygments (1.6)
pytz (2013.9)
setuptools (0.9.8)
six (1.4.1)
Unidecode (0.04.14)
wsgiref (0.1.2)
Pelicanを使う!
「pelican-quickstart」でひな形を作る
- 便利なコマンド
pelican-quickstart
を使ってサイトのひな形を作る事ができます- インタビュー形式で記載していくとサイトのひな形が出来上がります
- ※インタビュー形式では入力に日本語(マルチバイト)を利用できないが、後から設定ファイルを直接編集すれば利用可能
- もちろん後から修正する事が可能です
% cd ~/Pelican-Blog
% pelican-quickstart
Welcome to pelican-quickstart v3.3.0.
This script will help you create a new Pelican-based website.
Please answer the following questions so this script can generate the files
needed by Pelican.
> Where do you want to create your new web site? [.]
> What will be the title of this web site? ysaotome blog
> Who will be the author of this web site? ysaotome
> 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://ysaotome.github.io
> Do you want to enable article pagination? (Y/n) Y
> How many articles per page do you want? [10] 10
> 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
Done. Your new project is available at /Users/ysaotome/Pelican-Blog
- 質問内容と回答例
- Where do you want to create your new web site? [.] .
- ウェブサイト作成するディレクトリはどこ? → ここでは
.
とした(現在のディレクトリ)
- ウェブサイト作成するディレクトリはどこ? → ここでは
- What will be the title of this web site? ysaotome blog
- ウェブサイトの名前は? → 空白にはできない。ここでは
ysaotome blog
とした
- ウェブサイトの名前は? → 空白にはできない。ここでは
- Who will be the author of this web site? ysaotome
- ウェブサイトの作者は? → ここでは
ysaotome
とした
- ウェブサイトの作者は? → ここでは
- What will be the default language of this web site? [en] ja
- ウェブサイトのデフォルトの言語は? → ここでは
ja
とした
- ウェブサイトのデフォルトの言語は? → ここでは
- Do you want to specify a URL prefix? e.g., http://example.com (Y/n) Y
- URLのプレフィックスを指定する? → ここでは
Y
とした
- URLのプレフィックスを指定する? → ここでは
- What is your URL prefix? (see above example; no trailing slash) http://ysaotome.github.io
- URLプレフィックスは? → ここでは
http://ysaotome.github.io
とした
- URLプレフィックスは? → ここでは
- Do you want to enable article pagination? (Y/n) Y
- ページネーション(ページ分割)を有効にする? → ここでは
Y
とした
- ページネーション(ページ分割)を有効にする? → ここでは
- How many articles per page do you want? [10] 10
- 1ページあたりの記事数は? → ここでは
10
とした
- 1ページあたりの記事数は? → ここでは
- Do you want to generate a Fabfile/Makefile to automate generation and publishing? (Y/n) Y
- 記事の生成と公開を自動化するFabfile / Makefileを生成しますか? → ここでは
Y
とした
- 記事の生成と公開を自動化するFabfile / Makefileを生成しますか? → ここでは
- Do you want an auto-reload & simpleHTTP script to assist with theme and site development? (Y/n) Y
- テーマやサイト作成に便利なオートリロードやsimpleHTTPスクリプトを利用しますか? → ここでは
Y
とした
- テーマやサイト作成に便利なオートリロードやsimpleHTTPスクリプトを利用しますか? → ここでは
- Do you want to upload your website using FTP? (y/N) N
- ウェブサイトのアップロードに FTP を利用しますか? → ここでは
N
とした
- ウェブサイトのアップロードに FTP を利用しますか? → ここでは
- Do you want to upload your website using SSH? (y/N) N
- ウェブサイトのアップロードに SSH を利用しますか? → ここでは
N
とした
- ウェブサイトのアップロードに SSH を利用しますか? → ここでは
- Do you want to upload your website using Dropbox? (y/N) N
- ウェブサイトのアップロードに Dropbox を利用しますか? → ここでは
N
とした
- ウェブサイトのアップロードに Dropbox を利用しますか? → ここでは
- Do you want to upload your website using S3? (y/N) N
- ウェブサイトのアップロードに S3 を利用しますか? → ここでは
N
とした
- ウェブサイトのアップロードに S3 を利用しますか? → ここでは
- Do you want to upload your website using Rackspace Cloud Files? (y/N) N
- ウェブサイトのアップロードに Rackspace Cloud Files を利用しますか? → ここでは
N
とした
- ウェブサイトのアップロードに Rackspace Cloud Files を利用しますか? → ここでは
- Where do you want to create your new web site? [.] .
- 作成されたファイルを確認
% ls
. .python-version content fabfile.py pelicanconf.py
.. Makefile develop_server.sh output publishconf.py
記事を書いてみる
テストに記事を書いて見ます。
Pelicanは「reStructuredText」形式での記載がデフォルトですが、今回は書き慣れた「Markdown」を使って書いていきます。
記事は content
ディレクトリ配下にファイルを作成する事で書くことができます。
first-post.md
というファイル名で記事を記載します。- 拡張子の
.md
でファイルフォーマットを判断されるので Markdown 形式で記載する時は.md
reStructuredText 形式で記載するときは.rst
とします
- 拡張子の
% vim content/first-post.md
Title: 最初のPelicanブログ
Date: 2014-01-04 22:00
Category: Pelican
Tags: pelican, python
Slug: first-post
Author: ysaotome
Summary: 記事の要約です。
# ペリカン記事のタイトル
- SyntaxHighlitだってバッチリ!
python
print “Hello World!!”
- 作成したファイルから
make html
コマンドでhtmlファイルを生成できます- デフォルトで
output
ディレクトリ配下にhtmlファイルが生成されます。
- デフォルトで
% make html
pelican /Users/ysaotome/Pelican-Blog/content -o /Users/ysaotome/Pelican-Blog/output -s /Users/ysaotome/Pelican-Blog/pelicanconf.py
Done: Processed 1 articles and 0 pages in 0.30 seconds.
- htmlファイルが無事生成できたら、
make serve
コマンドで組み込みウェブサーバ(simpleHTTP)を起動して内容を確認します
% make serve
cd /Users/ysaotome/Pelican-Blog/output && python -m pelican.server 8000
- 無事起動したらブラウザから
http://localhost:8000/
にアクセスします

Pelicanで記事が作成出来ました!
デザインを割り当ててみる
デフォルトのテーマだとちょっとかっこ悪いですよね。
Wrdpressもそうである様にPelicanも有志の方々が作ったカッコイイテーマがいくつかあります。
(Wordpressよりはかなり少ないですが。。。)
公式が集めているテーマの一覧は Pelican Themes のサイトで確認できます。
ただ、今回はカッコイイテーマって事で「pelican-octopress-theme」を使いたいと思います。
名前の通りOctopressの見た目をPelicanに適用したものになります。
Pelicanでのテーマ割り当て方法はとても簡単です。
- リポジトリからテーマを取得
% cd ~/Pelican-Blog
% % wget https://github.com/duilio/pelican-octopress-theme/archive/master.zip ; unzip -q master.zip ; rm -rf master.zip
--2014-01-04 10:11:07-- https://github.com/duilio/pelican-octopress-theme/archive/master.zip
Resolving github.com... 192.30.252.129
Connecting to github.com|192.30.252.129|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/duilio/pelican-octopress-theme/zip/master [following]
--2014-01-04 10:11:08-- https://codeload.github.com/duilio/pelican-octopress-theme/zip/master
Resolving codeload.github.com... 192.30.252.146
Connecting to codeload.github.com|192.30.252.146|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/zip]
Saving to: ‘master.zip’
[ <=> ] 95,168 489KB/s in 0.2s
2014-01-04 10:11:10 (489 KB/s) - ‘master.zip’ saved [95168]
- 設定ファイル
pelicanconf.py
を修正- 任意の場所に
THEME = './pelican-octopress-theme-master'
を追記する
- 任意の場所に
% vi pelicanconf.py
THEME = './pelican-octopress-theme-master'
- htmlファイルの生成
% make html
- 組み込みサーバを起動して確認
% make serve
- ブラウザから
http://localhost:8000/
へアクセスします

一気にブログっぽくなりました。
GitHub Pagesでサイトを公開してみる
- まずはgitの初期設定を行います
% git init
Initialized empty Git repository in /Users/ysaotome/Pelican-Blog/.git/
- サイトに公開したくないファイル(.gitで管理したくないファイル)の一覧を設定します
- gitでは
.gitignore
というファイルにパスを記載する事でgitで管理したくないファイルを設定できます
- gitでは
% vi .gitignore
## Pelican
output/*
*.pid
## Python
*.py[cod]
## Mac OS X
.DS_Store
.*~
*~
- GitHub Pagesに公開します
- 最初に接続する際にGitHubの
Username
とPassword
が聞かれますので入力してください。 make html
コマンドでhtmlファイルを生成し、ghp-import output
コマンドで公開用ディレクトリを指定しています- 最後に
git push https://github.com/ysaotome/ysaotome.github.io.git gh-pages:master
でGitHub Pages用のリポジトリに公開します。
- 最初に接続する際にGitHubの
% make html
pelican /Users/ysaotome/Pelican-Blog/content -o /Users/ysaotome/Pelican-Blog/output -s /Users/ysaotome/Pelican-Blog/pelicanconf.py
Done: Processed 1 articles and 0 pages in 0.18 seconds.
% ghp-import output
% git push https://github.com/ysaotome/ysaotome.github.io.git gh-pages:master
Username:
Password:
Counting objects: 37, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (22/22), done.
Writing objects: 100% (37/37), 58.50 KiB | 0 bytes/s, done.
Total 37 (delta 12), reused 37 (delta 12)
To https://github.com/ysaotome/ysaotome.github.io.git
* [new branch] gh-pages -> master
- ブラウザで
http://ysaotome.github.io
を開いて確認します- 反映は長いと10分程度かかります。

- 以上で公開完了です
- 記事の作成は、上記の手順の繰り返しになります
余談
Pelicanを触り始めて一番最初に困った事は日本語情報の少なさでした。
といっても、本家ドキュメントが充実していて、海外での利用ユーザもそれなりにいて情報公開してくれているので、頑張ればなんとかなる感じです。
Pelicanはシンプルで使いやすい静的サイトジェネレータだと思います。
日本語情報が少ない事で、使われないのは惜しいと思い、この記事を書き起こしました。
- 他のツールは?
なんとなく年末に静的サイトジェネレーターを探していた所、下記サイトを見つけました。
Pythonに限らずRubyやPerlなど言語別や更新頻度別に静的サイトジェネレータを探す事が出来るサイトです。
いくつか試してみましたが、自分の中ではPelicanが一番しっくりきました。
他にもたくさん紹介されているので、この中から試して使いやすいツールを見つけるのも楽しいかと思います。
- このサイトは?
「GitHub Pages でサイトを公開!」と言っているわりに、このサイトはさくらのVPSで公開していたりします。