PhoenixKit.Modules.Publishing.Web.HTML (phoenix_kit v1.7.71)

Copy Markdown View Source

HTML rendering functions for Publishing.Web.Controller.

Summary

Functions

Pre-computes date counts for timestamp-mode posts to avoid per-post DB queries.

Builds a post URL based on mode. When multiple languages are enabled, always includes locale prefix. When languages module is off or only one language, uses clean URLs.

Builds a public path with explicit date and time (always includes time). Used when redirecting from date-only URLs to full timestamp URLs.

Builds language data for the publishing_language_switcher component on public pages. Converts the @translations assign to the format expected by the component.

Extracts and renders an excerpt from post content. Returns content before <!-- more --> tag, or first paragraph if no tag. Renders markdown and strips HTML tags for plain text display.

Resolves a featured image URL for a post, falling back to the original variant.

Formats a date for display using locale-aware month names.

Formats a date for URL.

Formats a date with time for display. Used when multiple posts exist on the same date.

Formats a post's publication date, including time only when multiple posts exist on the same date.

Formats time for URL (HH:MM).

Builds the public URL for a group listing page. When multiple languages are enabled, always includes locale prefix. When languages module is off or only one language, uses clean URLs.

Checks if a post has a publication date to display. For timestamp mode, the date comes from the directory structure. For slug mode, it comes from metadata.published_at.

Pluralizes a word based on count.

Functions

all_groups(assigns)

build_date_counts(posts)

Pre-computes date counts for timestamp-mode posts to avoid per-post DB queries.

Returns a map of %{date_string => count} for use with build_post_url/4 and format_post_date/3.

build_post_url(group_slug, post, language, date_counts \\ nil)

Builds a post URL based on mode. When multiple languages are enabled, always includes locale prefix. When languages module is off or only one language, uses clean URLs.

For slug mode posts, uses the language-specific URL slug (from post.url_slug or post.language_slugs[language]) for SEO-friendly localized URLs.

For timestamp mode posts:

  • If only one post exists on the date, uses date-only URL (e.g., /group/2025-12-09)
  • If multiple posts exist on the date, includes time (e.g., /group/2025-12-09/16:26)

build_public_path_with_time(language, group_slug, date, time)

Builds a public path with explicit date and time (always includes time). Used when redirecting from date-only URLs to full timestamp URLs.

build_public_translations(translations, current_language)

Builds language data for the publishing_language_switcher component on public pages. Converts the @translations assign to the format expected by the component.

extract_excerpt(content)

Extracts and renders an excerpt from post content. Returns content before <!-- more --> tag, or first paragraph if no tag. Renders markdown and strips HTML tags for plain text display.

format_date(datetime)

Formats a date for display using locale-aware month names.

format_date_for_url(datetime)

Formats a date for URL.

format_date_with_time(datetime)

Formats a date with time for display. Used when multiple posts exist on the same date.

format_post_date(post, group_slug, date_counts \\ nil)

Formats a post's publication date, including time only when multiple posts exist on the same date.

format_time_for_url(datetime)

Formats time for URL (HH:MM).

group_listing_path(language, group_slug, params \\ [])

Builds the public URL for a group listing page. When multiple languages are enabled, always includes locale prefix. When languages module is off or only one language, uses clean URLs.

has_publication_date?(post)

Checks if a post has a publication date to display. For timestamp mode, the date comes from the directory structure. For slug mode, it comes from metadata.published_at.

index(assigns)

pluralize(count, singular, plural)

Pluralizes a word based on count.

show(assigns)