@rathnasgala2/template
Part of Galascribe, blog publishing software and a
Markdown publishing platform for a site you own: you write in an editor, every
post is a Markdown file in your own GitHub repository, and the site is published
to GitHub Pages on your own domain, with scheduled posts, RSS feeds, six
built-in themes and search. This repository is the static site renderer that
turns those Markdown files into the published site.
What Galascribe does ·
Markdown publishing platform
The deterministic Eleventy-backed static publication renderer for Galascribe's
portable author repository format. It is one of the three author-facing S2
artifacts, alongside one @rathnasgala2/theme-* package and
@rathnasgala2/publish-action.
This package is JavaScript ESM on Node 24, authored without TypeScript sources:
every export carries JSDoc types, checked by tsc --checkJs --noEmit against a
hand-maintained .d.ts surface.
Status
This repository's scaffold (exact pins, src/core/-only layout, module-tree
absence gate, quality-gate tooling) plus its renderer adapter:
renderPublication(buildInput, options), exported from src/core/index.js, is
the package's one documented entry point. It:
- validates a candidate
urn:gala:schema:build-input:2.0.0 document with
@rathnasgala2/schemas' validateGalaDocument and fails closed
(BuildInputValidationError, before anything is written) on an invalid one;
- renders the publication profile (when selected) and every selected content
record, plus every authored static redirect document, as complete documents
(
src/core/internal/site-render.js assembles the pages and
src/core/internal/document-shell.js wraps each in its <head> and
<body>), then writes them through a single confined, single-pass
programmatic Eleventy 3.1.6 build behind
src/core/internal/eleventy-render.js — the only module in this repository
permitted to import @11ty/eleventy, so no Eleventy object, plug-in API or
config object ever crosses back out of it; and
- assembles, digests and schema-validates a closed
urn:gala:schema:artifact-manifest:2.0.0 instance describing the candidate
output directory.
The media pipeline lives under src/core/internal/media/, run from
renderPublication after the Eleventy route listing so its output is never
mistaken for an HTML route:
- Bounded decode. JPEG (via the pinned pure-JS
jpeg-js decoder, no native
addon or WebAssembly) and PNG (hand-written, using Node's built-in zlib with
a decompression-bomb-bounded inflate) are fully decoded to RGBA8; WebP, AVIF
and GIF get bounded container/declared-dimension validation without a full
entropy decode, and their original bytes pass through unmodified (a documented
scope decision — see webp-probe.js/avif-probe.js/ gif-probe.js; an
animated GIF keeps its animation). Every format shares one set of resource
ceilings in limits.js (raster dimension, pixel count, decoded-buffer and
source-byte caps reused from the theme package's own closed binary-asset
decoder bounds, plus this renderer's own documented per-publication ceilings).
- Metadata strip, orientation. PNG/JPEG derivatives are always re-encoded
from decoded pixels, never byte-copied, so no ancillary/EXIF metadata survives
into a derivative; JPEG's EXIF
Orientation tag is read and applied
(rotate/flip) before any derivative is produced.
- Deterministic responsive derivatives. Content-addressed
assets/media/<sourceDigest>/{original,<width>w}.<ext> files at fixed widths
320/640/960/1280/1920 (below the source width), re-encoded with fixed,
pinned encoder settings so two clean builds of the same source produce
byte-identical derivative files.
- SVG rejection. Any byte sequence recognized as SVG/XML is rejected
unconditionally as an image reference (
MEDIA_SVG_REJECTED) — SVG is never
processed as author media.
- Font policy.
appearance.fontAssets entries must be bounded WOFF2 (exact
signature, a fixed 4,194,304-byte font cap); a remote font reference cannot
enter build-input in the first place (resolvedFile is always a
repository-relative path), so "no remote font is ever retrieved" holds
structurally.
- Fail-closed errors. Every rejection — oversize, decompression bomb, digest
mismatch, SVG, unrecognized format, invalid font — is a
MediaPipelineError
with a stable reasonCode, thrown before anything is written.
options.sourceDirectory is the caller-mounted, read-only repository source
tree build-input's resolvedFile references point into; every referenced
file's bytes are read from there and verified against build-input's declared
sourceDigest before being decoded.
Content images
Every <img> in a rendered body must name an image file build-input
inventories for that document in content[].media[] (an entry whose mediaType
is image/png, image/jpeg, image/webp, image/avif or image/gif). The
src is resolved by one rule (src/core/internal/media/content-images.js): it
is entity-decoded; a scheme, a protocol-relative //, a query or a fragment
never resolves; one leading / or ./ is dropped (paths are
repository-root-relative); the rest is percent-decoded and NFC-normalized; an
empty, . or .. segment never resolves; the result must equal an inventoried
path. The publication profile and the footer card (checked only when enabled,
since only then is it rendered) have no inventory, so an image there never
resolves.
An image that resolves to nothing (a remote image included: the render policy
already strips its src) fails the build with BuildInputValidationError, one
MEDIA_REFERENCE_UNRESOLVED diagnostic per image (instancePointer names the
body, reference the src), before anything is written. An inventoried file
the media pipeline rejects fails with that MediaPipelineError reason code,
also before anything is written.
A resolved image runs through the media pipeline and renders as
<img src srcset sizes="(max-width: 960px) 100vw, 960px" alt width height loading="lazy" decoding="async">:
srcset names every output file in ascending width (PNG/JPEG: each fixed
derivative width below the source plus the re-encoded original; GIF, WebP and
AVIF: the original only), and src is the widest of them no wider than 960
pixels, or the original when none is. alt is the authored text. The feeds
carry the same src as an absolute URL, without srcset. Only pipeline output
is written: the source file is never copied, and identical bytes under two paths
are processed and written once. Images use the base layer's existing img
rules; no class is added. The front-matter hero renders as the article's cover
<figure> above the body (role: "decorative" renders alt="").
Fenced blocks: video, bookmark, file, poll and quote cards
A fenced code block whose info string is video, bookmark, file, poll or
quote is a card instead of code. This is the authoring contract the App editor
writes and reads back; the blocks are part of the render policy (fencedBlocks
in contracts/render-policy.jcs), so a change to the grammar changes the policy
identity.
Grammar. The body is key: value lines. The value is the rest of the line,
trimmed (no quoting); blank lines are ignored; keys are case-insensitive; a key
the block does not know is ignored. A block is malformed, and renders as an
ordinary code block (never an error), when a non-blank line is not key: value,
a key repeats, a required key is missing or empty, or a value is invalid. Text
limits, in characters and without control characters: title 200, description
500, site 100.
```video
provider: youtube
id: dQw4w9WgXcQ
title: Why we rebuilt it
poster: assets/why-we-rebuilt-it.jpg
```
```bookmark
url: https://example.com/essay
title: A good essay
description: What it argues, in a sentence.
site: Example
```
```file
path: docs/annual-report.pdf
title: Annual report 2026
description: The full report.
```
| Block |
Required |
Optional |
Notes |
video |
provider, id, title |
poster |
provider is youtube (id: 11 characters of A-Za-z0-9_-) or vimeo (id: 1 to 12 digits). poster is a repository image path, resolved like a body image. |
bookmark |
url, title |
description, site |
url is http or https without credentials. site defaults to the hostname without www.. No image: images come only from the repository (img-src 'self'). |
file |
path, title |
description |
path is a repository path ending in .pdf (PDF only), resolved like a body image against the document's media[]. |
Polls. A poll block asks one question with two to six options:
```poll
id: best-day
question: Which day should the newsletter go out?
option1: Monday
option2: Friday
option3: Sunday
```
Keys: id (^[a-z0-9][a-z0-9-]{0,30}$, unique within the post: a second poll
with the same id is an ordinary code block), question (1 to 200 characters),
option1 and option2 (required), option3 to option6 (optional, no gaps;
option7 or a gap makes the block malformed), each option 1 to 80 characters.
The stored and page form is the same, with no script needed:
<figure class="g-poll" data-gala-block="poll" data-gala-poll="<id>"><figcaption>question</figcaption><ul><li data-gala-option="0">option</li>...</ul></figure>.
The sanitizer keeps data-gala-poll only as a valid id and a list item's
data-gala-option only as 0 to 5. With the interactions module on, the
interactions script reads the page's polls once
(GET /v2/public/publications/{publicationId}/contents/{contentId}/polls,
answering {polls: [{pollId, total, options: [{index, count}], myOption?}]}),
turns each list into option buttons, and a signed-in reader's click sends
PUT .../polls/{pollId}/vote with {option}; the percentages and the total
then show, and the reader may vote again to change it. A signed-out reader is
sent to sign in as a like does; every failure leaves the list and is announced
in the live region. The reader-visible sentences are in every message catalog
(pollTotalLabel, pollYourVoteLabel, pollChangeHintLabel,
pollSavedLabel). The interactive preview simulates the read and the vote.
Quotes. A quote block is a testimonial: the words, then who said them:
```quote
text: The words the person said, on one line.
name: Their real name
role: Founder, Example Co
url: https://example.com
photo: images/people/jane.jpg
```
Keys: text (1 to 600 characters) and name (1 to 80) are required; role (1
to 80), url (https:// only, no credentials, at most 2048 characters) and
photo (a repository image path, resolved and inventoried exactly like a
video's poster) are optional. Any other value makes the block malformed (a
code block). It works in posts and pages, with no script. Stored and page form
(escaped throughout, no class added to the public styling contract):
<figure class="g-quote" data-gala-block="quote"><blockquote><p>text</p></blockquote><figcaption>[<img src alt="">]<a href>name</a>, role</figcaption></figure>
(the name is plain text without a url; no role means no comma). The
sanitizer needs no new attribute. The block adds no structured data (no
Review, AggregateRating or Quotation); feeds and email fragments carry the
same figure, and llms-full.txt shows the text and a line — name, role.
Stored form (the body is language-neutral policy output): one
<figure class="g-video|g-bookmark|g-file" data-gala-block="video|bookmark|file">
(a video also carries data-gala-video="<provider>:<id>") holding one <a>
with <strong> (title), optional <small> (description) and, for a bookmark,
<em> (site); a video's poster is an <img src alt=""> inside the link. The
sanitizer keeps figure's class, data-gala-block and data-gala-video only
when they form one block (a known class, the matching block name, a well-formed
video reference); otherwise it removes them all.
Page form (render time, in the page's language; internal/content-blocks.js):
each card is one link (g-block), with the icon set the template already owns.
A video is a poster (or a plain play card), a play button, the title and "Watch
on YouTube" as the no-JavaScript link to the provider's watch page. A bookmark
shows title, description and "Read on ", with the anchor rules every
absolute link gets (rel="noopener noreferrer", no target). A file shows its
title, description and "Download PDF (1.2 MB)". Feeds and email fragments carry
the stored card with the file link pointed at the emitted file.
Files. A file block's path must name a content[].media[] entry of
mediaType application/pdf (declared byteLength 1 to 10 MiB, sourceDigest
sha256:…) of the same document; otherwise the build fails with a
MEDIA_REFERENCE_UNRESOLVED diagnostic before anything is written. Each
referenced file is checked against its declared digest and length, must start
with %PDF-, and is copied as-is, once, to
assets/files/<name>.<first 8 hex of sha256>.pdf (media/files.js, as Listen
audio is) with one manifest asset row. The row's media type is
application/octet-stream because the artifact-manifest schema pinned here has
no application/pdf member. schemas 3.32.0 admits the PDF entry in
build-input; until it is pinned the template checks the entry itself
(internal/forward-compat.js) and leaves it out of the schema validation.
Click to play. A page that holds a video card loads
assets/gala-video-v1.js (defer, same origin). A plain tap replaces the card
with one <iframe> from https://www.youtube-nocookie.com/embed/<id> or
https://player.vimeo.com/video/<id> (loading="lazy",
referrerpolicy="strict-origin-when-cross-origin", allowfullscreen, a title
from the card). Until then the page loads nothing from either provider. The CSP
carries frame-src https://player.vimeo.com https://www.youtube-nocookie.com in
both forms (the <meta> and the complete header string); nothing else may be
framed, and no third-party script ever runs.
Galleries
Two or more adjacent image-only paragraphs in a post (Markdown: one image per
paragraph, or several images in one paragraph) are wrapped, when the page is
rendered, in <div class="g-gallery" data-count="N"> (N is the number of
images): a grid of two columns for two or three images, three for more, one
under 480 pixels. The stored body, the first-body-image choice, the feeds, the
search index and the llms files do not see the wrapper.
Recommendations
publication.recommendations (schemas 3.32.0; at most 24 items of
{url, title, description?, addedOn?}) renders a "Recommended by "
section of cards at the end of the About page (the publication profile page; a
site with no profile page shows none) and publishes
/.well-known/recommendations.json (joined with basePath like every fixed
output) as Ghost does: a bare JSON array of {url, created_at, updated_at},
both timestamps being addedOn at midnight UTC or else the build time. The
template validates the member itself (https addresses without credentials,
unique, a title of 1 to 120 characters, a description of up to 300, a real
YYYY-MM-DD day) and fails the build on anything else; with none, there is no
section and no file.
Comment likes, pinned comments and sort