Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lustre-labs/ssg
https://github.com/lustre-labs/ssg
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/lustre-labs/ssg
- Owner: lustre-labs
- Created: 2023-09-17T08:46:59.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-26T20:10:00.000Z (3 months ago)
- Last Synced: 2024-11-20T16:28:49.756Z (22 days ago)
- Language: Gleam
- Size: 79.1 KB
- Stars: 62
- Watchers: 2
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
- awesome-gleam - lustre_ssg - [📚](https://hexdocs.pm/lustre_ssg/) - A simple static site generator for Lustre projects. (Packages / Websites)
README
# lustre_ssg
[![Package Version](https://img.shields.io/hexpm/v/lustre_ssg)](https://hex.pm/packages/lustre_ssg)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/lustre_ssg/)A simple static site generator for [Lustre](https://github.com/lustre-labs/lustre)
projects, written in pure Gleam. `lustre_ssg` will run on both Gleam's Erlang and
JavaScript targets. If you're using the JavaScript target, `lustre_ssg` is tested
to work on both Node.js and Deno!## What it is
`lustre_ssg` is a low-config static site generator for simple things like a
personal blog or documentation site. Declare your routes, tell `lustre_ssg` how
to render them, and it will spit out a bunch of HTML files for you.## What it is not
`lustre_ssg` is not a batteries-included framework for generating static sites.
There is no CLI, no built-in server, no fancy data fetching, and no client-side
hydration. If you need those things, you will have to build them yourself!## Usage
1. Add `lustre_ssg` as a development dependency to your Gleam project:
```sh
$ gleam add lustre_ssg --dev
```2. Create a `build.gleam` file in your project's `src` directory.
3. Import `lustre/ssg` and configure your routes:
```gleam
import gleam/list
import gleam/map
import gleam/io// Some data for your site
import app/data/posts// Some functions for rendering pages
import app/page/index
import app/page/blog
import app/page/post// Import the static site generator
import lustre/ssgpub fn main() {
let posts = map.from_list({
use post <- list.map(posts.all())
#(post.id, post)
})let build = ssg.new("./priv")
|> ssg.add_static_route("/", index.view())
|> ssg.add_static_route("/blog", blog.view(posts.all()))
|> ssg.add_dynamic_route("/blog", posts, post.view)
|> ssg.buildcase build {
Ok(_) -> io.println("Build succeeded!")
Error(e) -> {
io.debug(e)
io.println("Build failed!")
}
}
}
```4. Run the build script to generate your static site!
```sh
$ gleam run -m build
``````sh
$ tree privpriv
├── blog
│ ├── wibble.html
│ ├── wobble.html
│ └── ...
├── blog.html
└── index.html
```