wobblyhead hg > wobbly_ssg
view doc/format.md @ 0:71dd8d58a8e5 default tip
cleaned up re-init from net_wobblyhead_www project tooling
| author | ark |
|---|---|
| date | 2026-10-22 14:59 +0200 |
| parents | |
| children |
line wrap: on
line source
# Format This document describes everything a site author writes: the site layout, the configuration, the page sources and the templates. What the generator does with them is in [build.md](build.md). ## Site layout A site is a directory. The tools are run in it. - `config.txt` -- the site configuration. - `src/` -- the page sources, and the images and other files they reference. - `static/` -- files copied to the output as they are, which no page references: a favicon, `robots.txt`. - `tpl/` -- the templates and their assets: stylesheets, images, fonts. - `www/` -- the build directory, configurable. It is output, never input. - `dist/` -- archives written by `make_dist.sh`. The output tree mirrors the source tree. `src/notes/first_steps.md` becomes `www/notes/first_steps.html`, and an image next to it is placed next to the output. The generator creates only the directories it needs to mirror the source. `index.md` is an ordinary source with no special role. Where directory-style links are wanted, they have to be written out. Files from `static/`, from `tpl/` (all except `.html` files) and from `src/` all end up in the build directory. They must not overlap. All text files are UTF-8. The output is UTF-8. `.DS_Store` files are not copied. ## Site configuration `config.txt` uses the same format as the header block of a page, described below. It has no body. A missing `config.txt` is an error, and an unknown key produces a warning. Keys: - `site_url` -- required. The public address of the site, without a trailing slash. The absolute addresses in the page head are built from it. - `build_dir` -- the output directory. Defaults to `www`. - `image_sizes` -- symbolic image sizes, as a comma-separated list of `<name>:<width in pixels>` pairs. - `extra_header_keys` -- a comma-separated list of page header keys that should not produce a warning. - `index_sections` -- the sections of the root index page that `update_index.py` maintains. A comma-separated list of `<directory>:<heading>` pairs. See [tools.md](tools.md). - `index_recent` -- the number of entries in each of those sections. Defaults to 5. All values are available to templates with a `site.` prefix. Example: site_url: https://www.example.org build_dir: www image_sizes: small:300, half:400, wide:800 extra_header_keys: location index_sections: notes:Recent notes index_recent: 3 A change to `image_sizes` takes effect for existing images only after a clean build. ## Pages A page is a header block, a blank line and a body. A source that does not start with a header block is an error. Further blank lines between the header block and the body are ignored, and so are blank lines at the end of the file. A page with headers and no body produces an empty page and a warning. ### Header block Lines of `key: value`. The first blank line ends the block. A value is literal text to the end of the line. There is no quoting, nesting or list syntax. Long values are folded the way mail headers are (RFC 5322). A line that starts with a space or a tab continues the previous value, and the parts are joined with a single space. Leading whitespace is therefore significant in the header block: a continuation line that loses its indentation becomes an invalid header line. The order of keys does not matter. A duplicate key produces a warning, and the later value wins. Example: title: First steps subtitle: Notes from the first week, written down later tags: Notes, Model making created_at: 2026-03-01 updated_at: 2026-03-04 is_published: 1 ### Header keys `title` is the only required key. A page without a title is an error. Keys the generator acts on: - `title` -- the page title. The template uses it for the page heading. - `is_published` -- `1` publishes the page. Anything else, or no value, leaves it unpublished. Unpublished pages are only built in draft mode. - `tags` -- a comma-separated list of tags. Empty items are dropped. Each tag links to a tag index page, see [Tag index pages](#tag-index-pages). - `template` -- the file name of a template in `tpl/` to use instead of `page.html`. - `description` -- one or two sentences summarising the page, for search results and link previews. Without it, `subtitle` is used. - `image` -- the link preview image, as a path relative to the source. It is expected to be 1200x630 pixels. See [build.md](build.md). - `crossref` -- the path of a related page, relative to the source, like a link in the body. A `.md` extension is rewritten to `.html`, and the target is checked like a body link. A value with a scheme, such as `https:`, produces a warning and is passed on unchanged. - `created_at` -- an ISO date, `YYYY-MM-DD`, or an ISO date and time such as `2026-03-01T14:30:05+01:00`. Templates get the date as `dd.mm.yyyy`. - `updated_at` -- as `created_at`. The generator reads the dates only to format them and to sort tag index pages. A time is accepted and not shown. The date is shown as written, without converting the time zone. A value that is not a valid ISO date produces a warning and is shown as written. The accepted forms are those of Python's `datetime.fromisoformat`, which accepts more of them from Python 3.11 on. Known keys without defined format, passed to templates as they are: - `subtitle` -- a one-line summary. - `timeframe` -- a period, as free text, such as `03.2024 - 06.2025`. - `repository` -- the address of the source repository of a project. - `todo` -- notes for the author. Any other key is passed to templates as well, and produces a warning unless it is listed in `extra_header_keys`. The warning only catches typos in keys that are known. ### Body The body is Markdown, processed by python-markdown with two extensions: - `extra` -- abbreviations, attribute lists, definition lists, fenced code, footnotes, Markdown inside HTML, and tables. - `sane_lists`. The top-level heading comes from the `title` header through the template. The body usually starts at the second level. HTML in the body is passed through. Links and images in it are handled like those written in Markdown, as long as attributes are in double quotes. ### Links Paths are relative to the source file. A link to another page can use the `.md` extension, which is rewritten to `.html`, or the `.html` extension directly. Fragments and query strings are kept. A `.md` link that points nowhere is still rewritten. A link to a file that is neither a page nor an image, such as a PDF or an archive, copies that file to the mirrored output path. Links with a scheme, such as `https:` or `mailto:`, and protocol-relative links are left alone. All other links are checked, see [build.md](build.md). ### Tables Standard pipe tables. Outer pipes are optional. | Year | Model | Scale | |------|------------|------:| | 2024 | Tug | 1:50 | | 2025 | Lighthouse | 1:87 | Alignment markers produce an inline `text-align` style on every cell. Attribute lists cannot be attached to tables, so all tables share one style. Where Markdown cannot express a table, it can be written in HTML. ### Footnotes A reference is `[^label]` in the text. A definition is `[^label]:` at the start of a line, followed by the text. The label identifies the note and can be any string without whitespace; it is not the printed number. Further paragraphs of a note are indented by four spaces. The hull was planked twice.[^planks] [^planks]: The first planks were too thick. Notes are numbered in the order of their definitions, not of their references. Putting each definition right after the paragraph that refers to it keeps the two orders the same. A definition without a reference is still printed and numbered. A reference without a definition stays in the text as written, without a warning. The notes are collected at the end of the body in a `div` of class `footnote`. The generator passes them to the template separately, as `footnotes`. The generated ids are `fn:` and `fnref:` followed by the label; they share the id space of the page. ### Images An image is standard Markdown, with the path relative to the source file:  The output gets `width` and `height` attributes, see [build.md](build.md). #### Sizes A smaller copy of an image is requested in the file name, by putting a size between the name and the extension:   The size is either a width in pixels or a name from `image_sizes`. The height follows from the aspect ratio. If `hull.800.jpg` exists as a file, it is copied as it is, and no copy is generated. PNG and JPEG can be scaled, and WebP where Pillow supports it. Other formats, SVG among them, are only copied. #### Layout classes An attribute list adds classes, which the stylesheet defines: {: .right } Class names are not checked. How an image without a class is shown is up to the stylesheet. #### Captions The title of an image becomes its caption when the image is alone in its paragraph:  The paragraph becomes a `figure` with a `figcaption` below the image. The title attribute is removed, so the caption does not also appear as a tooltip. Classes move from the image to the figure, so a floated image takes its caption along. An image with a title inside running text keeps the title as a tooltip. #### Linking to the original A thumbnail linked to the original is the nested Markdown construct: [](hull.jpg) The inner reference generates the smaller copy, the outer link copies the original. An original that is only used for smaller copies is not copied to the output. An attribute list attaches to the thumbnail, and a title makes a caption as above: [{: .right }](hull.jpg) ## Templates `tpl/` holds the template set: one or more HTML templates and their assets, which may be in subdirectories. Everything in `tpl/` except `.html` files is copied to the build directory, keeping its relative path. - `page.html` is the default page template. The `template` header selects another one. - `tag.html` renders the tag index pages. Error pages, such as a 404 page, are ordinary pages. ### Markers A marker is replaced with a value: <h1>{{title}}</h1> <p>{{site.site_url}}</p> A marker is `{{`, a key, optionally a `|` and a filter name, and `}}`, with no spaces. Anything else is left as it is, including a stray `{{`. There is no way to escape a well-formed marker. Rendered values are not scanned for markers or blocks again. A marker for an undefined value renders as an empty string and produces a warning. A marker with an unknown filter, and a marker for a list value, are errors. ### Filters Values are HTML-escaped by default. - `{{key|htmlencode}}` -- HTML-escaped. This is the default, written out. - `{{key|literal}}` -- not escaped. Needed for `body` and `footnotes`. - `{{key|urlencode}}` -- URL-encoded, including `/`. ### Blocks A condition renders its content only when the condition holds: {% if subtitle|isnotempty %}<p class="subtitle">{{subtitle}}</p>{% endif %} Conditions: - `isempty` -- the value is undefined, an empty string or an empty list. - `isnotempty` -- the opposite. An unknown condition is an error. A condition on an undefined value does not produce a warning. A loop renders its content once for every item in a list: {% loop tags %}<li><a href="{{url}}">{{name}}</a></li>{% endloop %} The list has to be a list of dictionaries. Inside the loop only the keys of the current item are available; page values such as `relRoot` are not. A loop over an undefined value renders nothing and produces a warning. A loop over anything other than a list of dictionaries is an error, and so is a condition on a loop. A block cannot contain another block of its own kind, at any depth: the inner end tag would close the outer block. A condition inside a loop, or a loop inside a condition, works. A block tag that is not part of a complete block is an error. ### Page values - `site.<key>` -- every key of the site configuration. - Every header of the page, under its own name. Headers the page does not set are undefined. - `body` -- the HTML of the body, without the footnotes. Use with `literal`. - `footnotes` -- the footnotes `div`, or empty. Use with `literal`. A template without it drops the footnotes. - `tags` -- the tags of the page, as a list of items with `name` and `url`. The address is relative to the page. Empty for a page without tags. - `crossrefUrl` -- the `crossref` header as an address relative to the page, with `.md` rewritten to `.html`. Empty without the header. - `relRoot` -- the relative path from the page to the site root, ending in a slash. `./` at the top level. For links to assets and other pages. - `absRoot` -- `/`. For error pages, which the server delivers at other addresses than their own. - `pageUrl` -- the absolute address of the page. An `index.html` is addressed by its directory, ending in a slash. - `metaDescription` -- the `description` header, or `subtitle` without one, or empty. - `createdDate`, `updatedDate` -- the dates of `created_at` and `updated_at` as `dd.mm.yyyy`. Empty without the header. `updatedDate` is also empty when it is the same date as `createdDate`. - `ogImage`, `ogImageWidth`, `ogImageHeight`, `ogImageAlt` -- the link preview image: its absolute address, its size in pixels, and the alt text of the image it was cut from. Undefined when there is no preview image; the template then names its own default or none. See [build.md](build.md). ### Tag index pages Tag index pages have no source. They are written to the build root as `tag_<name>.html`. The name is the tag in lower case, with everything other than the letters a to z and digits removed: "Model making" becomes `tag_modelmaking.html`. Tags that differ only in case, spaces or punctuation share one page. A source with the same name as a tag index page collides with it. Values for `tag.html`: - `site.<key>` -- as for pages. - `tag` -- the tag. Where several spellings share a page, the first one found. - `relRoot` -- always `./`. `absRoot` -- `/`. - `pageUrl` -- the absolute address of the tag index page. - `pages` -- the pages with this tag, newest first by `created_at`, then by title. Pages without `created_at` come last. Each item has the headers of its page except `tags`, plus: - `url` -- the address of the page, relative to the build root. It replaces a header of the same name. - `descOrSubtitle` -- the `description` header, or `subtitle` without one, or empty. A header that a page does not set is undefined in its item, and a marker for it produces a warning. Optional headers belong in a condition. ### Stylesheets Every local image in the output has `width` and `height` attributes. A stylesheet that limits the width of images has to set `height: auto`.
