Skip to content

Error ad

The ad slot of an error page, one vintage-style ad as decoration at the foot of a 404 or a 500.

<div class="ad-demo-page">
  <p>Page not found. Try the search, or go back to the home page.</p>
  <div data-mount="corner"></div>
</div>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/error-ad.css";
import { adProblems, burstPoints, scopeArt } from "capsomer/behavior/error-ad";

Usage

<div class="cap-ad" data-size="corner" aria-hidden="true" data-ad="field-notes">
  <svg class="cap-ad-defs" focusable="false"><!-- the scoped art's symbols --></svg>
  <svg class="cap-ad-art" viewBox="0 0 600 360" focusable="false">
    <g><text class="cap-ad-f-display">FIELD NOTES!</text></g>
    <text class="cap-ad-f-serif cap-ad-ink">The pocket notebook</text>
    <text class="cap-ad-f-slab">NEW!</text>
  </svg>
</div>

Examples

Large, in a gallery

<div class="ad-demo-page">
  <div data-mount="large"></div>
</div>

API reference

ErrorAd

PropTypeRequiredDoes
adAd & { art: string }YesThe ad, with its art already scoped (scopeArt): trusted markup from the site's own repository.
size"corner" | "large""corner": the foot of an error page; "large": a gallery that shows one ad whole.
stylesheetstringThe error-ad stylesheet's and fonts' addresses as the site's bundler emits them, so only a page that shows an ad loads them (a link here, never an import in the root error boundary).
fontsstring[]

Functions

FunctionSignatureDoes
adProblems(ad: Partial<Ad> | null | undefined, art: string): string[]Everything wrong with an ad's data, as sentences; an empty list is a valid ad. ad is a parsed ad.json, art its folder's raw art.svg.
burstPoints(cx: number, cy: number, outer: number, inner: number, points: number): stringThe points of a starburst: points spikes alternating between outer and inner radius.
scopeArt(art: string, adId: string): stringPrefixes an art file's ids (and its internal links) with the ad's id, so two ads' symbols never collide.
chooseAd<T extends { id: string; }>(ads: T[], search: string, random?: () => number): T | undefinedThe ad a request gets: the one ?ad= names when it exists (so a link can show one), else a random one.

CSS variables

VariableDefault
--cap-ad-ink#1b1f3b

Parts and data attributes

ClassIs
.cap-adthe root
.cap-ad-arta part
.cap-ad-defsa part
.cap-ad-f-displaya part
.cap-ad-f-serifa part
.cap-ad-f-slaba part
.cap-ad-inka part
AttributeValues
data-sizelarge

Accessibility

None. The ad has no controls.

  • aria-hidden="true" on the whole ad, and focusable="false" on its SVGs; the page's own message carries the content.
  • pointer-events: none and no links.