til/applied-sciences/engineering/til-taxonomy-build
til-taxonomy-build.mdupdated 2026-07-162990 words
ダブルクリックで英日反転
Applied Sciences · Engineering

Building til's Taxonomy — a Directory → JSON Pipeline

EN

The two-tier taxonomy of this TIL site is generated, not hand-maintained. A Node.js script walks five division directories, derives category and subcategory from the path, and emits two JSON data files consumed by Jekyll.

Pipeline at a glance

  • `build-articles-tree.mjs` walks `<division>/<subcategory>/<slug>.md` recursively
  • Outputs `_data/articles.json` (flat list + tree_by_subcat + orphans)
  • Outputs `_data/taxonomy.json` (fixed vocab + counts + tags)
  • Jekyll reads the JSON via Liquid to render the index

Key design decisions

  • Source of truth is code: `CATEGORIES_META` + `SUBCATEGORIES_META` are fixed in the script
  • category/subcategory derived from path segments; articles outside the vocab become orphans
  • Only two fixed tiers — deeper structure uses `parent` (threads) and tags (facets)
  • Empty categories kept as a permanent 'map of disciplines'

Hard-won gotchas

  • Unquoted YAML arrays (`[a, b]`) char-split into junk tags — always quote them
  • Restructuring directories changes URLs; update all in-site links and `parent` refs
  • Use `git mv` to move files and preserve blame history
  • On Windows, run the build via PowerShell — git-bash background forks are unstable

Adding a new note

  • Place file at `<division>/<subcategory>/<slug>.md`, fill front matter
  • Run `node seo/scripts/build-articles-tree.mjs`, confirm `orphans: 0`
  • Commit and push → GitHub Pages rebuilds automatically
Keep the fixed vocabulary in code, derive structure from the directory path, and make `orphans: 0` your green light before every commit.
Applied Sciences · Engineering

TILの​分類体系​(タクソノミー)を​ディレクトリ→JSONパイプラインで​自動生成する

JP

この​TILサイトの​二層分類体系は​手作業で​管理していない。​Node.jsスクリプトが​5つの​ディビジョン​(分野区分)​ディレクトリを​再帰的に​走査し、​カテゴリ・サブカテゴリを​パスから​導出して、​Jekyllが​Liquidで​読み込む​2つの​JSONファイルを​生成する。

パイプラインの​全体​像

  • `build-articles-tree.mjs`が​`<division>/<subcategory>/<slug>.md`を​再帰的に​走査
  • `_data/articles.json`​(フラットリスト+ツリー+orphans)を​出力
  • `_data/taxonomy.json`​(固定語彙+カウント+タグ)を​出力
  • Jekyllが​Liquid経由で​JSONを​読み込みインデックスを​描画

設計上の​重要な​決断

  • 正典​(ソース・オブ・トゥルース)は​コード:スクリプト内の​`CATEGORIES_META` / `SUBCATEGORIES_META`が​固定値
  • カテゴリ・サブカテゴリは​パスセグメントから​自動導出。​語彙外の​記事は​orphan​(孤立記事)と​して​検出
  • 固定階層は​2層まで。​それ以下の​構造は​`parent`​(記事スレッド)と​タグ​(ファセット)で​表現
  • エントリが​0件の​カテゴリも​残す——​「学問分野の​地図」と​して​恒久的に​保持

実際に​嵌った​落とし穴

  • YAMLの​配列を​引用符なしで​書くと​文字単位で​分割されて​ゴミタグが​大量生成される​——必ず引用符で​囲む
  • ディレクトリ構造を​変えると​URLが​変わる。​サイト内リンクと​`parent`参照を​すべて​追随させる​こと
  • `git mv`で​ファイルを​移動すると​リネームと​して​追跡され、​blameの​履歴が​失われない
  • Windowsでは​git-bashの​バック​グラウンドフォークが​不安定——ビルドは​PowerShellから​実行する

新しい​記事を​追加する​手順

  • `<division>/<subcategory>/<slug>.md`に​配置し、​フロントマターを​記入
  • `node seo/scripts/build-articles-tree.mjs`を​実行し`orphans: 0`を​確認
  • コミット&プッシュ → GitHub Pagesが​自動ビルド
固定語彙は​コードで​管理し、​構造は​ディレクトリパスから​導出する。​コミット前の​合格基準は​`orphans: 0`。
148 notestil