lustre/ssg
Types
The Config type tells lustre_ssg how to generate your site. It includes
things like the output directory and any routes you have configured.
The type parameters are used to track different facts about the configuration and prevent silly things from happening like building a site with no guaranteed routes.
pub opaque type Config(has_static_routes, has_static_dir)
This type is used to tag the Config through the different builder functions.
It indicates a configuration that has a static assets directory to copy.
pub type HasStaticDir
This type is used to tag the Config through the different builder functions.
It indicates a configuration that will generate least one static route.
pub type HasStaticRoutes
This type is used to tag the Config through the different builder functions.
It indicates a configuration that does not have a statica ssets directory to
copy.
pub type NoStaticDir
This type is used to tag the Config through the different builder functions.
It indicates a configuration that will not generate any static routes.
Your configuration must have at least one static route before it can be passed
to build. This is to prevent you from accidentally building a completely
empty site.
pub type NoStaticRoutes
Functions
pub fn add_dynamic_route(config: Config(a, b), path: String, data: Map(
String,
c,
), page: fn(c) -> Element(d)) -> Config(a, b)
Configure a map of dynamic routes to be generated. As with add_static_route
the base path should be the route that each page will be available at when
served by a HTTP server.
The initial path is the base for all dynamic routes to be generated. The
keys of the data map will be used to generate the dynamic routes. For
example, to generate dynamic routes for a blog where each page is a post
with the route “/blog/:post” you might do:
let posts = [
#("hello-world", Post(...)),
#("why-lustre-is-great", Post(...)),
]
...
ssg.config("./dist")
|> ...
|> ssg.add_dynamic_route("/blog", posts, render_post)
Paths are converted to kebab-case and lowercased. This means that the path “/Blog” will be available at “/blog” and and “/About me” will be available at “/about-me”.
pub fn add_static_dir(config: Config(a, NoStaticDir), path: String) -> Config(
a,
HasStaticDir,
)
pub fn add_static_route(config: Config(a, b), path: String, page: Element(
c,
)) -> Config(HasStaticRoutes, b)
Configure a static route to be generated. The path should be the route that the page will be available at when served by a HTTP server. For example the path “/blog” would be available at “https://your_site.com/blog”.
You need to add at least one static route before you can build your site. This is to prevent you from providing empty dynamic routes and accidentally building nothing.
Paths are converted to kebab-case and lowercased. This means that the path “/Blog” will be available at “/blog” and and “/About me” will be available at “/about-me”.
pub fn build(config: Config(HasStaticRoutes, a)) -> Nil
Generate the static site. This will delete the output directory if it already exists and then generate all of the routes configured. If a static assets directory has been configured, its contents will be recursively copied into the output directory.