8 releases

new 0.3.2 Jun 5, 2024
0.3.1 Jun 5, 2024
0.2.2 Jun 3, 2024
0.2.1 May 14, 2024
0.1.1 May 13, 2024

#39 in Template engine

Download history 230/week @ 2024-05-08 70/week @ 2024-05-15 9/week @ 2024-05-22 140/week @ 2024-05-29

449 downloads per month

ISC license

26KB
465 lines

Sigen   builds.sr.ht Status

Sigen is a simple static site generator that allows complete control over the generated result. Everything is build around using handlebars template files to generate output.

Usage

Usage: sigen [OPTIONS]

Options:
  -i, --input <INPUT>    source folder location [default: ./]
  -o, --output <OUTPUT>  output folder location [default: ./output]
  -w, --watch            Watch files and regenerate on change
  -h, --help             Print help
  -V, --version          Print version

This generator works using the following folder structure:

example/
├── data/
│  └── file.yaml
├── markdown/
│  ├── test.md
│  └── test2.md
├── static/
│  └── style.css
└── templates/
   ├── base.part
   ├── index.hbs
   └── markdown.hbs

Which generates the following output:

output/
├── content/
│  ├── test.html
│  └── test2.html
├── index.html
├── markdown.html
└── static/
   └── style.css
  • data

In the data folder you can place yaml files with data that will be passed to the templates. The files will be parsed and added to a user_data object with the filename as identifier. To use data in the file example, you would use {{user_data.example.xxx}}.

  • markdown

All markdown files (.md) in this folder will be rendered to html and placed in output/content/. Sigen supports yaml metadata field is the markdown files. Using the metadata the generated output can be influenced. You are free to add any field you like, this data will be passed to the renderer as a variable content. There are some fields that directly impact the renderer:

  • renderer: When the markdown html is generated the output will be rendered using the configured render file found in the templates folder.
  • datetime: When give, as a iso8601 formated string, the markdown files will be ordered according to this date. Markdown files without this field will get the timestamp of the current UTC.

If the markdown file contains a metadata field renderer then the markdown file html will be parsed with the specified render template. The html output from the markdown renderer will be passed as a variable content to the template. All other markdown metadata fields will be stored in a data object and passed to the template renderer.

  • static

This folder will be copied recursively to the output folder.

  • templates

All template files are rendered using handlebars, files with a .part extension will be registers as a partial. All hbs files will be rendered to html and have access to the partials and markdown file info. Partials will have the same name as their filename, without the extension.

All templates are passed the following json:

{
   "markdown_files":[
      {
         "name":"",
         "datetime": "",
         "data": {}
      }
      ...
   ],
   "user_data": {},
   "git": {
      "branch":"",
      "rev_short":"",
      "rev":""
   }
}

Helpers

Helper functions extending the handlebars renderer.

  • (format_datetime <datatime> <format>): Format datetime strings. Look here for formatting options.
  • All the handlebars crate helpers

Dependencies

~13–25MB
~378K SLoC