Packages
arctic
11.0.0
11.0.10
11.0.9
11.0.8
11.0.7
11.0.6
11.0.6-z6
11.0.6-z5
11.0.6-z4
11.0.6-z3
11.0.6-z2
11.0.6-z1
11.0.6-gamma
11.0.6-delta
11.0.6-beta
11.0.6-alpha
11.0.5
11.0.4
11.0.3
11.0.2
11.0.1
11.0.0
11.0.0-alpha5
11.0.0-alpha4
11.0.0-alpha3
11.0.0-alpha2
11.0.0-alpha
10.0.1
10.0.0
10.0.0-alpha2
10.0.0-alpha
9.0.5
9.0.4
9.0.3
9.0.2
9.0.0
8.0.0
7.0.0
6.0.0
5.0.0
4.0.0
3.0.0
2.0.0
1.0.1
1.0.0
A friendly web framework for fast response times and a lightweight or serverless backend, written in Gleam!
Current section
Files
Jump to
Current section
Files
src/arctic/page.gleam
import arctic.{type Page, Page}
import birl.{type Time}
import gleam/dict.{type Dict}
import gleam/option.{None, Some}
import lustre/element.{type Element}
/// Construct a new page, with the given ID and default-everything.
pub fn new(id: String) -> Page {
Page(
id: id,
body: [],
metadata: dict.new(),
title: "",
blerb: "",
tags: [],
date: None,
)
}
/// Add a "body" to a page.
/// A body is the list of elements that will appear when the page is loaded.
pub fn with_body(p: Page, body: List(Element(Nil))) -> Page {
Page(..p, body:)
}
/// Add some metadata to a page.
/// This is any string key and value, that you can look up during parsing later.
/// Sorry for the lack of type safety!
/// Processing mismatches are handled with `snag` results,
/// which is like compile-time errors since the run-time is at build-time.
/// Also, note that some metadata gets privileged fields store in a different way,
/// like `.date`. This adds type safety and convenience, and is opt-in.
pub fn with_metadata(p: Page, key: String, val: String) -> Page {
Page(..p, metadata: dict.insert(p.metadata, key, val))
}
/// Swap out the entirety of the metadata for a page with a new dictionary,
/// except for the privileged metadata like `.title` and `.date`.
/// This is useful for if you're building a metadata dictionary programmatically.
pub fn replace_metadata(p: Page, metadata: Dict(String, String)) -> Page {
Page(..p, metadata:)
}
/// Add a title to a page.
pub fn with_title(p: Page, title: String) -> Page {
Page(..p, title:)
}
/// Add a blerb (description, whatever) to a page.
/// This is useful for nice thumbnails.
pub fn with_blerb(p: Page, blerb: String) -> Page {
Page(..p, blerb:)
}
/// Add tags to a page.
/// This is useful for implementing a helpful search.
pub fn with_tags(p: Page, tags: List(String)) -> Page {
Page(..p, tags:)
}
/// Add a date to a page.
/// This is useful for sorting pages by date in a list,
/// like in a blog.
pub fn with_date(p: Page, date: Time) -> Page {
Page(..p, date: Some(date))
}