静的サイトジェネレータPelicanを使ってみる。
開発環境
- Linux Mint 17.3 MATE 32bit
- pyenv
- pelican 3.7.1
前回まで
- Pythonの環境構築について調べてpyenvで3.6.1をインストールした
- Pythonのvenvで仮想環境を用意してする
- pyenvで入れたPython3.6.1のvenvを使ってPelicanをインストールした
- pipでMarkdownとghp-importをインストールした
参考
Pelican + Markdown + GitHub Pagesで管理するブログの作り方 - blog@sotm.jp
準備
bash -l $ python -V Python 3.6.1 $ source .../venv/3_6_1/pelican_install/bin/activate
- pyenvを有効にする
- pythonは3.6.1を使う
- venvで作った仮想環境
pelican_installをアクティブにする
ブログのディレクトリを作る
pelican_quickstart_blogとする。
(pelican_install) $ mkdir pelican_quickstart_blog (pelican_install) $ cd pelican_quickstart_blog
ブログのひな形を作る
pelican-quickstartコマンドを実行する。
(pelican_install) ... $ pelican-quickstart
質問攻めされる。適当に答えてしまったが、とりあえずやってみる。
Welcome to pelican-quickstart v3.7.1.
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? Python Study
> Who will be the author of this web site? pylangstudy
> What will be the default language of this web site? [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://pylangstudy.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) Y
> What is the hostname of your FTP server? [localhost]
> What is your username on that server? [anonymous]
> Where do you want to put your web site on that server? [/]
> Do you want to upload your website using SSH? (y/N) y
> What is the hostname of your SSH server? [localhost]
> What is the port of your SSH server? [22]
> What is your username on that server? [root]
> Where do you want to put your web site on that server? [/var/www]
> 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 /tmp/pelican_quickstart_blog
Web サイトのための作業ディレクトリを作る - Compnet
pelican_quickstart_blog/ディレクトリ配下に以下のようなファイルが生成されたはず。
- content/
- output/
- pelicanconf.py
- publishconf.py
content作成
content/ディレクトリ配下にindex.mdファイルを作成する。
index.md
# マークダウン
pelican content -s publishconf.pyコマンドでHTMLを生成する。はずだったがエラー。
(pelican_install) $ pelican content -s publishconf.py ERROR: Skipping ./index.md: could not find information about 'title'
失敗。調べてみた。
Pelican + Markdown + GitHub Pagesで管理するブログの作り方 - blog@sotm.jp
どうやらMarkdownファイルの先頭に以下が必要らしい。以下の疑問は無視して進める。
- それってMarkdownじゃなくね?
- Author最初に設定しなかったっけ?
Title: 最初のPelicanブログ Date: 2018-01-15 17:30 Category: Pelican Tags: pelican, python Slug: first-post Author: pylangstudy Summary: 記事の要約。
index.md
Title: 最初のPelicanブログ
Date: 2018-01-15 17:30
Category: Pelican
Tags: pelican, python
Slug: first-post
Author: pylangstudy
Summary: 記事の要約。
# 見出し
* リスト1
* リスト2
```python
print('hello world !!')
```
abc|def|ghi
---|---|---|
1|2|3
4|5|6
contentをHTML化
(pelican_install) $ pelican content -s publishconf.py Done: Processed 1 article, 0 drafts, 0 pages and 0 hidden pages in 0.62 seconds.
make htmlコマンドでも実行できる。
(pelican_install) $ make html pelican /tmp/pelican_quickstart_blog/content -o /tmp/pelican_quickstart_blog/output -s /tmp/pelican_quickstart_blog/pelicanconf.py Done: Processed 1 article, 0 drafts, 0 pages and 0 hidden pages in 1.04 seconds.
output/ディレクトリの中にできる。index.htmlを開いてブラウザで閲覧する。

CSSが反映されていない。ローカルサーバで表示確認するらしい。
ローカルサーバ
(pelican_install) $ make serve
ブラウザ起動して以下のURLを参照する。
http://localhost:8000/

所感
色々と謎は多いが、とりあえずブログは書けそう。