Wraith. Content
(Wraith v0.1.0)
View Source
Posts and pages, their tags and revisions.
A post is a map: id, type ("post" | "page"), title, slug,
markdown, excerpt, status ("draft" | "scheduled" | "published"),
visibility ("public" | "members"), featured, tags (slugs),
author_id, published_at, feature_image, meta_title,
meta_description, sort_at.
Layout (see Wraith.Store.Keys): the post item sits on the index under
POSTS#<status> sorted by sort_at (published_at once published,
updated_at while a draft); a slug item makes slugs unique; published
posts also have one membership item per tag and one under their author,
so tag/author pages are a single query. Every save writes a revision.
publish_due/0 flips scheduled posts whose time has come; Wraith.Clock
calls it every minute.
Summary
Functions
A new draft. attrs may carry any post field; author_id is required.
Make sure a tag item exists for the slug (named after it unless told otherwise).
Is the post gated at all?
The post behind a preview token, whatever its status; nil when unknown.
A published post or page by slug — what the public may read.
Every post of every status for the admin list, newest activity first.
Posts of one status, newest first, paged. Options: type: ("post",
"page", default both), limit:, cursor:, featured: true.
Returns %{posts, next}.
Page n (1-based) of a cursor-paged listing. fetch is a function of
[limit:, cursor:] returning %{posts, next} (any of the listings
above); cursors are walked from the start, which is fine for a blog.
Returns %{posts, page, has_next}.
Published posts by an author, newest first.
Published posts carrying a tag, newest first.
A shareable preview link's token for post, minted on first ask and then
stable, so a reviewer who isn't staff can read a draft at /preview/<token>.
The token is random (128 bits) and never derived from the post.
Publish now; when the post asks for it, mail it too.
Scheduled posts whose time has come are published (and mailed when
send_on_publish); published posts past their unpublish_at go back to
draft. Returns how many changed.
Publish now (or at at, which schedules it).
The markdown a reader may see: the whole thing for public posts (and for a
reader with access), only the part above <!--members-only--> otherwise.
Every public-facing renderer — the page, feeds, the Content API, the search
index — goes through here, so the paywall has exactly one definition.
What the dashboard lists as recent activity: the newest n of each status
index, merged by updated_at. Bounded reads instead of every post. A draft
sorts by its last save, so drafts are exact; a published post edited long
after it went out is ranked by its publish date and may not make the cut
(the posts list, sorted by edit time, still has it).
Published posts sharing the most tags with this one (then the newest), up to n.
Revoke a post's preview link: the pointer is deleted and the post forgets the token.
Change fields on a post; the slug and the index items follow.
Words in the body, for the editor.
Functions
A new draft. attrs may carry any post field; author_id is required.
Make sure a tag item exists for the slug (named after it unless told otherwise).
Is the post gated at all?
The post behind a preview token, whatever its status; nil when unknown.
A published post or page by slug — what the public may read.
Every post of every status for the admin list, newest activity first.
Posts of one status, newest first, paged. Options: type: ("post",
"page", default both), limit:, cursor:, featured: true.
Returns %{posts, next}.
Page n (1-based) of a cursor-paged listing. fetch is a function of
[limit:, cursor:] returning %{posts, next} (any of the listings
above); cursors are walked from the start, which is fine for a blog.
Returns %{posts, page, has_next}.
Published posts by an author, newest first.
Published posts carrying a tag, newest first.
A shareable preview link's token for post, minted on first ask and then
stable, so a reviewer who isn't staff can read a draft at /preview/<token>.
The token is random (128 bits) and never derived from the post.
Publish now; when the post asks for it, mail it too.
Scheduled posts whose time has come are published (and mailed when
send_on_publish); published posts past their unpublish_at go back to
draft. Returns how many changed.
Publish now (or at at, which schedules it).
The markdown a reader may see: the whole thing for public posts (and for a
reader with access), only the part above <!--members-only--> otherwise.
Every public-facing renderer — the page, feeds, the Content API, the search
index — goes through here, so the paywall has exactly one definition.
access? is the caller's answer to Wraith.Members.can_read?/2 (or staff).
What the dashboard lists as recent activity: the newest n of each status
index, merged by updated_at. Bounded reads instead of every post. A draft
sorts by its last save, so drafts are exact; a published post edited long
after it went out is ranked by its publish date and may not make the cut
(the posts list, sorted by edit time, still has it).
@spec revoke_preview(map()) :: :ok
Revoke a post's preview link: the pointer is deleted and the post forgets the token.
Change fields on a post; the slug and the index items follow.
Words in the body, for the editor.