Manual
Almnck.
Price: 50ⓐ

Editorial Margin Boxes

Beyond the inline margin boxes defined within individual articles (see the Markdown Guide), Almanack supports editorial margin boxes — site-wide content that gets injected into pages automatically. These are useful for:

  • Rotating aphorisms and quotes
  • Calls-to-action (membership, newsletter signup)
  • Seasonal announcements
  • Featured content highlights

Creating Margin Boxes

Editorial margin boxes live in editorial/margin-boxes/. Each box has its own directory containing a margin-box.md file:

editorial/margin-boxes/
├── seneca-time/
│   └── margin-box.md
├── subscriber-cta/
│   └── margin-box.md
└── winter-sale/
    └── margin-box.md

Frontmatter

---
type: aphorism
placement: right-top
priority: normal
pages: [articles]
weight: 50
active: true
starts: 2026-01-01
expires: 2026-03-01
tags: [stoicism, featured]
---

Required Fields

  • type: The box style — aphorism, quote, editorial, ad, or poem
  • active: Set to true to include in rotation, false to disable

Optional Fields

Field Default Description
placement any Position hint: right-top, left-bottom, any, etc.
priority normal critical (always shown), high, normal, or low
pages [all] Which page types: articles, front, pages, or all
slugs [] Article slugs — if set, only show on these specific articles
weight 50 Selection weight (1-100). Higher = more likely to appear
starts — ISO date when box becomes active
expires — ISO date when box stops appearing
tags [] For categorization and future filtering
interactive — JavaScript component name (auto-detected from code.js)
wash (auto) Watercolour wash tint: none, ultramarine, vermilion, verdigris, saffron, parchment

Content

After the frontmatter, write the box content in Markdown:

---
type: aphorism
placement: right-top
priority: normal
pages: [articles]
weight: 50
active: true
---

*Time discovers truth.*
— Seneca

The content is rendered to HTML during sync, so standard Markdown formatting works: *italics*, **bold**, [links](/path/), etc.

Box Types

Aphorism

Short, pithy statements displayed in Fell English typography, centered.

type: aphorism
---

Everything should be made as simple as possible, but not simpler.

Quote

Quotations with attribution, rendered in italics with a left border.

type: quote
---

The important thing is not to stop questioning.

<cite>Albert Einstein</cite>

Editorial

General editorial content — announcements, CTAs, notices.

type: editorial
---

**Support the Almanack**

Become a member to access the full archive.

[Learn more →](/membership/)

Period-appropriate advertisements, boxed and centered.

type: ad
---

**ACME MOON CHEESE**

Now available in three flavours!

Poem

Verse with floral ornaments (❦ above, ❧ below).

type: poem
---

*Fragment*

Time discovers truth,
And truth, in time, discovers us.

— After Seneca

Placement and Priority

Placement Tokens

The placement field accepts hyphen-separated tokens:

Token Effect
top Place at top of margin, fill downward
bottom Place at bottom of body text, fill upward
left Prefer left margin
right Prefer right margin
any No preference (default)
masthead Route to masthead instead of margins (works on all viewports)

Examples: right-top, left-bottom, any, masthead

Priority Levels

Priority Behavior
critical Always included, placed first
high Placed early, position locked
normal Standard placement (default)
low Placed last, may shift to fill gaps

Use critical sparingly — for urgent announcements that must appear on every page load.

Selection Algorithm

When a page loads, the system selects margin boxes using a deterministic algorithm:

  1. Filter by active: true
  2. Filter by pages matching the current page type
  3. Filter by slugs — if the box specifies slugs, only include it when the current article’s slug matches. Boxes with an empty slugs list (the default) pass through unrestricted.
  4. Filter by date range (starts ≤ today ≤ expires)
  5. Include all critical priority boxes
  6. Fill remaining slots using weighted random selection

The selection is seeded by page path and build date, so the same page shows the same boxes until the next build. This ensures cacheability while still rotating content across different pages.

Page Types

Type Matches
front The homepage / front page
articles Individual article pages
pages Static pages (about, contact, etc.)
all All page types

