BoxLang 🚀 A New JVM Dynamic Language Learn More...

BoxLang SSG

v1.1.0 BoxLang Modules

BoxLang SSG

A static site generator for BoxLang. Install it once as a BoxLang module, then run it in any folder that holds a site, the way you would use Hugo or Jekyll. Pages are written in Markdown (.md) or BoxLang markup (.bxm) with YAML front matter, and rendered through views and layouts into plain HTML that works on any static host.

  • Markdown and BoxLang markup pages with YAML front matter, plus per-folder front matter defaults
  • Layouts, views and partials in _includes/, helper functions in _includes/applicationHelper.bxm
  • Collections by type, by tag and by any front matter key you list, with excerpts and previous/next links
  • JSON, YAML and CSV data from _data/
  • Folder-style URLs (/posts/hello-world/), permalinks, permalink patterns per type and pagination
  • A baseUrl for sites served from a sub-path, with relUrl() and absUrl() helpers
  • serve rebuilds the site when a source file changes and reloads the browser; build --watch rebuilds without serving
  • new creates a post or page with its front matter filled in
  • A starter site with an Atom feed and a sitemap

Requires BoxLang 1.19.0 or later.

Install

install-bx-module boxlang-ssg bx-yaml bx-markdown bx-jsoup

install-bx-module installs only the modules you name; it does not read the dependencies declared in this module's box.json. That is why the three modules the generator needs (bx-yaml, bx-markdown, bx-jsoup) are listed explicitly. If one is missing, build and serve stop with exit code 2 and print the exact install-bx-module command to run.

Add --local to install into ./boxlang_modules/ of the current folder instead of the BoxLang home. BoxLang only finds locally installed modules when it runs from the folder that holds boxlang_modules/; see the quick start below.

CommandBox users can run box install boxlang-ssg instead. CommandBox installs boxlang-modules packages into the BoxLang home (~/.boxlang/modules/) and does install the declared dependencies.

Quick start

With the modules installed in the BoxLang home (the default, without --local):

boxlang module:ssg init my-site
cd my-site
boxlang module:ssg build
boxlang module:ssg serve

init copies the starter site into my-site/. build writes the site to my-site/_site/. serve builds, serves _site/ at http://localhost:8080/ and rebuilds when you change a file. Stop it with Ctrl-C.

If you installed with --local, stay in the folder that holds boxlang_modules/ and point each command at the site with --source; after cd my-site BoxLang no longer finds the module and fails with "module [ssg] does not exist":

boxlang module:ssg init my-site
boxlang module:ssg build --source my-site
boxlang module:ssg serve --source my-site

Commands and flags

Run commands as boxlang module:ssg <command> [options] from the site root, or pass --source.

Command What it does
init [dir] Copies the starter site into dir (default: the current directory). Refuses, with exit code 1, if dir/ssg-config.json already exists. Any other file already in dir is kept: init prints Skipped <file> (already exists) and copies the rest.
build Deletes outputDir and builds the whole site into it. With --watch, keeps running and rebuilds whenever the source changes.
serve Builds, serves outputDir with a built-in web server, checks the site for changes every second, rebuilds and reloads open pages in the browser.
list Prints the documents that would be built, relative to the site root.
clean Deletes outputDir.
new <title> Creates a Markdown document with its front matter filled in, by default posts/<title-slug>.md. See Creating documents.
help Prints usage. Running with no command prints usage too, but exits 1.
Flag Applies to Meaning
--source <dir> build, serve, list, clean, new Site root. Default: the current directory.
--verbose build Lists every file written.
--drafts build, serve Also builds drafts: documents with published: false, and posts (type: post) whose date is in the future. Without it, both are left out of the output and of every collection. Other document types are never skipped because of their date.
--port <n> serve Port to serve on. Default: 8080.
--watch build After building, checks the site for changes every second and rebuilds until you press Ctrl-C. Each rebuild prints its warnings and errors, if any, then a summary line (Rebuilt <n> files in <ms> ms, or Build failed with <n> error(s)); watching continues after a failed rebuild.
--no-reload serve Turns live reload off: pages are served exactly as built.
--type <type> new type written into the front matter: letters, digits, - and _ only (anything else is a usage error). Default: post.
--dir <dir> new Folder for the new file, relative to the site root, outside outputDir. Default: posts for type post, otherwise the site root.
--draft new Adds published: false.

--watch, --no-reload, --type, --dir and --draft are usage errors (exit code 1) on any other command.

Exit codes:

