Packages

A reusable static blog engine for Elixir. Generates a complete website from markdown with syntax highlighting, RSS, sitemap, SEO structured data, MarsEdit integration via Micropub/XML-RPC, and Cloudflare R2 publishing.

Current section

Files

Jump to
static_blog lib static_blog.ex
Raw

lib/static_blog.ex

defmodule StaticBlog do
@moduledoc """
A reusable static blog engine for Elixir.
`StaticBlog` provides the core infrastructure for building, previewing,
and publishing a static blog. Each consumer project adds this library as
a dependency, supplies its own content in `priv/posts/`, and configures
site metadata under the `:static_blog` application key.
The primary public API is `site_config/0`, `consumer_app/0`,
`template_module/0`, and `all_posts/0`.
"""
@doc """
Returns the consumer application atom.
This is the OTP application that owns the `priv/posts/` and
`priv/static/` directories. Configured via
`config :static_blog, :app, :my_blog`.
### Returns
* The consumer app atom from `config :static_blog, :app`.
"""
@spec consumer_app() :: atom()
def consumer_app do
Application.fetch_env!(:static_blog, :app)
end
@doc """
Returns the site configuration keyword list.
### Returns
* A keyword list of site-wide settings from `config :static_blog, :site`.
"""
@spec site_config() :: keyword()
def site_config do
Application.fetch_env!(:static_blog, :site)
end
@doc """
Returns the template module to use for rendering.
Defaults to `StaticBlog.Template.Default` if not configured.
### Returns
* A module that implements `StaticBlog.Template`.
"""
@spec template_module() :: module()
def template_module do
Application.get_env(:static_blog, :template, StaticBlog.Template.Default)
end
@doc """
Returns all blog posts.
If a `:blog_module` is configured, delegates to that module's
`all_posts/0` function. Otherwise falls back to
`StaticBlog.RuntimePosts.all/0` which reads from disk at runtime.
### Returns
* A list of `t:StaticBlog.Post.t/0` structs sorted by `:date` descending.
"""
@spec all_posts() :: [StaticBlog.Post.t()]
def all_posts do
case Application.get_env(:static_blog, :blog_module) do
nil -> StaticBlog.RuntimePosts.all()
module -> module.all_posts()
end
end
end