Getting Started

Installing the module, building a first site, and how a site folder is laid out.

Requirements

BoxLang 1.19.0 or later, and three modules the generator uses: bx-yaml, bx-markdown and bx-jsoup.

Install

bashinstall-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):

bashboxlang 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":

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

Example site

ssg-template is a complete site built with boxlang-ssg 1.1: Dark Sky Dispatch, a blog for a made-up astronomy club. It uses every feature of the generator, from folder defaults, taxonomies and permalink patterns to YAML and CSV data, pagination over a data file, an Atom feed and a sitemap, and its README has a table of the file where each one lives. It's a GitHub template repository, so Use this template starts a new site from it.

bashgit clone https://github.com/robertz/ssg-template.git
cd ssg-template
boxlang module:ssg serve

It needs boxlang-ssg 1.1.0 or later. Its baseUrl is a placeholder (https://darksky.example.org/); change it before you publish.

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.