diff doc/build.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 diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/build.md	Thu Oct 22 14:59:43 2026 +0200
@@ -0,0 +1,201 @@
+# How a build works
+
+This document describes what `make_site.py` does. Its command line is in
+[tools.md](tools.md), the formats it reads are in [format.md](format.md).
+
+## Order of work
+
+1. Read `config.txt`. Create the build directory, after emptying it if a
+   clean build was asked for.
+2. Copy the files of `static/` and the non-HTML files of `tpl/` that are
+   newer than their copies in the build directory.
+3. Build each selected page, by default every `.md` file below `src/`:
+    - Skip the page if its output exists and is not older than the source.
+    - Read the header block. Skip an unpublished page, unless draft mode is
+      on.
+    - Convert the Markdown body to HTML.
+    - Rewrite links, copy referenced files, place images and add their
+      dimensions, turn captioned images into figures.
+    - Split off the footnotes.
+    - Pick the link preview image and write it if needed.
+    - Render the template and write the page.
+4. Write the tag index pages, if they are being rebuilt.
+5. Check the links of all pages built in this run.
+
+Tag index pages are rebuilt with `--tags`, and always with `--clean`. Then
+the header block of every selected page is read before the date check, so
+pages that are up to date are listed too.
+
+Output paths mirror source paths. The build directory is `build_dir` from
+`config.txt`, or the directory given with `--build-dir`.
+
+## Incremental builds
+
+Without `--clean`, the build compares modification times only: a page with
+its source, a generated image with its original, a copied file with its
+source. Nothing else is tracked, and nothing is removed. As a result:
+
+- A changed template or configuration rebuilds nothing.
+- A page that is unpublished or deleted keeps its old output.
+- Link preview images from earlier versions of an image stay.
+
+A clean build fixes all of these, and is the normal way to build for
+publishing.
+
+## Unpublished pages
+
+A page without `is_published: 1` is skipped with a warning. In draft mode,
+`--draft`, it is built, and the warning says so.
+
+## Reporting
+
+Messages have three severities. All of them go to standard error.
+
+- Error -- no correct output is possible. The build stops. Examples: a
+  missing `config.txt` or `site_url`, a source that does not start with a
+  header block, a page without a title, a missing template, a template
+  syntax error.
+- Warning -- output is produced but is probably wrong. Examples: a broken
+  link, an unknown image size, an unknown or duplicate header key, an unknown
+  configuration key, an original smaller than the size asked for, a skipped
+  unpublished page, a page rendered as a draft, a page with no body, two
+  spellings of a tag sharing one index page, a date that is not an ISO date,
+  an `image` header that points nowhere or at an image that is not 1200x630,
+  an image that cannot be cropped for the link preview.
+- Notice -- normal events. A page skipped because it is up to date, an image
+  copied or generated, a tag index page written with its tag and number of
+  pages, a link preview image generated or found up to date.
+
+Errors and warnings are printed by default. `--quiet` prints errors only.
+`--verbose` adds notices.
+
+The summary counts the files created and updated, the images generated and
+the warnings. When tag index pages were written, a second line lists their
+tags. The summary goes to standard output, with `--report` or `--verbose`.
+
+The exit code is 0 on success, 1 when an error stopped the build, and 2 for
+a usage error. Warnings do not change the exit code.
+
+## Images
+
+### Resolving a reference
+
+An image reference names either a file in the source tree or a smaller copy
+to be generated:
+
+1. If the path exists as a source file, it is copied as it is.
+2. Otherwise, for formats that can be scaled, the last dot-separated part
+   before the extension is taken as a size. If the name without that part
+   exists, the copy is generated from it.
+3. Otherwise the reference is broken and produces a warning.
+
+A size that is neither a number nor a name from `image_sizes` produces a
+warning, and the original is copied under the requested name.
+
+Each output file is placed once per build. Further references to it, from the
+same page or another, are not checked or reported again. A broken reference
+produces a warning on every page that has it.
+
+### Formats
+
+PNG and JPEG can be scaled. WebP can be scaled where the local Pillow
+supports it, so the same site can build differently on another machine. An
+MPO file, a JPEG with further images appended as some cameras write it, is
+treated as a JPEG.
+
+The format is read from the content of the original. A PNG named `.gif` is
+handled as a PNG, and its scaled copy is written as a PNG too, whatever the
+extension says.
+
+### Scaled copies
+
+Only the width is given; the aspect ratio is kept. The image is resampled
+with the Lanczos filter.
+
+A scaled copy keeps the colour profile of the original. The Exif orientation
+is applied to the pixels first, then the Exif data is dropped. JPEG copies
+are written at quality 85; other formats use the Pillow defaults.
+
+An original narrower than the requested width is not scaled up. It is copied
+unchanged under the requested name, with all its metadata, and the build
+produces a warning.
+
+### Dimensions
+
+Every local `img` in a page body, from Markdown or from HTML, gets `width`
+and `height` attributes from the file that was placed. Images that already
+have a `width` attribute, and images Pillow cannot open, such as SVG, are
+left alone.
+
+## Link preview
+
+### The image
+
+The preview image of a page is picked in this order:
+
+1. The `image` header. An image of exactly 1200x630 is copied. Any other size
+   is cropped as described below, with a warning. A header that points
+   nowhere produces a warning, and the search goes on.
+2. The first local image in the body that can be scaled and whose original is
+   at least 600x315. The original is used, not the scaled copy the page
+   shows. Its alt text becomes the alt text of the preview.
+3. None. The template names a default image, or writes no image tags.
+
+600x315 is the smallest size Facebook still shows as a large card.
+
+Cropping cuts the largest centred area with an aspect ratio of 1200:630 out
+of the image. If that area is larger than 1200x630, it is scaled down to that
+size; it is never scaled up. A portrait photo loses its top and bottom. Where
+that cuts off the subject, a prepared image in the `image` header avoids it.
+The preview keeps the format and colour profile of the original and loses
+its Exif data, like a scaled copy.
+
+The image is written next to the page output, in the directory `img`, as
+`og_<source name>_<modification time><extension>`. For `first_steps.md` with
+a JPEG this is, for example, `img/og_first_steps_1772371200.jpg`. The
+modification time is that of the original image, in whole seconds since
+1970. Consumers cache preview images by address, so a changed image gets a
+new address. An existing file of that name is not written again.
+
+### Page head
+
+The generator supplies the values; the templates write the tags. The example
+template writes:
+
+- `meta name="description"` from `metaDescription`
+- `link rel="canonical"` from `pageUrl`
+- `og:type` (`website`), `og:site_name`, `og:title`, `og:description`,
+  `og:url`
+- `og:image`, `og:image:width`, `og:image:height`, `og:image:alt`
+- `twitter:card` (`summary_large_image`)
+
+The addresses are absolute and built from `site_url`. A page named
+`index.html` is addressed by its directory: `src/index.md` becomes
+`https://www.example.org/`, not `https://www.example.org/index.html`. A
+server delivers the same page either way, but consumers treat the two
+addresses as two pages.
+
+## Tag index pages
+
+There is one tag index page per tag, in the build root. It lists only pages
+selected for this build and rendered: published pages, and unpublished ones in
+draft mode. A build of part of the site therefore writes incomplete tag index
+pages, and they replace complete ones from an earlier build. Tag index pages
+are always written, without a date check.
+
+## Link checking
+
+Links are checked after all pages have been written. A link is valid if its
+target exists in the build directory, so pages built later in the same run
+count.
+
+Only internal links are checked: links in the body, image references, and
+the `crossref` header.
+
+Unpublished pages are not built, so a link to one produces a warning, as
+does a link to a file that does not exist. In draft mode these warnings
+disappear.
+
+When only part of the site is built, only the links of the selected pages
+are checked. Targets left from an earlier build count as present. Built into
+a clean directory, a subset produces warnings for every link outside it.