Code Meaning
0Success.
1Usage error: unknown command or option, a flag without its value or used with the wrong command, an invalid --port, a source directory that does not exist, init into a folder that already has ssg-config.json, or a new that is refused.
2Build failure: invalid configuration, a document that fails to parse or render, a required module that is missing, or a serve port that is already in use. Every failure is printed as <file>: <message>, with the file relative to the site root.

Problems found before rendering (configuration, front matter, folder defaults, data files, permalink patterns, pagination, two documents writing the same file, a missing passthru entry) stop the build before anything is written or deleted. A page that fails to render is not written; the other pages are, and the build still exits 2.

A render error names the file that actually failed, and the line when BoxLang reports one:

broken.bxm: Function [noSuchFunction] not found (line 3)
_includes/page.bxm: while rendering about.md: The requested key [nope] was not located in any scope or it's undefined (line 1)

When the failing file is a view or layout, the message says which page was being rendered, and the same failure is reported once per build however many pages use that view or layout; none of those pages is written. Compile errors already carry Line: N Col: N in their message and get no extra suffix. When no line can be determined, the suffix is left out.

Notes:

  • serve uses a small web server built into the module, so it needs nothing beyond BoxLang. It listens on 127.0.0.1 only, answers a missing page with the site's 404.html when there is one, and tells browsers not to cache. If the port is already in use, serve says so and exits 2. It is a preview server, not something to put on the internet.
  • Live reload: serve adds a small inline <script> before </body> (or at the end when there is none) of every HTML page it sends, the 404 page included. The script asks /__ssg/reload about once a second and reloads the page after each rebuild, failed rebuilds included, so fixing an error shows up too. The files in outputDir are never changed; only the response is. With --no-reload nothing is injected and /__ssg/reload is an ordinary missing page.
  • serve ignores baseUrl and previews the site at the root: links get no path prefix and absUrl() and prc.absoluteUrl use http://localhost:<port>. build uses the configured value.
  • serve and build --watch watch every file under the site root except outputDir, folders whose name starts with . and symbolically linked folders. outputDir is read again from ssg-config.json on every check (the last one that loaded is kept while the file does not load), so changing it triggers one rebuild into the new folder, not a rebuild loop. The old output folder is left in place and from then on counts as source; delete it.
  • serve keeps serving the outputDir it read at start, even after outputDir changes and the site is rebuilt into the new folder. Stop and restart serve to serve the new one.
  • The boxlang launcher in BoxLang 1.19 splits arguments that contain spaces, so --source "my site" does not work through it. cd into the site and run the command there instead.

Site layout

my-site/
  ssg-config.json          configuration (optional; every key has a default)
  index.bxm                home page            -> /
  404.md                   not-found page       -> /404.html
  jokes.bxm                paginated page       -> /jokes/, /jokes/page/2/, ...
  tags.bxm                 one page per tag     -> /tag/<tag>/
  feed.bxm                 Atom feed of posts   -> /feed.xml
  sitemap.bxm              sitemap              -> /sitemap.xml
  posts/
    hello-world.md         a post               -> /posts/hello-world/
  _includes/
    layouts/main.bxm       layout: the HTML shell
    page.bxm  post.bxm     views, chosen by `view` or `type`
    sidebar.bxm            a partial, included from views
    applicationHelper.bxm  functions available in every template
  _data/
    jokes.json             data                -> collections.global.jokes
  assets/                  copied as-is (listed in passthru)
  _site/                   build output (outputDir)

Every .md and .bxm file is a document, except files in:

  • _includes/, _data/ and the output directory
  • any folder whose name starts with ., at any depth
  • boxlang_modules/ and node_modules/, at any depth
  • the folders listed in the ignore config key

README.md at the site root is skipped as well.

How a document is rendered

  1. A .md body is converted to HTML. A .bxm file is executed as a BoxLang template.
  2. The view _includes/<view>.bxm is rendered, if it exists, with the result in prc.content. view defaults to the document's type.
  3. The layout _includes/layouts/<layout>.bxm is rendered, if it exists, with the result in renderedHtml. layout defaults to main.

layout: none skips both the view and the layout: the page is written exactly as step 1 produced it.

Templates see:

  • prc: the current document (all front matter keys plus the fields below)
  • collections: every document grouped as described under Collections and data
  • renderedHtml: in layouts, the output of the view, or of the document if it has no view
  • config: the loaded configuration, including your own keys from ssg-config.json (see Configuration)
  • relUrl( path ) and absUrl( path ): links that respect baseUrl (see Base URL)
  • every function defined in _includes/applicationHelper.bxm

Partials are included relative to the including template, for example <bx:include template="sidebar.bxm" />.

