Site Themes
A release can carry its own front end: stylesheets, scripts and fonts, published with the pages and with no build step. This needs site themes turned on for your FOLD (FOLD_SITE_THEMES=on).
Add A Theme
Put .css and .js files anywhere in the directory. They're published at their authored paths. Then add a head.html at the root that lists what every page loads.
<meta name="description" content="Field notes">
<link rel="preload" as="font" type="font/woff2" crossorigin href="/fonts/body.woff2">
<link rel="stylesheet" href="/styles/styles.css">
<script type="module" src="/scripts/scripts.js"></script>
FOLD then serves each page as a full document. The <head> holds the charset, a viewport unless you supply one, a <title> from the page's first heading, and your elements. The body is <header></header><main>PAGE</main><footer></footer>, with the page in <main>.
What head.html Accepts
| Element | Accepted |
|---|---|
link |
rel of stylesheet, preload, modulepreload or icon, with href, and optionally as (preload only), type, crossorigin, media and sizes |
script |
type="module" with a src. Inline scripts aren't supported |
meta |
name and content |
Each href and src must name a .css, .js, font or image file in the same release. FOLD rewrites it relative to each page, so a theme works under a site mount and in a preview. Any other element, attribute or outside URL fails the build with a diagnostic that names it.
On a theme page, Markdown tables are parsed, and HTML pages keep up to eight lowercase class names on div and section.
What A Theme Page Can Load
FOLD sends theme pages a content security policy.
- Scripts, styles, fonts and requests must come from the release's own origin.
- Setting HTML from a script requires Trusted Types, with one policy named
fold. - Scripts run on the site's own hostname and in a preview you've been granted. On the shared platform host, theme pages keep their styles but no script runs.
For a working starting point, copy the FOLD site template. This site is built from it.
How Theme Files Are Cached
FOLD also serves every .css, .js, font and image file under /_fold/theme/SET/, where SET is a digest of all of them, and points your head.html references there. On a published site a browser keeps those files for a year without asking again. SET changes only when one of the files changes, so publishing new pages keeps visitors' copies, and a rollback returns to the earlier set.
Files keep their layout under that path, so a relative import or url() between them still works. A script that loads other theme files should resolve them against its own URL. Pages and fragments stay at the site root, which a script one folder down finds like this:
const assets = new URL('../', import.meta.url);
const root = new URL(assets.href.replace(/_fold\/theme\/[0-9a-f]{64}\/$/, ''));
Next: Images and variants