libssg

Crates.iolibssg
lib.rslibssg
version0.1.1
sourcesrc
created_at2020-02-11 17:26:02.393126
updated_at2020-02-11 21:59:08.132801
descriptionstatic site generation library
homepage
repositoryhttps://github.com/epilys/libssg
max_upload_size
id207396
size98,655
Manos Pitsidianakis (epilys)

documentation

README

libssg

static site generation library

Build your own executable static generator that includes your building logic instead of using configuration files and command line arguments. Inspired by Hakyll.

use libssg::*;
/*
 * $ tree
 * .
 * ├── Cargo.toml etc
 * ├── src
 * │   └── main.rs
 * ├── css
 * │   └── *.css
 * ├── images
 * │   └── *.png
 * ├── index.md
 * ├── posts
 * │   └── *.md
 * ├── _site
 * │   ├── css
 * │   │   └── *.css
 * │   ├── images
 * │   │   └── *.png
 * │   ├── index.html
 * │   ├── posts
 * │   │   └── *.html
 * │   └── rss.xml
 * └── templates
 *     ├── default.hbs
 *     └── post.hbs
*/


fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut state = State::new()?;
    state
        .then(match_pattern(
            "^posts/*",
            Route::SetExtension("html"),
               Renderer::Pipeline(vec![
                   Renderer::LoadAndApplyTemplate("templates/post.hbs"),
                   Renderer::LoadAndApplyTemplate("templates/default.hbs"),
               ]),
            compiler_seq(
                pandoc(),
                Box::new(|state, path| {
                    let path = path
                        .strip_prefix(&state.output_dir().parent().unwrap())
                        .unwrap_or(&path)
                        .to_path_buf();
                    if state.verbosity() > 3 {
                        println!("adding {} to RSS snapshot", path.display());
                    }
                    let uuid = uuid_from_path(&path);
                    state.add_to_snapshot("main-rss-feed".into(), uuid);
                    Ok(Default::default())
                }),
            ),
        ))
        .then(match_pattern(
            "index.md",
            Route::SetExtension("html"),
            Renderer::LoadAndApplyTemplate("templates/default.hbs"),
            pandoc(),
        ))
        .then(copy("^images/*", Route::Id))
        .then(copy("^css/*", Route::Id))
        .then(build_rss_feed(
            "rss.xml".into(),
            rss_feed(
                "main-rss-feed".into(),
                RssItem {
                    title: "example page".into(),
                    description: "example using libssg".into(),
                    link: "http://example.local".into(),
                    last_build_date: String::new(),
                    pub_date: "Thu, 01 Jan 1970 00:00:00 +0000".to_string(),
                    ttl: 1800,
                },
            ),
        ))
        .finish()?;
    Ok(())
}

cargo run and the output is saved at ./_site/.

Set $FORCE, $VERBOSITY (0..5) to change behaviour.

Commit count: 9

cargo fmt