A box with pages: [articles, front] appears on articles and the homepage but not on static pages.

Pinning (Reader Persistence)

Readers can “pin” margin boxes they like, causing them to appear on every page they visit — even pages where that box wouldn’t normally be selected.

How It Works

  1. Pinned box slugs are stored in localStorage
  2. On page load, the JavaScript fetches pinned boxes from /margin-boxes/{slug}.html
  3. Pinned boxes are treated as high-priority and positioned first
  4. A 📌 button appears on pinned boxes for unpinning

Static Fragments

Each active margin box generates a static HTML fragment at:

/margin-boxes/{slug}.html

These fragments enable client-side pinning without server round-trips.

JavaScript API

The margin box system exposes a public API at window.Sidenotes:

// Pin a box (persists in localStorage)
window.Sidenotes.pinMarginBox('seneca-time')

// Unpin a box
window.Sidenotes.unpinMarginBox('seneca-time')

// Get all pinned slugs
window.Sidenotes.getPinnedBoxes()
// → ['seneca-time', 'subscriber-cta']

// Check if a specific box is pinned
window.Sidenotes.isBoxPinned('seneca-time')
// → true

// Inject a box dynamically (doesn't persist)
window.Sidenotes.injectMarginBox({
  content: '<p>Dynamic content!</p>',
  type: 'editorial',
  placement: 'right',
  priority: 'normal',
  nearAnchor: document.querySelector('#my-element'),  // optional: DOM element for 'near' placement
  nearOffset: 0  // optional: pixel offset from anchor
})

// Remove an injected box by ID
window.Sidenotes.removeMarginBox('mb-abc123')

// Reposition all margin content
window.Sidenotes.reposition()

Interactive Margin Boxes

Margin boxes can include JavaScript behaviour via a convention-based loader. If an assets/code.js file exists in the margin box directory, the sync process automatically sets the box’s interactive field to its slug, and the client-side interactive-margin-boxes.js loader will import and run it.

Convention

editorial/margin-boxes/my-widget/
├── margin-box.md          # Content + <style> blocks
└── assets/
    └── code.js            # ES module: export function setup(container) { ... }

The module must export a setup(container) function that receives the .margin-box DOM element:

// assets/code.js
export function setup(container) {
  // Enhance the margin box content
  container.innerHTML = '<p>Interactive content!</p>';
}

(Prior to the May 2026 View Transitions migration, setup() could return a cleanup function called on HTMX swaps. Cross-document navigation makes that unnecessary — the old document just dies — but the loader will still ignore any returned value if you want to keep existing modules compatible.)

CSS

Embed styles in <style> blocks inside margin-box.md rather than in code.js. The loader hoists these blocks out of the box element before calling setup(), so they survive even if setup() replaces innerHTML. Scope styles using .margin-box[data-slug="my-widget"] to avoid leaking.

Wash Control

The sundial lighting system automatically assigns a watercolour wash tint to margin boxes based on type and algorithmic colour balancing. To override:

  • wash: none — no wash at all (useful for interactive boxes with their own styling)
  • wash: ultramarine — force a specific pigment (vermilion, verdigris, saffron, parchment also available)

If omitted, the system chooses. Conventions by type: quote gets vermilion, ad gets saffron, poem and annotation get none.

Masthead Placement

Boxes with placement: masthead are extracted from the margin flow and rendered inside the #masthead-identity container in the page header. This is how the subscriber identity stamp works. Masthead boxes appear on all viewport widths, including mobile where margins are hidden.

Examples

The project has three interactive margin boxes:

  • identity (placement: masthead) — subscriber’s name and balance stamp
  • subscribe — inline newsletter signup form with no-JS fallback
  • previously — “Lately Published” list with data-hide-on-page

Contextual Hiding with data-hide-on-page

Any HTML element can declare that it should be hidden when the reader is on a specific page. Set data-hide-on-page to one or more space-separated URL paths:

<dt data-hide-on-page="/6026/1/26/logiebair/">Logie Baird Article</dt>

