# Design notes

## Requirements

The generator was written for a personal site. It is mostly a gallery of
projects, with posts and links to other sites. Pages have tags, and the tags
are the navigation. Links to the site get shared, so pages need link preview
metadata. There are no comments and no other dynamic parts. The site is
updated about once a week at most.

The toolchain avoids Node.js and npm. Python with python-markdown and Pillow
is the whole dependency list. The build runs on the author's machine, and only
the finished output goes to the server.

The images are mostly JPEG photos from a phone, plus screenshots. They
document things; fidelity is not a goal. They do need the right orientation,
no location data in the published copies, and screenshots have to stay
legible.

Because the site changes rarely, few moving parts matter more than build
speed. Whoever comes back to it after months has to be able to read the whole
generator.

## Decisions

### Clean builds

The normal workflow is a clean build, followed by replacing the whole
published site with an archive of the output. Incremental builds are a
convenience during writing. They only compare the dates of sources and
outputs, and they never remove files. See [build.md](build.md).

### Header blocks

A page starts with `key: value` lines, folded like mail headers. This is not
YAML: there is no quoting, no nesting and no fence. Every value is a string.
The site configuration uses the same format.

Unknown header keys are passed to the templates and produce a warning. The
warning catches typos. It does not restrict what keys a site may use: a key
stops warning once it is listed in the configuration.

### Mirrored paths

The output tree mirrors the source tree. The generator creates no directories
of its own and gives `index.md` no special role. Navigation and directory
indexes are written by hand, or kept up to date with `update_index.py`.

### Errors and warnings

An error stops the build. It is used only where no correct output is possible,
such as a page without a title. Everything else produces output and a
warning: broken links, unknown sizes, unknown keys. A build with warnings
still exits successfully.

### Markdown

python-markdown with the `extra` bundle and `sane_lists`. `smarty` is off,
so quotes and dashes stay as written.

### Images

Image sizes are requested in the file name of the reference, such as
`photo.800.jpg`, so the Markdown stays standard. The original is the name
without that part.

The format of an image is decided by its content, not by its extension. A
generated image keeps the format of its original. There is no format
conversion.

Phone photos may be stored sideways, with the rotation recorded only in the
Exif (Exchangeable Image File Format) data. Generated images have the rotation
applied to their pixels and contain no Exif data, so location and camera
details are not published. They keep the colour profile of the original,
because phone cameras record in a wider colour space than sRGB. Images are
never scaled up.

Files referenced verbatim, including the originals behind linked thumbnails,
are copied unchanged with all their metadata.

### Link previews

Services that show a preview card for a shared link read tags in the page
head. There is no standard all of them follow. Most read the Open Graph tags,
X wants its own `twitter:card` tag, and search engines read the description
meta tag. Each one crops, sizes and caches the image in its own way. The
generator aims at a common set of tags that most of them understand.

The generator supplies the values; the templates write the tags. Preview
images are cut to 1200x630, the size Facebook and LinkedIn ask for.

Consumers fetch a page on their own, so the canonical address and the image
address are absolute. They are built from the production address in the
configuration. `make_dist.sh` replaces it in a copy of the output when an
archive is meant for another address, such as a test server.

### Templates

Templates are plain HTML with value markers and two kinds of block: a
condition and a loop. Blocks of the same kind cannot be nested. Values are
HTML-escaped unless a filter says otherwise.

### Accepted limitations

- A file name with dots can be read as a size request. A reference to
  `my.photo.png` with no such file present is taken as a request for size
  `photo` of `my.png`.
- Building a subset of the site into a clean directory produces link
  warnings for everything outside the subset, and incomplete tag index pages.
- Files from `static/`, `tpl/` and `src/` are copied into one tree. Nothing
  detects one of them overwriting another.
- A changed template or configuration does not cause a rebuild. A clean
  build does.