Front matter in a layout or view file is merged into prc of every document that uses it, without overwriting keys the document already has, either from its own front matter, from folder defaults or as a built-in default. So a layout or view can add keys of its own, but cannot change built-in ones such as title, type or view.

The starter keeps the site title, description and author in ssg-config.json under site and reads them as config.site.title and so on, so that pages with layout: none, such as the feed, see the same values as the layout.

Front matter

Front matter must start on the first line of the file.

In .md files it sits between --- lines:

---
type: post
title: Hello World
description: The first post
date: 2026-01-15
tags:
- boxlang
- getting started
---

# Hello

In .bxm files it is a leading <!--- ---> comment:

<!---
type: page
title: Home
--->
<bx:output>
<bx:loop array="#collections.post#" item="post">
	<a href="#post.permalink#">#post.title#</a><br />
</bx:loop>
</bx:output>

A leading .bxm comment counts as front matter only if it parses as a YAML mapping. Any other leading comment stays in the page as an ordinary comment, and the build prints a warning naming the file. In .md files, front matter that is not valid YAML, or a missing closing ---, fails the build.

Key Default Meaning
title "" Page title. The starter layout puts it in <title>.
description "" Short description. The starter layout puts it in <meta name="description">, falling back to the site description.
type page Document type. Picks the default view and the collection the document joins (collections.<type>).
layout main Layout in _includes/layouts/, without extension. none renders without view and layout.
view the type View in _includes/, without extension.
slug file nameLast part of the URL when there is no permalink.
permalink derived from the pathOutput URL. See URL scheme.
fileExt html Output extension, for example xml for a feed.
date see belowDate of the document; the sort key for posts.
publishDate Used as the date when date is absent.
tags A tag or a list of tags. Builds collections.tags and collections.byTag. An empty tags: is allowed.
published true false makes the document a draft. See --drafts.
excludeFromCollections false true builds the page but keeps it out of every collection.
excerpt see belowSummary used as prc.excerpt, for example in a post list or feed.
pagination Expands the document into several pages. See Pagination.

The date of a document is date, else publishDate, else the date at the start of its file name, else the file's modified time. A value that is not a date is ignored with a warning.

A file named YYYY-MM-DD-name.md (or .bxm), such as posts/2026-03-01-launch.md, takes 2026-03-01 as its date when it sets neither date nor publishDate. A prefix that is not a real date (2026-13-40-x.md) is ignored without a warning. The default URL still contains the whole file name (/posts/2026-03-01-launch/); use slug, permalink or a permalink pattern to drop the date from it.

Besides its front matter keys, prc holds:

Field Meaning
inFile Source path relative to the site root, for example posts/hello-world.md
outFile Output path relative to outputDir, for example posts/hello-world/index.html. Never includes the baseUrl path.
permalink URL of the page, for example /posts/hello-world/, or /blog/posts/hello-world/ with a baseUrl path of /blog
absoluteUrl Full URL of the page, https://example.com/blog/posts/hello-world/, when baseUrl has a scheme and host; otherwise the same as permalink. An absoluteUrl set in front matter (the document's, folder defaults', or its layout's or view's) is kept as written.
fileSlug Source file name without extension
content Converted Markdown for .md; in views, the rendered document
excerpt A short summary as HTML. See below.
previous, next Neighbouring documents of the same type. See below.
date Resolved date (a date object)
lastModified File modified time, ISO 8601

prc.excerpt is the excerpt front matter key when there is one, from the document, its folder defaults, or its layout or view. Otherwise, when the body contains <!--more-->, it is everything before the marker (for .md converted to HTML; for .bxm the template source before the marker, not executed). Otherwise, for .md, it is the first paragraph (<p>...</p>) of the converted HTML, and for .bxm it is "". The marker itself stays in prc.content; as an HTML comment it does not show.

prc.previous and prc.next link each document to its neighbours in collections.<type>, in that collection's order. Posts are newest first, so on a post next is the newer post and previous the older one. Each is an empty struct when there is no neighbour, and otherwise a small struct { title, permalink, absoluteUrl, date }:

<bx:if !prc.next.isEmpty()>
	<a href="#prc.next.permalink#">#prc.next.title# &rarr;</a>
</bx:if>

Documents that are not in collections get empty structs. If the front matter already sets excerpt, previous or next, that value is kept as written.

Folder defaults

A file named _defaults.yml, _defaults.yaml or _defaults.json in any folder supplies front matter for every document in that folder and the folders below it:

# posts/_defaults.yml
type: post
layout: main
author: boxlang-ssg

Precedence, highest first:

  1. the document's own front matter
  2. the nearest folder's defaults, then each parent folder's, up to the site root
  3. the built-in defaults (type: page, layout: main and the others in the table above)
  4. layout and view front matter, which only fills keys still missing

