Sphinxにひっそり存在するビルダー "dirhtml"の使い勝手を知る
https://zenn.dev/attakei/articles/sphinx-make-dirhtml
nikola は使いこなせなくて短命に終わってしまった。
doit は面白いと思うのだが。
ということで、 sphinx
プラグインの ABlog です。
はまり1: Sphinx のキャッシュ
python -m sphinx content build
にデバッガをアタッチして試行錯誤するのだけど、
キャッシュされて処理されなかった。
python -m sphinx content build -E -v
とする。
- -E: 全処理(キャッシュを使わない)
- -v: 詳細メッセージ
はまり2: ablog が timezone の有無で日付の比較に失敗する
これは、既存記事の frontmatter
の日付に timezone
が付いていると
日付の比較に失敗する。
と対処した。
はまり3: myst-parser の toml frontmatter 対応
myst-parser
が ---
による yaml
形式の frontmatter
にしか対応していない様子。
hugo の frontmatter にある toml
様式に対応するべく改造したい。
切り出し
どこで処理しているのか探索が難航した。
site-packages/mdit_py_plugins/front_matter/index.py
で処理している。
Parse
site-packages/myst_parser/docutils_renderer.py
render_front_matter
で切り出した文字列を yaml
でパースしている。
except
節で toml
にリトライさせたら動いた。
モンキーパッチ
とりあえず conf.py
にて直接修正する。
ousttrue.github.io/content/patch.py at ablog · ousttrue/ousttrue.github.io
Contribute to ousttrue/ousttrue.github.io development by creating an account on GitHub.
https://github.com/ousttrue/ousttrue.github.io/blob/ablog/content/patch.py
後で PR 送ったりできるかな。
ABlog は何をしているのか
toctree無しのpost記事
特定の条件で、記事をブログ記事と見做して toctree
無しで辿れるようにする。
記事は、日付やタグでグループ化してくれる。
ablog.readthedocs.io
https://ablog.readthedocs.io/en/latest/manual/posting-and-listing/#posting-with-page-front-matter
パス指定。
条件。
frontmatter
等から最低限、日付の情報がとれないとトップページから辿る方法が無い状態になる。
あと sphinx
なのでトップレベルの表題が本文側に必要かも。
frontmatter
の title
を反映できると便利そう。
event: ‘doctree-read’
doctree から PostNode
を集める。
alog/post#process_posts(app, doctree)
追加のページ生成
ablog/templates
に格納されている。
これらに対して追加のページ生成を行っている。
genindex.html
などのように。
ToDo
✅ タグが変
toml 由来の tag の処理に失敗している。
["python", "ssg", "sphinx"]
が、
["python"
"ssg"
"sphinx"]
になっちゃってる。
Fix tags field for myst_parser by ousttrue · Pull Request #119 · sunpy/ablog
Description
Markdown post with tags field in front-matter has format mismatch.
---
tags: ["a", "b"]
---
Interpreted as ["a" and "b"].
I'm fix it.
This is caused in
https://github.com/executableb...
https://github.com/sunpy/ablog/pull/119
送ってみた。
v0.10.22
で修正。👍
✅ 日付のフォーマット
conf.py
✅ 記事のURL
✅ 記事タイトルは最初の見出しではなく、frontmatter の title にしたい
MystParser
を改造した。
わりと Sphinx わかってきた。
python
でデバッガがアタッチできるとなんでもできる(慣れ)。
[ ] tagの表記振れ
c++
と C++
、c#
と csharp
などをたばねる。
参考