Hashimoto   Baku

Hashimoto   Baku

garden.oooのページスキーマ

garden.oooのページのデータモデルについて。型定義は types/page.ts、RxDB スキーマは utils/rxdb/pageSchema.ts にある。

Page インターフェース

Page は frontmatter の情報に加えて、パース済みの本文やアウトリンクを含む完全なページデータ。

主なフィールド:

  • path — ファイルパス(拡張子なし)
  • slug — 正規化済みの識別子(→ information-architecture.md
  • content_id — ULID。リネーム追跡用の不変 ID
  • body — パース済みの本文 AST(MDCRoot、en/ja の多言語対応)
  • source — Markdown のソースコード(非 admin には非公開)
  • outlinks — このページから出ている内部リンクの配列
  • uncreated — 赤ページかどうか(実体がなく、バックリンクのみで存在するページ)

Frontmatter

YAML frontmatter のスキーマは Zod で定義している(FrontmatterSchema)。Obsidian 互換を意識したフォーマット。

content_id: 01HQ3K5P0G3Z1VXYZ2ABC3DEF
title: Hello World
title_locale:
  ja: こんにちは、世界!
created: 2025-08-20
modified: 2025-08-21
visibility: public
archival: true
layout: grid
sort_by: modified
sort_order: desc
tags:
  - video
  - diary
description: A sample page
thumbnail: https://example.com/image.jpg

主なフィールド:

  • content_id — ULID。省略時は自動生成
  • title — 文字列、または {en, ja} のオブジェクト
  • created / modified — ISO 8601 の日付または日時
  • visibility'public' / 'unlisted' / 'protected' / 'private'(→ information-architecture.md
  • archival — 永続化フラグ。特定のタグやレイアウトで自動推定される
  • layout'page'(デフォルト)/ 'grid' / 'table'
  • sort_by / sort_ordergrid / table レイアウトでのバックリンク表示順
  • tags — tag link の配列。slug に正規化されて outlinks に変換される
  • aliases — ページの別名(リダイレクト用)
  • redirect — 別ページへの転送

ページから出ていくリンクの型。

interface Link {
  type: 'tag' | 'folder' | 'link'
  slug: string
  hash?: string
}
  • tag — frontmatter の tags から生成
  • folder — パスの親ディレクトリから暗黙的に生成
  • link — 本文中のハイパーリンクから生成

RxDB スキーマ

DB 上では PageDoc = {id: string, content: Omit<Page, 'uncreated'>} の形で保存される。uncreated は実行時に導出されるフィールドなので DB には含まれない。

contentadditionalProperties: true にしている。MDC の AST のような複雑なデータを RxDB の JSON Schema で完全にモデル化するのは現実的でないので。

主なインデックス:

  • content.content_id
  • content.path
  • content.slug
  • content.created
  • content.modified
  • content.visibility.type

slug の重複チェックは upsertPage メソッド内で行っている。同じ slug で異なる content_id のドキュメントが既にあれば DuplicateSlugError を投げる。