Packages
arctic
11.0.2
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/config.gleam
import arctic.{
type Collection, type Config, type ProcessedCollection, Config, RawPage,
}
import lustre/element.{type Element, text}
import lustre/element/html
import gleam/option.{Some, None}
/// Produce a new Arctic configuration, with default settings.
/// An Arctic configuration holds all the collections, pages, parsing rules, etc.
pub fn new() -> Config {
Config(
render_home: fn(_) {
html.html([], [
html.head([], []),
html.body([], [text("No renderer set up for home page")]),
])
},
main_pages: [],
collections: [],
render_spa: Some(fn(body) { body })
)
}
/// Set the renderer for the home page of a site (`/index.html`).
/// Note that a list of all collections, with all of their pages, is provided if you'd like to use it.
pub fn home_renderer(
config: Config,
renderer: fn(List(ProcessedCollection)) -> Element(Nil),
) {
Config(..config, render_home: renderer)
}
/// Add a "main page" to an Arctic configuration.
/// Main pages are pages that aren't a part of any collection, like "Contact" or "About."
/// Note that the home page (`/index.html`) is handled via `home_renderer` instead.
pub fn add_main_page(config: Config, id: String, body: Element(Nil)) {
Config(..config, main_pages: [RawPage(id, body), ..config.main_pages])
}
/// Add a "collection" to an Arctic configuration.
/// A collection holds a bunch of pages and their processing rules,
/// like a set of products, blog posts, wiki entries, etc.
/// See `arctic/collection` for more.
pub fn add_collection(config: Config, collection: Collection) {
Config(..config, collections: [collection, ..config.collections])
}
/// Specify code that is on the outside of a page,
/// and doesn't get re-rendered on page navigation.
/// This can be nav bars, a `head` element, side panels, footer, etc.
pub fn add_spa_frame(config: Config, frame: fn(Element(Nil))->Element(Nil)) {
Config(..config, render_spa: Some(frame))
}
/// Generate the site as a directory of files,
/// instead of as a single-page app with clever routing.
pub fn turn_off_spa(config: Config) {
Config(..config, render_spa: None)
}