Giter Club home page Giter Club logo

ssg's Introduction

lustre_ssg

Package Version Hex Docs

A simple static site generator for 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:
$ gleam add lustre_ssg --dev
  1. Create a build.gleam file in your project's src directory.

  2. Import lustre/ssg and configure your routes:

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/ssg

pub 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.build

  case build {
    Ok(_) -> io.println("Build succeeded!")
    Error(e) -> {
      io.debug(e)
      io.println("Build failed!")
    }
  }
}
  1. Run the build script to generate your static site!
$ gleam run -m build
$ tree priv

priv
├── blog
│   ├── wibble.html
│   ├── wobble.html
│   └── ...
├── blog.html
└── index.html

ssg's People

Contributors

hayleigh-dot-dev avatar giacomocavalieri avatar okkdev avatar brzezinskip avatar daniellemaywood avatar nicd avatar tanklesxl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.