Staticsite itself
Got far enough into staticsite
that it was time to go beyond the
basic blog, and the ice cream blog turns
out to be a good testbed for that.
Fix the images
Images (specifically, jpg
files from cameras or modern cellphones)
are, by default, large and messy, despite staticsite
doing clever
things with img.srcset
. It turns out that there's a stack of
problems:
- ImageMagick
convert
doesn't update (or discard)EXIF.width
andEXIF.height
when resizing, and later parts of the toolchain (probably including the browser itself) get mislead by small images with large dimensions. - Certain parts of the
staticsite
markdown processing path end up giving absolute instead of relative links to the produced images (still looking for where though) and so if you make a local sandbox copy of the main site, some of theimg
files that the browser fetches actually come from the upstream live site instead of the sandbox, completely confusing your debugging process. - I really want the images to use bootstrap's
img-fluid
which I can add using the markdown "attributes" extension, which is already turned on, but I want it consistently site wide.
On top of that, it may turn out that the part of the problem I care
about needs to be fixed in the python-markdown
layer instead of
staticsite
itself, but it may just be "non-overridable python code"1
rather than something I even can fix in a theme.
Current solutions:
- github ticket #70
filed to describe the
<img>
problem and hostname part. - Use the
python-markdown
attribute extension{: class="img-fluid"}
manually on all images, so that they scale-to-fit regardless of what processing they've been through. - Wrote a little
icecream-start shop-name
that takeskpa-grep
output and fills in a blank markdown file with a title and filled in![]()
image includes for each image (so I can write the article and just delete the unneeded images as I go along - which will work better once#70
is fixed, for now half of the images go upstream instead of locally.) - Bigger hammer:
icecream-start
now usesjhead -autorot -purejpg
2 which just rotates them losslessly and wipes out any conflicting EXIF metadata. This, combined withimg-fluid
and a width-clamp insite.css
were the minimal "image-heavy pages are actually good now" set of changes.
Finish taxonomy support
staticsite
has Hugo-style taxonomies (to the point of linking to
them for documentation.) It does a fine job building index pages, but
stops there. The two followons to make them useful are
- Link those index pages in the navbar (or the sidebar, but for
photo-heavy mobile use I find that the sidebar is an utter failure,
so my first template effort was to turn that off and use full
width ("12 column" in
bootstrap
terms) - The default page templates include the tags at the bottom, but only if they're from the tags taxonomy. Turns out we can just iterate over the available taxonomies and render all of them.
Current solutions:
- navbar config is one line in the
index.md
metadata, done. - replacing the "tags for this article" with "all tags for all taxonomies for this article" was some simple nested loops in Jinja2, once I got past the scoping problem below.
A future possibility is to add some markup (possibly subverting the
wikilinks
syntax, or maybe just using links with a magic urltype) that lets me
just use the tags in-line in the text without having to put them in
the per-post metadata. (Future, not blocking for now, and ideally it
would just be a hook into the same taxonomy
plumbing.)
The template changes ran into some issues:
- Jinja2 macros are file scoped, so an attempt to replace a single
macro (like
inline_page
as called bypages
) is silently ignored, instead you need to replace the entire file including the otherwise unchanged calling macro (at which point you might consider giving up on extending the existing theme in the first place.) - Some of the
ssite
subcommands will parse a.staticsite.py
orsettings.py
in the top level of the site source, which would let you configure a theme; important ones likessite show
ignore that entirely and require a--theme
argument. - For a while this looked like "syntactically bad themes (or settings) were silently not imported"; that turns out not to be true, it just wasn't importing them at all because the config was ignored instead.
- The existing settings aren't actually in-scope in the settings file, though you may be able to import the global settings it's not clear that those are the correct ones after other processing.
- Some of the data structures visible in the template act like strings
but aren't strings - so for example, you can iterate over the
taxonomies, and if you render that inline you get the names, but you
can't then get the taxonomy from there because you end up
attempting to use the object as a key and not the name. On top of
that, python code in jinja2 templates has very limited access to
python builtins - so you don't have
dir
orstr
(though you can simulate the latter with"" ~ var
, it's not great.) Turns out that most of these objects have a.name
you can use directly, but I haven't found good documentation for that - but at this point, I recognize it as a pattern, so "just try.name
" is part of my experimentation repertoire.
System dark mode
blag
had what turns out to be really simple bits of CSS3 for a dark
mode that turns on when the browser is in dark mode (usually triggered
by "system" darkmode, through xsettings
and GTK themes.) It's worth
adding that to the staticsite
theme if we can do it in a simple way.
Current solutions:
- Within the theme directory,
static/css/*.css
get installed, so just copy the defaultsite.css
there and add extra files that it explicitly@include
's. - Specifically,
@import "bootstrap-color-fix.css" screen and (prefers-color-scheme: dark);
isolates all of the horror - so providing a color mode is only one mechanical line of CSS. - To create that file, just copy
/usr/share/javascript/bootstrap4/css/bootstrap.css
(include attribution comments, it is MIT licensed) and delete everything that isn't a color, which gets it down to about 700 entries; then cook up a little elisp to "invert" a color string in the buffer. Yes, this is gruesomely brute force - but it's short term: bootstrap 5.3 has proper dark-mode support built in, so whenstaticsite
upgrades (not something I'm prepared to tackle myself right now1) we can just discard these changes and use that support instead. (I don't actually want any in-page controls for this, just automatic support for the viewer's system or in-browser choices.)
More markdown extensions
It's a little messy to even turn on extensions; the documentation
(doc/reference/pages/markdown.md
) says you can set
MARKDOWN_EXTENSIONS
but it doesn't actually say where and see the
problem above about things ignoring settings.py
.
Aside from
wikilinks
for in-line taxonomy reference,
I'd like to turn on whatever makes bare URLs into links;
SO
suggests just using <>
which I'd forgotten, but also gives both a
(mildly flawed) sample extension for it and a pointer to
markdown2
which has
link-patterns
as a mechanism for this.
Geography
Saw Simon Willison's experiments with OpenFreeMap and MapLibre and realized it would be really easy to lay out my Ice Cream Journey on it. Not sure it's worth actually hosting an entire tileset (when by definition I only need Massachusetts), and later on I might just stash maps at various static zoom levels or something simple like that. For now, though, it's responsive and doesn't need an API key, and the Javascript interface is straightforward.
In fact, my use of the interface is probably too straightforward -
rather than being generated from page metadata, there's just a
hard-coded list of Names, markdown page names, and lat/long pairs, and
two dozen lines of code to forEach
the place list and create a
maplibregl.Marker
attached to a maplibregl.Popup
for each; through
the glory of Unicode, we can even have 🍨 markers for general ice
cream and 🍦 for places that specialize in soft-serve. That all works
fine, the only manual step is adding a single line of data to the
map.html
file for every review I do - technically moving it into
per-page metadata wouldn't be less work, or more robust in any way,
but it feels like the right place for it, so I'll get to that
eventually.
Since this is still an experiment, I didn't want to just have "Map" in
the navbar, I wanted a specific experimental marker in the title. The
definition of the navbar is just a list in the metadata of index.md
itself, but the titles are expected to be in the metadata of each of
those pages - the main trick here is that raw html files aren't,
they're actually J2Page
Jinja2 templates, so you can stuff a {%
block front_matter %}
inside an HTML comment, and that works as a
clean way to hide the metadata.4
Page Width
One final issue (and one of the only design aspects I've gotten feedback about from readers5) is that on a wide screen, the pictures are too huge and the text ends up ridiculously wide. It took decades but the web design industry did realize that the newspaper industry's use of narrow columns was good for reading,6 but Bootstrap itself doesn't appear to have any useful defaults for this (or even any good stackoverflow answers.) All it needs is
@media (min-width: 40em) {
.container-fluid {
width: 40em;
}
}
(adjust 40em
to taste, but probably keep it in character-width
units to stay consistent with other user preference choices.) All
this declares is that if the screen is 40em
wide or larger, set
the outermost bootstrap container width to 40em
; this keeps smaller
size layouts unchanged, and breaks smoothly as you get larger.
-
It's open source python code, everything is overridable, but for me it's a big step towards just writing a new engine (or adding these features to one of my old ones) which I'm specifically shying away from in this moment. ↩↩
-
github:Matthias-Wandel/jhead, yes, that Matthias Wandel of youtube woodworking fame. ↩
-
See blag
style.css
for theprefers-color-scheme
conditionals in@media
stanzas; a mere 8 lines for each scheme. ↩ -
Both of them! Dark mode, on the other hand, was entirely implemented for me personally, and worth the effort to get working when I was still looking at the site in draft, regardless of anyone else ever seeing it. ↩
-
Even though it had very little to do with that and was more of an artifact of how to assemble type in frames for printing, up through linotype and phototypesetting in column inches that were literally pasted up. ↩