Bagatto

A transparent, extensible static site generator

bagatto API

bagatto

%p, *, attr-sorter, datestr->date, datestr->secs, epp, format, get-default, glob, include, item-getter, jdn-data, json-data, markdown->html, parse-base, parse-jdn, parse-json, parse-mago, path-copier, render, renderer, set-defaults!, set-output-dir!, sh/$<, sh/glob, site-getter, slug-from-attr, slugify, slurp-*

%p

function | source

(%p & elements)

Simple DSL for generating paths.

Given any number of string or keyword arguments, will return a function that takes an item and returns a file path.

The arguments make up the components of the path. To include an element directly in the path, put it as an argument. To indicate that an element should be treated as a key in site, precede it by a '%s. To indicate that an element should be treated as a key in item, precede it by a '%i. To join two elements directly, without a path separator, put a '% between them. For instance,

repl:9:> (def f (bagatto/%p "site" '%s "author" '%i :title '% ".html"))
<function 0x55F38B3B3880>
repl:10:> (f {"author" "Z. D. Smith"} {:title "My first post"})
"site/z-d-smith/my-first-post.html"
repl:11:> (f {"author" "Z. D. Smith"} {:title "My second post"})
"site/z-d-smith/my-second-post.html"

*

function | source

(* pattern)

Generate a function that will return all the filenames that match a given file blob.

attr-sorter

function | source

(attr-sorter key &opt descending?)

Return a sorter function that, given a list of items, sorts according to the items’ values at the specified key.

datestr->date

function | source

(datestr->date datestr &opt for-display?)

Given a string representation of a date or datetime, return a struct of the kind returned by os/date. Pass a truthy value in the second argument to adjust for human display (setting values like day and month to be 1-indexed).

datestr->secs

function | source

(datestr->secs datestr)

Given a string representation of a date or datetime, return the epoch seconds value for that date.

epp

function | source

(epp x)

Pretty-print to stderr. Since Temple templates operate over stdout, we should use stderr instead if we need to print something to the console for debugging purposes.

format

function | source

(format templ & xs)

A simple wrapper around string/format to ease development. If one of xs is nil, it will output an empty string rather than crashing the template.

get-default

function | source

(get-default attribute)

Get the value set in the bagatto defaults for the specified key. Can be used for a simple form of inheritence; if you have a default callback or value set, and you have some specific handler that needs to build on top of that functionality, you can call bagatto/get-default to get or evaluate it inside of the handler and then implement your more specific logic.

(see bagatto/set-defaults! for more information.)

glob

function | source

(glob pattern)

include

macro | source

(include template)

Require and render the named template.

In addition to being a convenient wrapper around

{$ (import foo) $}
{% (foo/render-dict args) %}

include will update the error-tracking context with the name of the included template. This makes it much easier to trace rendering errors in nested templates.

item-getter

function | source

(item-getter path)

Return a function that, given site and item data, gets the value at the given path in the item.

The path should be a tuple of keys, eg.: [:user :full-name].

jdn-data

function | source

(jdn-data src)

Get metadata from a JDN-formatted string.

json-data

function | source

(json-data src)

Get metadata from a JSON-formatted string.

markdown->html

function | source

(markdown->html md &keys {:exts exts :opts opts})

Render a markdown string into HTML.

parse-base

function | source

(parse-base _src attrs)

Base attribute parser: bypasses the input source and returns the default attributes that are provided for every file. These are:

parse-jdn

function | source

(parse-jdn src attrs)

Attribute parser for JDN.

parse-json

function | source

(parse-json src attrs)

Attribute parser for JSON.

parse-mago

function | source

(parse-mago src attrs)

Attribute parser for Mago.

path-copier

function | source

(path-copier base &opt key)

Return a function that will generate a new path with the same base, from the same key, for any item.

eg.:

repl:2:> (def f (bagatto/path-copier "destination"))
<function 0x55F38B3AE640>
repl:3:> (f {} {:path "original/source/directory/filename.md"})
"destination/filename.md"
repl:4:> (f {} {:path "original/source/directory/newfile.png"})
"destination/newfile.png"

render

function | source

(render template site &opt item)

Given site data and an optional item, render the specified Temple template.

All the attributes will be available in the template under args.

If a single item was passed in in addition to the site, that item will be available at (args :_item).

In addition to the standard Janet library, the same additional libraries that Bagatto makes available when writing an index module are also available (without explicitly importing them) from within a template.

See the Temple site for more details.

renderer

function | source

(renderer template-path &opt extra-attrs)

Return a function, given a template and optional extra attributes, that will call render with that template on any input.

(see bagatto/render for more details.)

set-defaults!

function | source

(set-defaults! defaults)

Set the defaults for the values specified in data and site specifications. For instance, setting the default of :attrs to bagatto/parse-json will attempt to set the attributes for any file by parsing it as JSON. :attrs could still be set on any entry in the data spec in order to override the default.

set-output-dir!

function | source

(set-output-dir! dir)

Name a directory for all produced files to be placed. For instance,

(bagatto/set-output-dir! "site") will place your generated file hierarchy in a directory called site.

sh/$<

macro | source

(sh/$< & _)

sh/glob

macro | source

(sh/glob &)

site-getter

function | source

(site-getter path)

Return a function that, given site data or site and item data, gets the value at the given path in the site.

The path should be a tuple of keys, eg.: [:blog :description].

slug-from-attr

function | source

(slug-from-attr item key)

Given an object and a key, get the value of that key in the object it make the value into a slug.

(see bagatto/slugify for more details.)

slugify

function | source

(slugify s)

Normalize a string for use as a slug, eg., in a file path.

slurp-*

function | source

(slurp-* pattern)

Generate a function that will slurp all the files that match a given file blob.

repl

eval-data, eval-site, write-site

eval-data

function | source

(eval-data data)

Evaluate an object according to the Bagatto site data specification.

Not necessary to define a module, but can be useful to debug your configuration from within the REPL.

eval-site

function | source

(eval-site site data)

Evaluate an object according to the Bagatto site generation specification, given a site data object as context.

Not necessary to define a module, but can be useful to debug your configuration from within the REPL.

write-site

function | source

(write-site writer-specs output-dir)

Given the output of a site generation specification, trigger the actual file generation.

Not necessary to define a module, but can be useful to debug your configuration from within the REPL.