PhoenixKitWeb.Live.Modules.Blogging.Metadata (phoenix_kit v1.6.16)

View Source

Metadata helpers for .phk (PhoenixKit) blogging posts.

Metadata is stored as a simple key-value format at the top of the file:

---
slug: home
title: Welcome
status: published
published_at: 2025-10-29T18:48:00Z
---

Content goes here...

Summary

Functions

Returns default metadata for a new post.

Extracts title from markdown content. Looks for the first H1 heading (# Title) within the first few lines. Falls back to the first line if no H1 found.

Parses .phk content, extracting metadata from frontmatter and returning the content. Title is extracted from the markdown content itself (first H1 heading).

Serializes metadata as YAML-style frontmatter. Note: Title is NOT saved in frontmatter - it's extracted from content.

Types

metadata()

@type metadata() :: %{
  status: String.t(),
  title: String.t(),
  description: String.t() | nil,
  slug: String.t(),
  published_at: String.t(),
  featured_image_id: String.t() | nil,
  created_at: String.t() | nil,
  created_by_id: String.t() | nil,
  created_by_email: String.t() | nil,
  updated_by_id: String.t() | nil,
  updated_by_email: String.t() | nil
}

Functions

default_metadata()

@spec default_metadata() :: metadata()

Returns default metadata for a new post.

extract_title_from_content(content)

@spec extract_title_from_content(String.t()) :: String.t()

Extracts title from markdown content. Looks for the first H1 heading (# Title) within the first few lines. Falls back to the first line if no H1 found.

parse_with_content(content)

@spec parse_with_content(String.t()) ::
  {:ok, metadata(), String.t()} | {:error, atom()}

Parses .phk content, extracting metadata from frontmatter and returning the content. Title is extracted from the markdown content itself (first H1 heading).

serialize(metadata)

@spec serialize(metadata()) :: String.t()

Serializes metadata as YAML-style frontmatter. Note: Title is NOT saved in frontmatter - it's extracted from content.