StaticBlog.RuntimePosts (StaticBlog v0.2.0)

Copy Markdown View Source

Reads blog posts from disk at runtime.

When posts are created, updated, or deleted through the Micropub endpoint, the process is long-running and needs to see file-system changes immediately.

This module reads priv/posts/**/*.md from disk on every call, parses the frontmatter map and markdown body, and returns a list of StaticBlog.Post structs. There is no cache — each call re-reads.

Summary

Functions

Return all posts found under priv/posts/, sorted newest-first.

Load a single post by its slug.

Return the raw markdown body of the post with the given slug, without frontmatter.

Return the absolute path to the markdown file backing a given slug, or nil.

Return the absolute path to the priv/posts/ directory.

Functions

all()

@spec all() :: [StaticBlog.Post.t()]

Return all posts found under priv/posts/, sorted newest-first.

Returns

by_slug(slug)

@spec by_slug(String.t()) :: StaticBlog.Post.t() | nil

Load a single post by its slug.

Arguments

  • slug is the URL slug portion of the post filename.

Returns

markdown_body(slug)

@spec markdown_body(String.t()) :: String.t() | nil

Return the raw markdown body of the post with the given slug, without frontmatter.

Arguments

  • slug is the URL slug portion of the post filename.

Returns

  • The markdown body as a string, or nil if no post has that slug.

path_for_slug(slug)

@spec path_for_slug(String.t()) :: Path.t() | nil

Return the absolute path to the markdown file backing a given slug, or nil.

Arguments

  • slug is the URL slug portion of the post filename.

Returns

  • An absolute path string, or nil if no file exists for that slug.

posts_dir()

@spec posts_dir() :: Path.t()

Return the absolute path to the priv/posts/ directory.

Returns

  • An absolute path string.