Keys are merged one by one at the top level; a struct or list value in a document replaces the default's whole value. A permalink from folder defaults counts as an explicit permalink. A defaults file that does not parse, or one that is not a mapping, fails the build naming the file, and so do two defaults files in the same folder. Defaults files are never rendered (only a passthru folder would copy one).

Creating documents

boxlang module:ssg new My First Post
boxlang module:ssg new About this site --type page
boxlang module:ssg new Work in progress --draft --dir drafts

The words after new are joined with single spaces to make the title, so quotes are not needed. The file is <dir>/<slugified title>.md under the site root (--source is honoured); its folder is created if needed. It starts with:

---
title: "My First Post"
type: post
date: 2026-11-29
---

date is today, and --draft adds published: false. Runs of whitespace in the title, line breaks included, become single spaces. The title is written as a quoted YAML string, so : and # are safe. new prints the path it created, relative to the site root. It refuses, with exit code 1, when no title is given, when the title produces no usable file name (the slug keeps only a-z, 0-9 and -, so a title such as !!! or one written entirely in a non-Latin script gives an empty name), when the file already exists, or when --dir points outside the site root or into outputDir.

URL scheme

URLs are folder-style, so a built site works on any static host without a router or rewrite rules.

Source Front matter URL Written to
about.md /about/ about/index.html
index.bxm / index.html
docs/index.md /docs/ docs/index.html
posts/my-file.md type: post /posts/my-file/ posts/my-file/index.html
posts/my-file.md type: post, slug: nice /posts/nice/ posts/nice/index.html
404.md /404.html 404.html
feed.bxm fileExt: xml /feed.xml feed.xml
x.md permalink: /a/b/ /a/b/ a/b/index.html
x.md permalink: a/b/ /a/b/ a/b/index.html
x.md permalink: /a/b.html /a/b.html a/b.html
x.md permalink: /sitemap.xml /sitemap.xml sitemap.xml (fileExt becomes xml)
posts/p.md type: post, permalink: /p/ /p/ p/index.html
x.md permalink: /a.xml, fileExt: rss /a.xml a.xml (fileExt stays rss)

The rules:

  • An explicit permalink always wins, for every type. Ending in /, it writes index.html under it; otherwise it is the file path as written. A leading / is added if missing.
  • Otherwise a permalink pattern for the document's type, when configured, is used, except for index documents and the root 404 document, which keep the URLs below.
  • Otherwise, a document is written to <dir>/<name>/index.html with the URL /<dir>/<name>/. <name> is slug when set, otherwise the file name.
  • index.md or index.bxm in a folder is written to <dir>/index.html with the URL /<dir>/.
  • 404.md at the site root is written to /404.html, where static hosts look for it.
  • A non-HTML fileExt keeps the flat form <dir>/<name>.<ext>.

Two documents that resolve to the same output file fail the build.

The permalinks config key maps a document type to a URL pattern:

{
	"permalinks": {
		"post": "/:year/:month/:slug/"
	}
}

With this, posts/2026-03-01-launch.md (type post) is written to 2026/03/launch/index.html with the URL /2026/03/launch/.

