Skip to main content

Module category

Module category 

Source
Expand description

Categories & taxonomies — hierarchical categorization, built the same way pages are: real migration-tracked models, not a JSON blob or a config file.

  • model::Category (cms_category) is the abstract base row — a materialized-path tree with typed columns (name, description, featured image, thumbnail, parent). Every vocabulary shares it.
  • model::Taxonomy (cms_taxonomy) is the vocabulary registry, mirroring cms_page_type: one row per vocabulary, synced from the TaxonomyHandler inventory at seed (upsert_taxonomy). The DB rows are the runtime source of truth (taxonomies).
  • assign::PageCategory (cms_page_category) files pages under categories.

A custom vocabulary is registered in code exactly like a custom page type: implement TaxonomyHandler + register_taxonomy!(T). Extra typed fields (a country’s flag + ISO code) live in the handler’s own per-type extension table (unique category_id FK) — the error_pages/page-type extension pattern. The built-in category vocabulary ships with only the base columns.

The tables are created by a migration (0005_categories.json, generated via cargo run --example gen_migration), not runtime ensure_table — so they are tracked exactly like cms_page.

Re-exports§

pub use assign::PageCategory;
pub use model::Category;
pub use model::CategoryError;
pub use model::CategoryNode;
pub use model::NewCategory;
pub use model::Taxonomy;
pub use model::DEFAULT_MAX_DEPTH;

Modules§

assign
Page ↔ category assignments — the cms_page_category M2M, mirroring crate::page_snippet_m2m / crate::page_tag. A page can be filed under many categories across many vocabularies; the join row denormalizes taxonomy_id so the editor can replace one vocabulary’s assignments without touching the others.
model
Category models — real, migration-tracked tables (not a JSON blob). Two models:

Structs§

CategoryTaxonomy
The built-in hierarchical category vocabulary shipped with every tenant. Base columns only — name, description, featured image, thumbnail, parent. The flat page_tag story stays the tags vocabulary.
TaxonomyHandlerRegistration
Inventory registration for a TaxonomyHandler (mirrors PageTypeHandlerRegistration). Populated by register_taxonomy!.

Traits§

TaxonomyHandler
A code-registered vocabulary. Mirrors PageTypeHandler: process-global, zero-arg constructible via the register_taxonomy! factory. The definition is synced into a cms_taxonomy row at seed; the optional extension hooks back a custom typed-field table.

Functions§

find_handler
The code handler for slug (for the extension hooks).
find_taxonomy
The cms_taxonomy row for slug, if seeded.
registered_handlers
Every code-registered vocabulary handler in the binary.
taxonomies
Every registered vocabulary, from the DB (the runtime source of truth, seeded from handlers), ordered by slug.
upsert_taxonomy
Sync a cms_taxonomy row from a registered handler — find-or-create keyed on the natural key slug, mirroring upsert_page_type (seed.rs). Called per-tenant at seed.