Assets and images
Files in assets/ are copied to the output, with stylesheets bundled and fingerprinted by Lightning CSS. Tailwind CSS is an opt-in. Image attachments have sizes, EXIF data and thumbnails.
The assets directory
Everything in assets/ is copied to the root of the output:
assets/robots.txt becomes robots.txt, assets/js/site.js becomes
js/site.js. Files starting with a dot are skipped. Link to assets with
asseturl, which adds the base path and the fingerprint:
<link rel="stylesheet" href="{{ '/css/main.css'|asseturl }}">
<script src="{{ '/js/site.js'|asseturl }}" defer></script>
<img src="{{ '/images/logo.svg'|asseturl }}" alt="">
With a theme, the theme's assets/ are built too, and a file
of the site's assets/ replaces the theme's file of the same path.
An asset and a page cannot have the same output path
(motabhai::build::output_conflict).
Stylesheets
Every .css file in assets/ is processed with
Lightning CSS, which is built into motabhai:
@imports of local files are bundled into the stylesheet. A path is relative to the importing file, or toassets/if it starts with/. Imports of URLs are kept as they are.- Newer syntax, such as nesting, is rewritten, and vendor prefixes are
added, for the browsers
css.browsersnames: Browserslist queries,["defaults"]unless set. - The result is minified, unless
css.minify = false. - The file name gets a hash of the built stylesheet, such as
css/main.3f2a9c1b.css, unlesscss.fingerprint = false.asseturllinks to the hashed name, so browsers can cache stylesheets forever.
Files whose names start with _ are partials: they are built only into
the stylesheets that import them, and cannot be linked to.
/* assets/css/main.css */ @import "_base.css"; @import "../vendor/reset.css"; .card { user-select: none; &:hover { color: red; } }
# motabhai.toml
[css]
browsers = ["safari 15"] # nesting rewritten, -webkit-user-select added
A syntax error, an import that does not exist, or an import from outside
assets/ fails the build with a location (motabhai::css::syntax,
motabhai::css::import), as does an error Lightning CSS reports while
minifying or writing the stylesheet (motabhai::css::invalid). A query in
css.browsers that Browserslist does not know is
motabhai::config::invalid_browsers. Only stylesheets are fingerprinted;
other assets keep their names. url() references inside stylesheets are not rewritten,
so keep them relative to the stylesheet.
Changing a stylesheet changes its hash, which rebuilds the pages that link to it. A change that builds the same CSS, such as a new comment, rebuilds nothing else.
Tailwind CSS
Tailwind is optional. Add a [tailwind] table to motabhai.toml:
[tailwind]
version = "4.3.5" # an exact Tailwind CSS 4 version
input = "css/main.css" # the default
and import Tailwind in the input stylesheet:
/* assets/css/main.css */ @import "tailwindcss";
motabhai new --tailwind sets both up. During a build, motabhai runs the
Tailwind standalone executable on the input, scanning templates/,
content/ and the templates of the theme in use for class
names, so classes typed into content work too. Its
output then goes through the same Lightning CSS processing and
fingerprinting as any stylesheet. Only the input is compiled by Tailwind;
other stylesheets are built as usual. motabhai serve runs Tailwind in
watch mode.
motabhai finds the executable in this order:
tailwindcsson yourPATH, if it is the pinned version;- a copy in the per-user cache from an earlier download;
- a download of the pinned version from Tailwind's GitHub releases into the cache, checked against its published checksum.
The cache is MOTABHAI_CACHE_DIR if set, else ~/Library/Caches/motabhai
on macOS, $XDG_CACHE_HOME/motabhai or ~/.cache/motabhai on Linux, and
%LOCALAPPDATA%\motabhai on Windows. MOTABHAI_TAILWIND_MIRROR replaces
the download location. CI runners need no extra step: the first build
downloads Tailwind. Tailwind publishes executables for macOS and Linux on
x64 and arm64, and for Windows on x64.
Errors:
| Code | Meaning |
|---|---|
motabhai::config::invalid_tailwind_version | The version is not an exact 4.x version. |
motabhai::config::invalid_tailwind_input | The input is not a .css path inside assets/. |
motabhai::tailwind::missing_input | The input stylesheet does not exist. |
motabhai::tailwind::unavailable | The pinned version is not on the PATH or in the cache, and cannot be downloaded, for example offline or on a platform Tailwind has no executable for. |
motabhai::tailwind::checksum | A download did not match its checksum. It is not kept. |
motabhai::tailwind::failed | Tailwind itself reported an error. |
Tailwind's working files go in .motabhai/tailwind/.
Images
An attachment that is a PNG, JPEG, GIF or WebP image tells templates about itself. The format comes from the file's content, not its extension.
| Attribute | Value |
|---|---|
width, height | The size as displayed, after the EXIF orientation is applied. |
format | png, jpeg, gif or webp. |
exif | The EXIF data; see below. |
For other files these are none.
{% for image in this.attachments if image.format %}
<img src="{{ image|url }}" width="{{ image.width }}" height="{{ image.height }}" alt="">
{% endfor %}
EXIF data
exif has these attributes, each none when the image does not have it:
| Attribute | Value |
|---|---|
camera_make, camera_model, lens_make, lens_model | Text. |
artist, copyright, description | Text. |
created_at | When the photo was taken, as ISO 8601 text such as 2026-11-29T10:30:00, which dateformat accepts. |
iso | A whole number, such as 400. |
f_num, aperture, focal_length | Numbers, such as 2.8 and 23.0. |
exposure_time | Text, in seconds: 1/250, or 2 for a long exposure. |
latitude, longitude | Decimal degrees, negative for south and west. |
altitude | A number, negative below sea level. |
orientation | The EXIF orientation, 1 to 8. |
{% set exif = image.exif %}
{{ exif.camera_make }} {{ exif.camera_model }}, {{ exif.lens_model }}
{{ exif.created_at|dateformat("%Y-%m-%d %H:%M") }}
ISO {{ exif.iso }}, f/{{ exif.f_num }}, {{ exif.focal_length }} mm, {{ exif.exposure_time }} s
Thumbnails
thumbnail(width, height, mode) makes a resized copy during the build.
Arguments can be given by position or by name, and any can be left out or
none. A thumbnail prints as its URL, under the base path, and has
url_path, width and height:
{% set image = this.attachments|selectattr("id", "eq", "photo.jpg")|first %}
<img src="{{ image.thumbnail(640) }}"
srcset="{{ image.thumbnail(320) }} 320w, {{ image.thumbnail(640) }} 640w"
width="{{ image.thumbnail(640).width }}" height="{{ image.thumbnail(640).height }}" alt="">
| Mode | Result |
|---|---|
"fit" (default) | Fits inside the width and height, keeping the aspect ratio. With one of them, the other follows. |
"crop" | Fills exactly the width and height, keeping the centre and cutting off what does not fit. Needs both. |
"stretch" | Exactly the width and height, distorting the image. Needs both. |
For a 40×30 image photo.png:
| Call | File | Size |
|---|---|---|
thumbnail(20) | photo@20x15.png | 20×15 |
thumbnail(none, 15) | photo@20x15.png | 20×15 |
thumbnail(20, 10) | photo@13x10.png | 13×10 |
thumbnail(height=6, width=100) | photo@8x6.png | 8×6 |
thumbnail(100) | photo@40x30.png | 40×30: never enlarged |
thumbnail(20, 20, "crop") | photo@20x20_crop.png | 20×20 |
thumbnail(80, 60, mode="stretch") | photo@80x60.png | 80×60 |
Thumbnails are written beside the image, in the image's own format, and
carry no EXIF data. Only the thumbnails some page asks for are built, each
once, and they are rebuilt only when the image changes. A thumbnail of a
hidden page's image is built, though the image itself is not. JPEGs turned
by their EXIF orientation get upright thumbnails. A thumbnail that would
get the name of a file that is already there, such as an attachment named
photo@20x15.png, is motabhai::build::output_conflict. A size that
is not a positive whole number, an unknown mode, or a file that is not an
image is motabhai::template::invalid_thumbnail.