wobblyhead hg > wobbly_ssg
comparison 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:71dd8d58a8e5 |
|---|---|
| 1 # How a build works | |
| 2 | |
| 3 This document describes what `make_site.py` does. Its command line is in | |
| 4 [tools.md](tools.md), the formats it reads are in [format.md](format.md). | |
| 5 | |
| 6 ## Order of work | |
| 7 | |
| 8 1. Read `config.txt`. Create the build directory, after emptying it if a | |
| 9 clean build was asked for. | |
| 10 2. Copy the files of `static/` and the non-HTML files of `tpl/` that are | |
| 11 newer than their copies in the build directory. | |
| 12 3. Build each selected page, by default every `.md` file below `src/`: | |
| 13 - Skip the page if its output exists and is not older than the source. | |
| 14 - Read the header block. Skip an unpublished page, unless draft mode is | |
| 15 on. | |
| 16 - Convert the Markdown body to HTML. | |
| 17 - Rewrite links, copy referenced files, place images and add their | |
| 18 dimensions, turn captioned images into figures. | |
| 19 - Split off the footnotes. | |
| 20 - Pick the link preview image and write it if needed. | |
| 21 - Render the template and write the page. | |
| 22 4. Write the tag index pages, if they are being rebuilt. | |
| 23 5. Check the links of all pages built in this run. | |
| 24 | |
| 25 Tag index pages are rebuilt with `--tags`, and always with `--clean`. Then | |
| 26 the header block of every selected page is read before the date check, so | |
| 27 pages that are up to date are listed too. | |
| 28 | |
| 29 Output paths mirror source paths. The build directory is `build_dir` from | |
| 30 `config.txt`, or the directory given with `--build-dir`. | |
| 31 | |
| 32 ## Incremental builds | |
| 33 | |
| 34 Without `--clean`, the build compares modification times only: a page with | |
| 35 its source, a generated image with its original, a copied file with its | |
| 36 source. Nothing else is tracked, and nothing is removed. As a result: | |
| 37 | |
| 38 - A changed template or configuration rebuilds nothing. | |
| 39 - A page that is unpublished or deleted keeps its old output. | |
| 40 - Link preview images from earlier versions of an image stay. | |
| 41 | |
| 42 A clean build fixes all of these, and is the normal way to build for | |
| 43 publishing. | |
| 44 | |
| 45 ## Unpublished pages | |
| 46 | |
| 47 A page without `is_published: 1` is skipped with a warning. In draft mode, | |
| 48 `--draft`, it is built, and the warning says so. | |
| 49 | |
| 50 ## Reporting | |
| 51 | |
| 52 Messages have three severities. All of them go to standard error. | |
| 53 | |
| 54 - Error -- no correct output is possible. The build stops. Examples: a | |
| 55 missing `config.txt` or `site_url`, a source that does not start with a | |
| 56 header block, a page without a title, a missing template, a template | |
| 57 syntax error. | |
| 58 - Warning -- output is produced but is probably wrong. Examples: a broken | |
| 59 link, an unknown image size, an unknown or duplicate header key, an unknown | |
| 60 configuration key, an original smaller than the size asked for, a skipped | |
| 61 unpublished page, a page rendered as a draft, a page with no body, two | |
| 62 spellings of a tag sharing one index page, a date that is not an ISO date, | |
| 63 an `image` header that points nowhere or at an image that is not 1200x630, | |
| 64 an image that cannot be cropped for the link preview. | |
| 65 - Notice -- normal events. A page skipped because it is up to date, an image | |
| 66 copied or generated, a tag index page written with its tag and number of | |
| 67 pages, a link preview image generated or found up to date. | |
| 68 | |
| 69 Errors and warnings are printed by default. `--quiet` prints errors only. | |
| 70 `--verbose` adds notices. | |
| 71 | |
| 72 The summary counts the files created and updated, the images generated and | |
| 73 the warnings. When tag index pages were written, a second line lists their | |
| 74 tags. The summary goes to standard output, with `--report` or `--verbose`. | |
| 75 | |
| 76 The exit code is 0 on success, 1 when an error stopped the build, and 2 for | |
| 77 a usage error. Warnings do not change the exit code. | |
| 78 | |
| 79 ## Images | |
| 80 | |
| 81 ### Resolving a reference | |
| 82 | |
| 83 An image reference names either a file in the source tree or a smaller copy | |
| 84 to be generated: | |
| 85 | |
| 86 1. If the path exists as a source file, it is copied as it is. | |
| 87 2. Otherwise, for formats that can be scaled, the last dot-separated part | |
| 88 before the extension is taken as a size. If the name without that part | |
| 89 exists, the copy is generated from it. | |
| 90 3. Otherwise the reference is broken and produces a warning. | |
| 91 | |
| 92 A size that is neither a number nor a name from `image_sizes` produces a | |
| 93 warning, and the original is copied under the requested name. | |
| 94 | |
| 95 Each output file is placed once per build. Further references to it, from the | |
| 96 same page or another, are not checked or reported again. A broken reference | |
| 97 produces a warning on every page that has it. | |
| 98 | |
| 99 ### Formats | |
| 100 | |
| 101 PNG and JPEG can be scaled. WebP can be scaled where the local Pillow | |
| 102 supports it, so the same site can build differently on another machine. An | |
| 103 MPO file, a JPEG with further images appended as some cameras write it, is | |
| 104 treated as a JPEG. | |
| 105 | |
| 106 The format is read from the content of the original. A PNG named `.gif` is | |
| 107 handled as a PNG, and its scaled copy is written as a PNG too, whatever the | |
| 108 extension says. | |
| 109 | |
| 110 ### Scaled copies | |
| 111 | |
| 112 Only the width is given; the aspect ratio is kept. The image is resampled | |
| 113 with the Lanczos filter. | |
| 114 | |
| 115 A scaled copy keeps the colour profile of the original. The Exif orientation | |
| 116 is applied to the pixels first, then the Exif data is dropped. JPEG copies | |
| 117 are written at quality 85; other formats use the Pillow defaults. | |
| 118 | |
| 119 An original narrower than the requested width is not scaled up. It is copied | |
| 120 unchanged under the requested name, with all its metadata, and the build | |
| 121 produces a warning. | |
| 122 | |
| 123 ### Dimensions | |
| 124 | |
| 125 Every local `img` in a page body, from Markdown or from HTML, gets `width` | |
| 126 and `height` attributes from the file that was placed. Images that already | |
| 127 have a `width` attribute, and images Pillow cannot open, such as SVG, are | |
| 128 left alone. | |
| 129 | |
| 130 ## Link preview | |
| 131 | |
| 132 ### The image | |
| 133 | |
| 134 The preview image of a page is picked in this order: | |
| 135 | |
| 136 1. The `image` header. An image of exactly 1200x630 is copied. Any other size | |
| 137 is cropped as described below, with a warning. A header that points | |
| 138 nowhere produces a warning, and the search goes on. | |
| 139 2. The first local image in the body that can be scaled and whose original is | |
| 140 at least 600x315. The original is used, not the scaled copy the page | |
| 141 shows. Its alt text becomes the alt text of the preview. | |
| 142 3. None. The template names a default image, or writes no image tags. | |
| 143 | |
| 144 600x315 is the smallest size Facebook still shows as a large card. | |
| 145 | |
| 146 Cropping cuts the largest centred area with an aspect ratio of 1200:630 out | |
| 147 of the image. If that area is larger than 1200x630, it is scaled down to that | |
| 148 size; it is never scaled up. A portrait photo loses its top and bottom. Where | |
| 149 that cuts off the subject, a prepared image in the `image` header avoids it. | |
| 150 The preview keeps the format and colour profile of the original and loses | |
| 151 its Exif data, like a scaled copy. | |
| 152 | |
| 153 The image is written next to the page output, in the directory `img`, as | |
| 154 `og_<source name>_<modification time><extension>`. For `first_steps.md` with | |
| 155 a JPEG this is, for example, `img/og_first_steps_1772371200.jpg`. The | |
| 156 modification time is that of the original image, in whole seconds since | |
| 157 1970. Consumers cache preview images by address, so a changed image gets a | |
| 158 new address. An existing file of that name is not written again. | |
| 159 | |
| 160 ### Page head | |
| 161 | |
| 162 The generator supplies the values; the templates write the tags. The example | |
| 163 template writes: | |
| 164 | |
| 165 - `meta name="description"` from `metaDescription` | |
| 166 - `link rel="canonical"` from `pageUrl` | |
| 167 - `og:type` (`website`), `og:site_name`, `og:title`, `og:description`, | |
| 168 `og:url` | |
| 169 - `og:image`, `og:image:width`, `og:image:height`, `og:image:alt` | |
| 170 - `twitter:card` (`summary_large_image`) | |
| 171 | |
| 172 The addresses are absolute and built from `site_url`. A page named | |
| 173 `index.html` is addressed by its directory: `src/index.md` becomes | |
| 174 `https://www.example.org/`, not `https://www.example.org/index.html`. A | |
| 175 server delivers the same page either way, but consumers treat the two | |
| 176 addresses as two pages. | |
| 177 | |
| 178 ## Tag index pages | |
| 179 | |
| 180 There is one tag index page per tag, in the build root. It lists only pages | |
| 181 selected for this build and rendered: published pages, and unpublished ones in | |
| 182 draft mode. A build of part of the site therefore writes incomplete tag index | |
| 183 pages, and they replace complete ones from an earlier build. Tag index pages | |
| 184 are always written, without a date check. | |
| 185 | |
| 186 ## Link checking | |
| 187 | |
| 188 Links are checked after all pages have been written. A link is valid if its | |
| 189 target exists in the build directory, so pages built later in the same run | |
| 190 count. | |
| 191 | |
| 192 Only internal links are checked: links in the body, image references, and | |
| 193 the `crossref` header. | |
| 194 | |
| 195 Unpublished pages are not built, so a link to one produces a warning, as | |
| 196 does a link to a file that does not exist. In draft mode these warnings | |
| 197 disappear. | |
| 198 | |
| 199 When only part of the site is built, only the links of the selected pages | |
| 200 are checked. Targets left from an earlier build count as present. Built into | |
| 201 a clean directory, a subset produces warnings for every link outside it. |
