Themes

A theme is a directory of templates and assets in themes/. The site names the one it uses, its own files replace the theme's, and the admin changes between the themes that are installed.

A theme supplies the templates and assets that make a site's pages, so the same content can be given another look by naming another theme. Every site made with motabhai new uses one.

Installed themes

A theme is a directory of themes/, named after the theme, with the same templates/ and assets/ a site has:

mysite/
  motabhai.toml
  themes/
    plain/
      templates/
        layout.html
        page.html
      assets/
        css/main.css
    engineering-fantasy/
      templates/
      assets/

The themes in themes/ are the installed ones. To install another, put its directory there. A theme's name is its directory's name: letters, digits, -, _ and ., not starting with a ..

A theme has only templates and assets. Models, content and databags are the site's own, whichever theme is in use.

theme in [project] names the theme in use:

[project]
name = "My site"
theme = "engineering-fantasy"

A name that is not a directory of themes/ is an error (motabhai::config::unknown_theme) that lists the installed themes, and one that could not be a theme's name, such as a path, is motabhai::config::invalid_theme. A site with no theme uses only its own templates/ and assets/.

The themes motabhai ships with

motabhai new installs both in the new site, and --theme picks the one it uses:

motabhai new mysite --theme engineering-fantasy
ThemeLook
plainOne column of text with the menu on top, light or dark as the system is. The default.
engineering-fantasyA sidebar with the menu, an icon beside each item, next to the content. On narrow screens the sidebar becomes a drawer. Posts and projects are cards, and the home page shows the three latest posts. It is coral, navy and cream, with a dark variant that follows the system and a light bulb button that overrides it. Blocks of code have line numbers, a button to turn them off and a button to copy the code.

Both have templates for the models of the starter site: pages, a blog with a page for each tag, posts, and projects. Both read the menu from the site's databags/menu.toml, a list of items with a label and a path. engineering-fantasy also reads each item's icon: home, blog, projects or about, and anything else gets a dot. The themes are plain files in the site, so you can change them there.

In both, highlighted code turns light or dark with the rest of the page: in engineering-fantasy, the light bulb turns it too.

Light and dark code in a theme of your own

Highlighted code carries a light and a dark colour for each token, as CSS light-dark(), and the page's color-scheme decides which one shows. A stylesheet that sets none gets the light colours. To follow the reader's system, set it on the root:

:root {
  color-scheme: light dark;
}

A theme with its own light and dark switch sets color-scheme to light or dark from it, as engineering-fantasy does from data-theme:

:root[data-theme="dark"] {
  color-scheme: dark;
}

Code blocks carry their own background, so a stylesheet's background for pre shows only on blocks that are not highlighted.

The site's own files come first

A file of the site's templates/ or assets/ replaces the theme's file of the same path, and the theme supplies the rest:

mysite/
  templates/
    page.html            # used in place of themes/plain/templates/page.html
  assets/
    favicon.ico          # added to the theme's assets
  themes/plain/
    templates/
      layout.html        # still used: page.html extends it
      page.html

This is how to change one template of a theme and keep the others, and how motabhai new --tailwind works: its layout.html, blog-post.html and stylesheet are the site's own, over the plain theme. --tailwind and --theme cannot be given together.

A stylesheet's @imports are looked up beside it, so a theme's stylesheet imports the theme's partials and the site's imports the site's.

With Tailwind CSS, the theme's templates are scanned for class names too, and the input stylesheet may be the theme's.

Changing the theme

Edit theme in motabhai.toml, or open Themes in the admin: it lists the installed themes, marks the one in use, and changes to the one you choose. It rewrites only that setting, leaving the file's comments and formatting alone, and the site is rebuilt with the new theme. A site with no theme can be given one there.

The page also lists the site's own templates and assets, since those replace the files of whichever theme is in use.

The next build after a change of theme rebuilds the pages and removes the old theme's files from the output. motabhai serve watches themes/ too, and a change to a file of the theme rebuilds only what uses it.

Changing the theme changes templates and assets, not content or models. A theme needs a template for each model the content uses, so a site changes cleanly between themes made for the same models, as the two shipped ones are.