niki-til

til の分類をビルドする — directory → JSON パイプライン

> TL;DR (EN): This til's two-tier taxonomy is generated, not hand-maintained. seo/scripts/build-articles-tree.mjs walks the five division directories recursively, derives category from the top path segment and subcategory from the second, reads front matter, and writes _data/articles.json (flat list + tree_by_subcat + orphans) and _data/taxonomy.json (fixed categories/subcategories with counts + tags). The fixed vocabulary lives in code (CATEGORIES_META / SUBCATEGORIES_META); anything outside it is flagged as an orphan. Depth below subcategory is not a fixed tier — it's expressed by tags (facets) and parent (article threads). Hard-won gotchas: unquoted YAML arrays char-split into junk tags; restructuring directories changes URLs; git mv preserves history.

分類の再設計をしたとき、「カテゴリは3箇所で同期が要る」ことに気づいた:①ディレクトリ名、②ビルドスクリプトの定義、③README の表。これを正しく回す設計をメモしておく。

パイプラインの全体像

<division>/<subcategory>/<slug>.md   (front matter: category / subcategory / tags / parent)
        │
        ▼  node seo/scripts/build-articles-tree.mjs
        │
   _data/articles.json   … flat list + tree_by_category + tree_by_subcat + orphans
   _data/taxonomy.json   … categories(固定) × subcategories(固定) + counts + tags
        │
        ▼  Jekyll (GitHub Pages)
   README.md の Liquid が JSON を読んで一覧を描画

設計の要点

ハマったところ(再発防止)

運用

新規ノートは <division>/<subcategory>/<slug>.md に置き、front matter に category/subcategory/tags/parent を埋め、node seo/scripts/build-articles-tree.mjs を回して orphans: 0 を確認 → commit → push で GitHub Pages が自動再ビルド。

参考・引用元