Language

Theme package layout

Which five cells the manifest requires, how the preview image is validated and bound, the rules for paths inside the package, and why changing templates must also bump the version number.

A theme package is a directory archive with a manifest.json. This page covers what it must declare, how uploads are checked, and which details that "look like mere layout" are actually rejected.

Five cells are required in the manifest. id, name, version, requires_kernel, templates. Optional are assets, preset, digest, preview, preview_for. requires_kernel is not decoration: when the kernel is incompatible the theme does not install, rather than installing and crashing on some render. templates is a declaration list — which files the theme editor can list and read all follow it, and the interface surface does not accept you handing over a file name directly. The consequence of this design is that "path traversal" has no entry on this surface, rather than "has an entry but is blocked".

The version number has only one owner. It is the manifest.json entry called version. The save request body has no second version parameter, and the "bump a version" on the UI edits this one cell's text. When a second declaration appears (another version number kept in the form), the two are bound to drift.

Paths inside the package must be relative to the package root. Ones with parent-directory jumps or in absolute-path form are rejected at the moment of unpacking, reporting "unsafe path" and naming the file. Likewise, if a declared path points outside the package or to something that does not exist, registration fails as a whole — there is no such thing as a half theme; either the whole package goes in, or not one byte.

An uploaded theme must carry a preview image, and this image is validated. It must be declared in assets; the actual bytes must be PNG or JPEG, no more than 1 MiB, with valid dimensions and encoding, and the extension must match the real encoding (renaming a JPEG to .png is rejected, not tolerated). Between the preview image and the theme content there is also a binding: when computing the theme digest, the preview image itself is deliberately excluded — otherwise "the image carries the digest and the digest contains the image" is a loop. The binding field's purpose is to keep a preview image from quietly belonging to another version — the "changed content without changing the preview" case is caught on the spot by this binding.

Built-in themes and uploaded themes differ on the preview image. The built-in one travels with the binary; the uploaded one follows this static-image path above. The UI states plainly "the author's preview image is a static reference, not a live screenshot" — it does not represent what visitors see in the current version.

Changing templates or CSS must also bump the version number. This is the easiest to overlook and the easiest to waste work on: at startup the embedded theme replays the version it declares, and changes landed on the same version number are "changed, but in vain". Bumping the version is safe for old stores, but the cost must be said — published snapshots still pin the old theme version, and operations must click publish once before new styles take effect for old visitors.

The styles come from the theme version's own .css assets, read from disk in the same pass as templates and cached under the same content digest. Three states are judged separately: if this version really declares no CSS, nothing is injected (no fallback to a style it never wrote and cannot remove from the theme); only when it is declared but cannot be read (directory missing, digest mismatch) does it fall back to the built-in preset, preserving the existing degradation behavior.

The interface surface is self-describing. The fields a theme can read are self-described by GET /api/v1/themes/api — field names, meanings and template examples are generated by reflection from the server-side data structures, not a second hand-written document. So when you see a new field, that self-description must contain both its Chinese and English explanations; conversely, a field absent from the self-description does not exist, so do not guess it in templates.