Files
View as Markdownimport { parseFiles, parseGlob } from '@memomori/obol/files'
const site = parseFiles(['layout.html', 'nav.html'])
const emails = parseGlob('emails/*.tmpl')
Each file becomes a template named after its base name, so views/nav.html
is nav.html. The first file leads the set: site.execute() runs
layout.html, and site.executeTemplate('nav.html', data) runs the other.
parseGlob sorts what the pattern matches, then calls parseFiles. It throws
when nothing matches.
Add to a template #
Pass a template as the second argument to add the files to it, for example to set functions first:
const site = parseFiles(
['layout.html', 'nav.html'],
new Template('layout.html').funcs({ year: () => new Date().getFullYear() }),
)
A file whose base name matches the template's name becomes its body. Two files with one base name in different folders share a name, and the last one wins.
This module reads with node:fs, so it runs in Node only. In a browser, fetch
the text and call parse.