Blog & Authors
Posts, authors, and categories with M2O/M2M relations
npx dkit add blog
Schema only: npx dkit add blog --schema-only · With sample data: npx dkit add blog --seed
Schema
Collections and fields from this module's snapshot.json (dkit.rest). Names below are logical; dkit add applies your collection prefix.
All relations
- posts.author → authors · on_delete SET NULL
- authors.avatar → directus_files · on_delete SET NULL
- posts.featured_image → directus_files · on_delete SET NULL
- posts_categories.posts_id → posts · on_delete CASCADE
- posts_categories.categories_id → categories · on_delete CASCADE
Access
- dkit Blog Public ReadPublic read for blog collections (flat rules — Core-compatible). UI filters published status.
- read → posts [*]
- read → authors [*]
- read → categories [*]
- read → posts_categories [*]
- read → directus_files [*]
Requires Directus 11+ (12.2+ recommended). Prefer a staging project before running dkit add against production.
Services
Fetch and write helpers installed as lib/dkit/blog.ts. Import from @/lib/dkit/blog. See Services.
function authorAvatarUrl(post: BlogPost): string | nullfunction authorName(post: BlogPost): string | nullfunction featuredImageUrl(post: BlogPost): string | nullasync function getBlogAuthorById(id: string): Promise<BlogAuthor | null>async function getBlogAuthorBySlug( slug: string, options: GetBlogBySlugOptions = {} ): Promise<BlogAuthor | null>Authors, by name.
async function getBlogAuthors(options: GetBlogAuthorsOptions = {}): Promise<BlogAuthor[]>Categories, by title.
async function getBlogCategories(options: GetBlogCategoriesOptions = {}): Promise<BlogCategory[]>async function getBlogCategoryById(id: string): Promise<BlogCategory | null>async function getBlogCategoryBySlug(slug: string): Promise<BlogCategory | null>async function getBlogPostById(id: string): Promise<BlogPost | null>async function getBlogPostBySlug( slug: string, options: GetBlogBySlugOptions = {} ): Promise<BlogPost | null>Posts, newest first.
async function getBlogPosts(options: GetBlogPostsOptions = {}): Promise<BlogPost[]>function normalizeCategories( raw: BlogPost["categories"] | JunctionCategory[] | null | undefined ): BlogCategory[]
Flows & seed
Optional Directus extras from services/. Flows apply on dkit add; seed only with --seed.
Seed
services/seed.json — import with npx dkit add blog --seedFiles
- Ada Lovelace avatar · ada-lovelace-avatar.png · image/png
- Hello from dkit cover · hello-from-dkit-cover.png · image/png
authors1 item
- Ada Lovelace
/ada-lovelacepublished
categories1 item
- Engineering
/engineering
posts2 items
- Sample post: getting started
/sample-getting-startedpublished - Sample post: modeling notes
/sample-modeling-notespublished
posts_categories2 items
- item
- item
UI preview
Preview data comes from the module seed — the same JSON as dkit add --seed.
blog-list
Stacked post list with optional thumbnails
blog-list-cards
Card grid of posts with date, excerpt, and hover accent
blog-detail
Article page with categories, byline, and rich text