Site

The ssglib.site module manages the output directory for a static site. It tracks which files are written, skips unchanged files, and can clean up stale output.

local site = require "ssglib.site"

Site.new(dir, prefix)

Create a new site rooted at dir. The directory is created if it does not exist. The optional prefix sets the URL path prefix (default "/"); it must start and end with "/".

local s = site.Site.new("docs")
local s = site.Site.new("docs", "/blog/")

Fields

Site:prepare(url)

Prepare to write a file at the given URL. Creates parent directories as needed. URLs ending with / are mapped to index.html. Returns the file system path of the output file.

local path = s:prepare("/articles/hello/")
-- path is "docs/articles/hello/index.html"

Site:write_data(url, data)

Write a string to the file at url. If the file already exists with the same content, the write is skipped.

s:write_data("/index.html", "<html>...</html>")

Site:write_file(url, path, mtime)

Copy a file from path to the site at url. If the target is newer than the source (based on mtime), the copy is skipped.

s:write_file("/style.css", "src/style.css")

Site:write_dir(url, root)

Recursively copy all files from the root directory to the site under url. Dotfiles are skipped.

s:write_dir("/", "static")

Site:cleanup()

Delete files in the output directory that were not written during this build, including dotfiles. Removes empty directories afterwards. Prints a summary of total, updated, and deleted files.