PhoenixKit.Modules.Pages.Renderer (phoenix_kit v1.7.71)

Copy Markdown View Source

Renders blog post markdown to HTML with caching support.

Uses PhoenixKit.Cache for performance optimization of markdown rendering. Cache keys include content hashes for automatic invalidation.

Summary

Functions

Clears all blog post caches.

Clears the render cache for a specific blog.

Returns whether the global render cache is enabled. Checks new key first, falls back to legacy key.

Returns whether render cache is enabled for a specific group. Does not check the global setting. Checks new key first, falls back to legacy key.

Invalidates cache for a specific post.

Returns the settings key for per-group render cache. Used by other modules that need to write to the setting.

Returns whether render caching is enabled for a blog.

Renders markdown or .phk content directly without caching.

Renders a post's markdown content to HTML.

Functions

clear_all_cache()

Clears all blog post caches.

Useful for testing or when doing bulk updates.

clear_group_cache(group_slug)

@spec clear_group_cache(String.t()) :: {:ok, non_neg_integer()} | {:error, any()}

Clears the render cache for a specific blog.

Returns {:ok, count} with the number of entries cleared.

Examples

Renderer.clear_group_cache("my-group")
# => {:ok, 15}

global_render_cache_enabled?()

@spec global_render_cache_enabled?() :: boolean()

Returns whether the global render cache is enabled. Checks new key first, falls back to legacy key.

group_render_cache_enabled?(group_slug)

@spec group_render_cache_enabled?(String.t()) :: boolean()

Returns whether render cache is enabled for a specific group. Does not check the global setting. Checks new key first, falls back to legacy key.

invalidate_cache(blog_slug, identifier, language)

Invalidates cache for a specific post.

Called when a post is updated in the admin editor.

Examples

Renderer.invalidate_cache("docs", "getting-started", "en")

per_group_cache_key(group_slug)

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

Returns the settings key for per-group render cache. Used by other modules that need to write to the setting.

render_cache_enabled?(blog_slug)

@spec render_cache_enabled?(String.t()) :: boolean()

Returns whether render caching is enabled for a blog.

Checks both the global setting and per-blog setting. Both must be enabled (or default to enabled) for caching to work. Checks new keys first, falls back to legacy keys.

render_markdown(content)

Renders markdown or .phk content directly without caching.

Automatically detects .phk XML format and routes to PageBuilder. Falls back to Earmark markdown rendering for non-XML content.

Examples

html = Renderer.render_markdown(content)

render_post(post)

Renders a post's markdown content to HTML.

Caches the result for published posts using content-hash-based keys. Lazy-loads cache (only caches after first render).

Respects pages_render_cache_enabled (global) and pages_render_cache_enabled_{blog_slug} (per-blog) settings.

Examples

{:ok, html} = Renderer.render_post(post)