Token Value
:year Year of the document's resolved date, 4 digits
:month, :day Month and day of the resolved date, 2 digits
:slug Front matter slug if set, else the file name without extension and without a YYYY-MM-DD- prefix
:name File name without extension, unchanged
:title Slugified title, or :slug when the title is empty
:dir Folder of the source file relative to the site root, without leading or trailing /; empty at the root (a resulting // becomes /)

The result follows the same rules as an explicit permalink (ending in / writes index.html). An explicit permalink in the front matter, or from folder defaults, still wins. An unknown token fails the build naming the document. A pattern applies to every document of its type except index.md/index.bxm in any folder and 404.md/404.bxm at the site root: with a pattern for page, index.bxm stays at /, docs/index.md at /docs/ and 404.md at /404.html. Give such a document an explicit permalink to move it.

Base URL

Set baseUrl when the site is not served from the root of its host, or to get absolute URLs for feeds and sitemaps:

baseUrl pathPrefix siteUrl
"" (default)"" ""
"/repo" or "/repo/" /repo ""
"https://example.com" "" https://example.com
"https://user.github.io/repo/" /repo https://user.github.io/repo

pathPrefix and siteUrl are also readable as config.pathPrefix and config.siteUrl, unless ssg-config.json defines keys with those names (see Configuration). pathPrefix is put in front of every prc.permalink, every pagination href, and the permalink of every document in collections; prc.outFile is not changed, so the files are written to the same place. prc.absoluteUrl is siteUrl plus the page's path when siteUrl is set.

URLs you write by hand in templates need the prefix too. Use the helpers, callable from any template, view, layout or applicationHelper.bxm function:

Helper With baseUrl https://user.github.io/repo/ With baseUrl ""
relUrl( "/assets/site.css" ) /repo/assets/site.css /assets/site.css
absUrl( "/feed.xml" ) https://user.github.io/repo/feed.xml /feed.xml

A path without a leading / gets one. An argument that already has a scheme (https:, mailto: and so on) or starts with // or # is returned unchanged by both. absUrl returns the same as relUrl when baseUrl has no scheme and host. A function named relUrl or absUrl in your applicationHelper.bxm replaces the built-in one.

prc.permalink, pagination hrefs and the permalinks in collections already include the prefix, so use them as they are: relUrl( prc.permalink ) adds the prefix a second time (/repo/repo/about/).

serve ignores baseUrl (see the notes under Commands and flags).

Collections and data

Collection Contents
collections.all Every document in the build
collections.<type> Documents of that type, for example collections.post and collections.page. The key is lower-case.
collections.post Sorted newest first by date
collections.tags Every tag, once, in its original spelling, sorted case-insensitively
collections.byTag[ slug ] Documents with that tag, newest first, keyed by slugify( tag )
collections.taxonomies.<name>.terms For each key listed in the taxonomies config key: every value of that front matter key, once, in its original spelling, sorted case-insensitively
collections.taxonomies.<name>.byTerm[ slug ] Documents with that value, newest first, keyed by slugify( term )
collections.global The data files in _data/, nested by folder: _data/nav/main.json is collections.global.nav.main

Drafts (unless --drafts), documents with excludeFromCollections: true, and the template of a paginated document are not in any collection. The pages that pagination generates are.

Pagination over collections.tags (or a taxonomy's terms) also produces pages for the tags carried by paginated documents, so every tag in the final collections.tags gets its page. Tags that only arrive through pagination data itself (the struct values merged into each page with size: 1) are not known at that point and may not get a page.

Taxonomies

tags is built in. To group documents by other front matter keys, list them in ssg-config.json:

{
	"taxonomies": [ "categories" ]
}

A document with categories: [ Guides, News ], or categories: Guides, then appears in collections.taxonomies.categories.byTerm.guides. A single value is one term and a list gives one term per entry; an empty value gives none, and entries that are empty or are themselves lists or mappings are skipped. When the first entry of the list is itself a list, that inner list is used instead ([ [ Guides, News ] ] reads as [ Guides, News ]). tags follow the same rules, except that for tags this inner-list case is handled only in a document's own front matter, not in folder defaults. collections.taxonomies always exists, empty when nothing is configured. Listing tags is allowed and gives the same terms as collections.tags. A page per term:

<!---
title: Categories
permalink: /category/{{category}}/
pagination:
  alias: category
  data: collections.taxonomies.categories.terms
--->

Data files

Every .json, .yml, .yaml and .csv file under _data/ is loaded into collections.global, keyed by folder and file name without extension. Other files are ignored.

  • JSON and YAML files hold any value. An empty YAML file is an empty struct.
  • A CSV file becomes an array of structs: the first row is the header, each further row a struct keyed by the header names, with every value a string. Quoted fields may contain commas, line breaks and doubled quotes (""). Blank lines at the end are ignored; a row with a different number of fields than the header fails the build.
  • A .yml, .yaml or .csv file with the same key as a .json file, such as _data/team.json and _data/team.yml, is skipped: the JSON file is used and the build prints a warning naming both.
  • Two .yml, .yaml or .csv files with the same key, such as _data/team.yml and _data/team.csv, fail the build naming both, as does a file that does not parse.
  • Two .json files with the same key, such as _data/team.json and _data/team.backup.json (the key is the file name up to its first .), are both loaded and the one listed later by the file system wins, as in 1.0.

Pagination

Add pagination to a document's front matter to turn it into several pages.

Key Default Meaning
data requiredA path starting with collections., for example collections.tags or collections.global.jokes.jokes, or an inline list. A path that does not exist fails the build. If it points to a struct, its keys are paged, sorted, and with size: 1 a key's value, when it is a struct, is merged into that page's prc.
size 1 Items per page.
alias pagedData Name under which each page's items appear in prc.

Each page gets its items in prc[ alias ] and navigation in prc.paginationInfo:

paginationInfo.pageNumber, pageSize, totalPages, totalItems
paginationInfo.href.current, previous, next, first, last   ("" when there is none)
paginationInfo.pages   [ { number, href, current } ]

Page URLs come from the document's permalink, or from the URL it would have without one:

  • {{page}} or {{pageNumber}} in the permalink is replaced by the page number on every page, including page 1.
  • {{<alias>}} is replaced by the slugified item. This needs size: 1 and simple values.
  • Otherwise page 1 is the permalink itself and page n is <permalink>page/<n>/. The permalink must end in / (or /index.html) when there is more than one page.

Every href points at a file the build writes.

A list of jokes from _data/jokes.json, five per page, at /jokes/, /jokes/page/2/, and so on:

<!---
title: Jokes
permalink: /jokes/
pagination:
  data: collections.global.jokes.jokes
  size: 5
--->
<bx:output>
<bx:loop from="1" to="#prc.pagedData.len()#" index="i">
	<p>#prc.pagedData[i]#</p>
</bx:loop>
<bx:if prc.paginationInfo.href.previous.len()>
	<a href="#prc.paginationInfo.href.previous#">Previous</a>
</bx:if>
<bx:if prc.paginationInfo.href.next.len()>
	<a href="#prc.paginationInfo.href.next#">Next</a>
</bx:if>
</bx:output>

One page per tag at /tag/<slugified tag>/:

<!---
title: Tags
permalink: /tag/{{tag}}/
pagination:
  alias: tag
  data: collections.tags
--->
<bx:output>
	<h4>Posts tagged as #prc.tag#</h4>
	<bx:loop array="#collections.byTag[ slugify( prc.tag ) ]#" item="post">
		<p><a href="#post.permalink#">#post.title#</a></p>
	</bx:loop>
</bx:output>

Link to a tag page with the same slug: <a href="#relUrl( '/tag/' & slugify( tag ) & '/' )#">#tag#</a>.

Configuration

ssg-config.json in the site root is merged over the defaults, so every key is optional and the file itself may be absent.

{
	"outputDir": "_site",
	"passthru": [],
	"ignore": [],
	"minify": false,
	"tidyHtml": false,
	"baseUrl": "",
	"permalinks": {},
	"taxonomies": []
}
Key Default Meaning
outputDir "_site" Build output folder. It is deleted on every build, so it must be inside the site root and not the site root itself.
passthru [] Files or folders, relative to the site root, copied into outputDir unchanged. An entry that does not exist fails the build.
ignore [] Folders, relative to the site root, to leave out of the build.
minify false Removes blank lines from HTML output.
tidyHtml false Reformats HTML output with jsoup.
baseUrl "" Public URL of the site (https://example.com/, https://user.github.io/repo/) or a path prefix (/repo). It must start with http://, https:// or a single / (not //), and contain no ? or #. See Base URL.
permalinks {} Permalink pattern per document type, for example { "post": "/:year/:month/:slug/" }. See Permalink patterns.
taxonomies [] Front matter keys to group documents by, besides tags. See Taxonomies.

minify and tidyHtml apply to HTML output only. Invalid JSON, or a value of the wrong type for one of these keys, fails the build with a message naming the key.

Any other key is kept and can be read in templates through config, for example config.site.title in the starter.

Reserved names:

  • siteRoot, outputPath and __ssg are set by the generator and overwrite a key of the same name in the file.
  • siteUrl and pathPrefix: when the file does not define them, config.siteUrl and config.pathPrefix hold the values derived from baseUrl. When it does, they are kept exactly as written, whatever baseUrl is; links, relUrl(), absUrl() and prc.absoluteUrl still use the values derived from baseUrl.
  • Collection names: collections.all, collections.tags, collections.byTag and collections.global are built in; do not use all, tags, byTag or global as a document type.
  • taxonomies as a document type: with no taxonomies configured, collections.taxonomies is the collection of documents of that type, as in 1.0. With taxonomies configured, a document of type taxonomies fails the build naming the document.

Feed and sitemap

The starter's feed.bxm writes an Atom feed of collections.post, newest first, to /feed.xml, and the layout links it with <link rel="alternate" type="application/atom+xml">. sitemap.bxm writes /sitemap.xml with one entry per HTML page in collections.all, leaving out 404.html. Both use layout: none and excludeFromCollections: true. Their entries link to each document's absoluteUrl; the feed's own rel="self" link is its prc.absoluteUrl, and its site link and <id> come from absUrl( '/' ).

Set baseUrl to the site's public URL before publishing. With the default empty baseUrl, the links in the feed and sitemap are root-relative paths such as /posts/hello-world/, which feed readers and search engines do not accept.

Development

git clone https://github.com/robertz/boxlang-ssg.git
cd boxlang-ssg
install-bx-module bx-yaml bx-markdown bx-jsoup --local
box install testbox --saveDev
./testbox/run --directory=tests.specs
tests/smoke.sh
  • Specs live in tests/specs/ (unit and integration), with one small site per behaviour in tests/fixtures/.
  • The TestBox runner exits non-zero and prints a stack trace even when every spec passes (an upstream bug), so read its "Final Stats" line rather than the exit code.
  • tests/smoke.sh runs the specs, judges them by "Final Stats", then runs the CLI end to end (help, init, build, list, new, a broken build, clean) against the working copy. It exits non-zero if anything failed. CI runs it on every push and pull request.
  • boxlang module:ssg loads modules from ./boxlang_modules/ of the current folder, so to try the working copy on a site, link the repository into the site's boxlang_modules/ as ssg. tests/smoke.sh shows how.
  • A module installed globally (under ~/.boxlang/modules/, the BoxLang home) takes priority over one of the same name in ./boxlang_modules/, so an installed boxlang-ssg would shadow the working copy. tests/smoke.sh therefore runs the CLI under its own empty BOXLANG_HOME; do the same when trying the working copy by hand on a machine that has the module installed.

License

MIT. See LICENSE.

Changelog

1.1.0

Added

  • baseUrl config key: a full URL (https://user.github.io/repo/) or a path prefix (/repo). prc.permalink, pagination hrefs and collection permalinks include the path prefix; prc.outFile does not. New prc.absoluteUrl (a front matter absoluteUrl still wins), derived config.pathPrefix and config.siteUrl (a site's own keys of those names are kept as written), and the template helpers relUrl() and absUrl(), which return an argument with a scheme, or starting with // or #, unchanged (a function of the same name in applicationHelper.bxm wins). A baseUrl starting with // is rejected. serve ignores baseUrl and previews at the root.
  • Templates can read the loaded configuration as config, including custom keys from ssg-config.json.
  • Folder defaults: _defaults.yml, _defaults.yaml or _defaults.json supplies front matter for every document in its folder and below.
  • _data/ also loads .yml, .yaml and .csv files. Two of these files for the same key fail the build; beside a .json file of the same key, one is skipped with a warning.
  • permalinks config key: a URL pattern per document type, with the tokens :year, :month, :day, :slug, :name, :title and :dir. An explicit permalink still wins, and a pattern does not apply to index documents or the root 404 document.
  • taxonomies config key: group documents by other front matter keys in collections.taxonomies.<name>.terms and .byTerm. A site with a document type named taxonomies keeps collections.taxonomies as that type's collection until it configures taxonomies; with taxonomies configured, such a document fails the build.
  • prc.excerpt (front matter excerpt, the content before <!--more-->, or the first paragraph of a Markdown document) and prc.previous / prc.next within each type collection.
  • new <title> command with --type, --dir and --draft.
  • build --watch rebuilds whenever the source changes. Changing outputDir while build --watch or serve runs triggers one rebuild, not a rebuild loop.
  • serve reloads open pages in the browser after each rebuild; --no-reload turns it off.
  • The starter has an Atom feed (/feed.xml) and a sitemap (/sitemap.xml), links the feed from its layout, uses relUrl() for its own links so it works under a path prefix, shows excerpts on the home page and previous/next links on posts. Its site title, description and author moved from the layout's front matter to site in ssg-config.json, read as config.site.*.

Changed

  • A file named YYYY-MM-DD-name.md without date or publishDate takes its date from the file name; in 1.0.0 it fell back to the file's modified time. So a post (type: post) whose file name carries a future date and that has no date in front matter is now future-dated, and left out of the build unless --drafts; 1.0.0 published it. A date in a file name that is impossible or unparsable (0000-01-01-, 2026-13-01-) is ignored without a warning.
  • .yml, .yaml and .csv files in _data/ are now loaded into collections.global (1.0.0 ignored them), and a _defaults.yml, _defaults.yaml or _defaults.json file now applies to its folder.
  • Data file keys: .json files load exactly as in 1.0.0, so two .json files with the same key (x.json, x.backup.json) still build and the later one wins. A .yml, .yaml or .csv file with the same key as a .json file is skipped, so the output is unchanged, and the build prints a warning naming both files. Two .yml, .yaml or .csv files with the same key fail the build naming both.
  • Existing custom keys named baseUrl, permalinks or taxonomies in ssg-config.json are now validated and fail the build if they have the wrong shape. Custom siteUrl and pathPrefix keys are kept as written; config.siteUrl and config.pathPrefix show the values derived from baseUrl only when the file does not define them. __ssg is reserved for the generator.
  • Render errors name the file that failed (the view or layout, not only the page) and end with (line N) when BoxLang reports a line. An error in a view or layout says which page was being rendered (<file>: while rendering <page>: <message>) and is reported once per build instead of once per page.

Fixed

  • A tag carried only by pages that pagination generates appeared in collections.tags but got no tag page; pagination over collections.tags now covers it. Tags that come only from the pagination data itself may still be missed.

1.0.0

  • Output paths changed to folder-style URLs: posts/x.html is now posts/x/index.html (URL /posts/x/), so sites work on any static host. router.bxs was removed.
  • boxlang-ssg is now a BoxLang module, installed once and run from any site folder with boxlang module:ssg <command>. New commands: init, serve, list, clean; new flags: --source, --verbose, --drafts, --port. Exit codes: 0 success, 1 usage error, 2 build failure.
  • setup.bx and requirements.txt were removed. bx-yaml, bx-markdown and bx-jsoup are declared as dependencies in box.json with caret ranges. install-bx-module does not install declared dependencies, so the install command names them; box install boxlang-ssg (CommandBox) does install them. build and serve check for the three modules at startup and print the install command if one is missing.

Fixed

  • Builds failed on BoxLang 1.19 because templates were included by absolute path; site templates are now included through an application mapping.
  • Exceptions are no longer swallowed: a page that fails to render is not written, every failure is reported as file: message, and the build exits 2. The error(), print.greyline(), dump() and abort calls are gone.
  • Pagination wrote page 1 of permalink: /jokes/page/{{page}}/index.html to /jokes/page/index.html/index.html; every page now substitutes its number, and paginationInfo.href values point at files that exist.
  • Paginated pages respect excludeFromCollections in type collections as well as all, and type keys are lower-cased consistently.
  • Discovery matches .md and .bxm by extension rather than by substring, and always skips _includes/, _data/, the output folder, dot-folders at any depth, boxlang_modules/ and node_modules/. Only the root README.md is skipped by default.
  • Front matter without a closing marker, or .md front matter that is not valid YAML, fails the build naming the file; an empty tags: no longer throws.
  • Posts sort newest first by date, then publishDate, then file modified time, without throwing when dates are missing. Future-dated posts are treated as drafts unless --drafts.
  • Tag permalinks use the slugified tag, and the starter links to the URL the tag page is written to.
  • The starter layout uses the page's title and description, falling back to the site values.
  • ssg-config.json is merged over defaults and validated; outputDir must be inside the site root and not the site root itself.
  • bx-markdown is no longer pinned to an exact version.
  • pagination.data resolves against collections only, and a path that does not exist fails the build instead of being created silently.
  • An explicit permalink on a type: post document was ignored when choosing the output file; an explicit permalink now wins for every type.
  • collections.tags and collections.byTag are built in one place from every document with tags that is not excluded from collections.
  • An empty front matter value such as title: left the key null on BoxLang without bx-compat-cfml; it now falls back to the default.
  • The starter's post date and stylesheet cache-buster used CFML date masks (mmm, yyyy-mm-dd), which fail or print minutes on BoxLang without bx-compat-cfml; they now use MMM and yyyy-MM-dd.

Changed

  • collections.tags is now sorted case-insensitively.
  • Generated pagination pages now take part in type and tag collections and honour excludeFromCollections.
  • A paginated template with no explicit permalink bases its pages on its own resolved permalink; size: 1 without a placeholder writes page/<n>/ instead of overwriting one file.
  • minify and tidyHtml apply to HTML output only (previously minify also touched non-HTML output such as XML feeds).
  • Front matter must start on the first line of the file.
  • In .bxm files a leading comment that is not a YAML mapping is treated as an ordinary comment with a warning.
  • Two documents that resolve to the same output file, a missing passthru entry, invalid config, and front matter/pagination/render errors now fail the build with exit code 2 instead of being skipped silently.
  • Bootstrap JS, jQuery and Popper removed from the starter layout.
  • prc.inFile and prc.outFile are now paths relative to the site root and the output folder (they were absolute paths), and prc.date is always a date object.
  • A passthru entry that is empty, ., an absolute path or contains .. now fails the build; entries must be paths inside the site root.
  • serve uses a web server built into the module and no longer needs boxlang-miniserver. It listens on 127.0.0.1 only, so the site is reachable from your own machine alone, and it answers a missing page with the site's 404.html.

$ box install boxlang-ssg

No collaborators yet.
     
  • {{ getFullDate("2026-11-29T10:23:50-06:00") }}
  • {{ getFullDate("2026-11-29T12:12:43-06:00") }}
  • 29
  • 4