The article and index templates emit a <style> block that hides matching elements using the CSS ~= word-match selector. For <dl> lists, adjacent <dd> siblings are hidden too. The style block reloads with each navigation, so the correct rule is always active for the current article.

This is useful for margin boxes that link to articles — you don’t want to show “recently published: Article X” when the reader is already reading Article X.

Assets (Images, etc.)

Margin boxes that need images or other assets store them in an assets/ subdirectory alongside the margin-box.md file:

editorial/margin-boxes/se-goldman-disillusionment/
├── margin-box.md
└── assets/
    └── cover.jpg

Reference assets in your markdown using the static path /static/margin-boxes/<slug>/<filename>:

<img src="/static/margin-boxes/se-goldman-disillusionment/cover.jpg"
     alt="Book cover" style="width: 100%;">

How asset serving works

  • Production (make build): The build copies editorial/margin-boxes/<slug>/assets/ to web/static/margin-boxes/<slug>/. This happens automatically.

  • Development (make serve): Django serves static files from assets/. You need a symlink in assets/margin-boxes/<slug>/ pointing back to the editorial source:

sh mkdir -p assets/margin-boxes/<slug> ln -sf ../../../editorial/margin-boxes/<slug>/assets/cover.jpg \ assets/margin-boxes/<slug>/cover.jpg

The symlinks are lightweight and should be committed to git. They let the dev server find the files without duplicating them.

Cache busting

Assets under /static/ are served with immutable cache headers (see assets/system/Caddyfile). If you update a margin box image, change the filename (e.g., cover-v2.jpg) to bust the cache.

Workflow

  1. Create a directory in editorial/margin-boxes/
  2. Add margin-box.md with frontmatter and content
  3. If the box has images, add them to assets/ and create dev symlinks in assets/margin-boxes/<slug>/
  4. Run make sync to import into the database
  5. Run make build to generate the site and fragments
  6. Verify on make serve

To disable a box temporarily, set active: false and re-sync.

To schedule content, use starts and expires dates.

Examples

Rotating Quote Collection

# editorial/margin-boxes/stoic-wisdom-01/margin-box.md
---
type: aphorism
pages: [articles]
weight: 30
active: true
tags: [stoicism]
---

*Time discovers truth.*
— Seneca
# editorial/margin-boxes/stoic-wisdom-02/margin-box.md
---
type: aphorism
pages: [articles]
weight: 30
active: true
tags: [stoicism]
---

*The obstacle is the way.*
— Marcus Aurelius

With equal weights, these appear with roughly equal frequency across different articles.

Seasonal Announcement

# editorial/margin-boxes/winter-membership/margin-box.md
---
type: editorial
placement: right-bottom
priority: high
pages: [all]
weight: 80
active: true
starts: 2026-12-01
expires: 2027-01-15
---

**Winter Membership Drive**

Join before the solstice and receive a complimentary ephemeris.

[Become a member →](/membership/)

Critical Alert

# editorial/margin-boxes/site-maintenance/margin-box.md
---
type: editorial
priority: critical
pages: [all]
active: true
expires: 2026-01-22
---

**Scheduled Maintenance**

The archive will be unavailable Jan 21, 2-4am UTC.

Critical priority ensures this appears on every page until the expiry date.

Article-Targeted Ad

# editorial/margin-boxes/se-goldman-disillusionment/margin-box.md
---
type: ad
placement: right
priority: high
pages: [articles]
slugs: [kropotkins-funeral]
weight: 80
active: true
tags: [anarchism, goldman, russia, books]
---

<img src="/static/margin-boxes/se-goldman-disillusionment/cover.jpg"
     alt="Cover: My Disillusionment in Russia" style="width: 70%;">

Emma Goldman — **My Disillusionment in Russia**

Free from [Standard Ebooks](https://standardebooks.org/ebooks/emma-goldman/my-disillusionment-in-russia).

The slugs: [kropotkins-funeral] field pins this ad to the Kropotkin funeral article only. It won’t appear on any other page, even though pages: [articles] would otherwise make it eligible site-wide.

You can list multiple slugs to target a group of related articles:

slugs: [kropotkins-funeral, logic-day, logiebair]