Date-Stamped Celestial Images
Date: 2026-02-17 Status: Design approved
Goal
Each page in the Almanack should display sun and moon images appropriate to that page’s date — capturing the actual sky (sunspots, moon phase) as a visual timestamp. The front page shows today’s sky; archive pages show the sky from their publication or almanac day.
Current state
bin/a-celestialdownloads real-time SDO sun and Dial-A-Moon images, processes them intoassets/celestial/sun.pngandmoon.png, overwriting each run.celestial.jspositions these two images on the masthead arc using the browser’s local time (new Date()).- There is no date-keying: every page shows the same sun and moon.
Design
1. Storage layout
assets/celestial/
├── 2026-01-26/
│ ├── sun.png
│ └── moon.png
├── 2026-02-13/
│ ├── sun.png
│ └── moon.png
├── 2026-02-17/
│ ├── sun.png
│ └── moon.png
├── latest → 2026-02-17/ # symlink, updated by a-celestial
└── default/
├── sun.png # generic sun (one good SDO capture)
├── moon-new.png # phase-accurate defaults
├── moon-waxing-crescent.png
├── moon-first-quarter.png
├── moon-waxing-gibbous.png
├── moon-full.png
├── moon-waning-gibbous.png
├── moon-last-quarter.png
└── moon-waning-crescent.png
Date directories hold real NASA captures for that specific day. The
latest symlink always points to the most recently generated date
directory — a reliable fallback that requires no JavaScript.
The default/ directory holds a generic sun plus eight phase-accurate
moon images (one per major phase), selected from representative
Dial-A-Moon frames and processed through the same pipeline as
date-specific images.
2. a-celestial script changes
a-celestial (no flags): Fetch today’s sun and moon from NASA. Save
to assets/celestial/YYYY-MM-DD/. Update the latest symlink to point
at that directory.
a-celestial --date YYYY-MM-DD: Fetch sun and moon for a specific
date (SDO archives go back to 2010; Dial-A-Moon accepts arbitrary
dates). Save to assets/celestial/YYYY-MM-DD/. Does not update the
latest symlink.
a-celestial --date YYYY-MM-DD --set-latest: Same as above, but
also updates the latest symlink.
a-celestial --generate-defaults: Fetch eight representative moon
phases from Dial-A-Moon plus one generic sun. Save to
assets/celestial/default/.
3. celestial.js changes
Date resolution
Priority order for determining which date’s images to display:
?fp=query parameter (front-page navigation context)- Almanac-day from the page (already present in
#frontpage-dateor parseable from the URL path) - Today’s date (fallback)
Hybrid date for position calculation
The sun and moon positions on the arc are calculated using a hybrid
Date object: the calendar day from the page’s date, combined with
the time-of-day from the browser’s clock.
const celestialDate = new Date(
pageDate.getFullYear(), pageDate.getMonth(), pageDate.getDate(),
now.getHours(), now.getMinutes(), now.getSeconds()
);
This means summer almanac-days show a high, long sun traverse; winter days show a low, short one. The moon’s synodic position shifts correctly for any date in history.
Image loading
Given a resolved date, load:
- /static/celestial/YYYY-MM-DD/sun.png
- /static/celestial/YYYY-MM-DD/moon.png
Fallback chain (via onerror on the <img> element):
- On 404 for the sun: load /static/celestial/default/sun.png
- On 404 for the moon: compute the synodic phase from the page date
using existing moonPosition() math, then load the nearest phase
image from /static/celestial/default/moon-{phase}.png
Exposed API for navigation
celestial.js exposes window.__celestialSetDate(dateStr) so that
frontpage-nav.js can trigger an image and position update after an
HTMX swap.
4. frontpage-nav.js changes
After an HTMX article swap, call window.__celestialSetDate(fpDate)
with the new front-page date string. This triggers celestial.js to
reload images and recalculate positions.
5. Build pipeline
No changes needed to build_with_distill.py. The existing
shutil.copytree of assets/celestial/ copies all subdirectories and
dereferences the latest symlink into a real directory — no dangling
symlinks in the static output.
6. Templates
No changes needed. The date is already present in the page:
- Front page (index.html): {% now %} tags in #frontpage-date,
overridable by ?fp= via frontpage-nav.js
- Article pages (article.html): {{ display_date|safe }} from
format_day(almanac-day) in #frontpage-date
7. Cache considerations
Date-keyed paths (/static/celestial/2026-02-13/sun.png) are
naturally cache-friendly — a given date’s images never change, so
they can be cached indefinitely. The latest/ path changes content
when the symlink is updated, but celestial.js should never request
latest/ directly; it always resolves to a specific date.
Scope
In scope (Phase 1):
- Date-keyed storage with latest symlink
- a-celestial --date and --generate-defaults flags
- celestial.js date resolution, hybrid positioning, image loading
with fallback
- Phase-accurate default moon images (eight phases)
- HTMX navigation integration via exposed function
- Backfill real images for existing front-page dates (2024–2026)
Future enhancements: - More astronomically accurate position models - Additional sky elements (planets, comets, eclipses) - Stylised woodcut celestial images for the medieval aesthetic - Procedurally generated historical suns