静的サイトジェネレータPelicanでAsciiDocを使いたかったが…。
開発環境
- Linux Mint 17.3 MATE 32bit
- pyenv
- pelican-quickstart v3.7.1
前回まで
Ruby
Python
- Pythonの環境構築について調べてpyenvで3.6.1をインストールした
- Pythonのvenvで仮想環境を用意してする
- pyenvで入れたPython3.6.1のvenvを使ってPelicanをインストールした
- pipでMarkdownとghp-importをインストールした
- pelican-quickstartでブログのひな形をつくってみる
- Pelicanのプラグインをインストールする
Pelicanのプラグインをダウンロードしたものの、AsciiDocプラグインが使えなかった。Python2で環境構築せねばならない。2は2020年でサポート終了するらしいので、今更使うかどうするか迷いどころ。Ruby製のAsciiDoctorにしたほうがいいか?
参考
- Pelican + Markdown + GitHub Pagesで管理するブログの作り方 - blog@sotm.jp
- Pelican 3.7.1 — Pelican 3.7.1 documentation
準備
bash -l $ python -V Python 3.6.1 $ source .../venv/3_6_1/pelican_install/bin/activate $ cd .../pelican_quickstart_blog
pyenv
を有効にするpython
は3.6.1を使うvenv
で作った仮想環境pelican_install
をアクティブにするcd
でブログのひな形を作ったディレクトリに移動する
プラグイン使用準備するも使えなかった
pelicanconf.py
PLUGIN_PATHS = ['.../root/pj/venv/3_6_1/pelican-plugins'] PLUGINS = ['asciidoc_reader', 'related_posts', 'tag_cloud', 'tipue_search', 'sitemap']
以下、AsciiDocが使えなかったログ。
$ make html ERROR: Could not process ./index.asc | ModuleNotFoundError: No module named 'cStringIO'
stringio - python 3.x ImportError: No module named 'cStringIO' - Stack Overflow
asciidoc_reader.py
のfrom cStringIO import StringIO
をfrom io import StringIO
に変更する。
$ make html ERROR: Could not process ./index.asc | TypeError: initial_value must be str or None, not bytes
以下のように修正した。
def read(self, source_path): """Parse content and metadata of asciidoc files""" # from cStringIO import StringIO # from io import StringIO from io import BytesIO with pelican_open(source_path) as source: # text = StringIO(source.encode('utf8')) text = BytesIO(source.encode('utf8')) # content = StringIO() content = BytesIO() ad = AsciiDocAPI()
$ make html ERROR: Could not process ./index.asc | NameError: name 'AsciiDocAPI' is not defined
https://github.com/getpelican/pelican-plugins/tree/master/asciidoc_reader
asciidoc_readerはPython3では動作しないらしい。これはひどい。
これならRuby製のAsciiDoctorを使ったほうがいいか。
所感
どうしよう…。
AsciiDoctorのRubyにしろ、AsciiDocAPIのPythonにしろ、大本のSDK環境構築とその利用が煩雑でむずかしい。