5.5.3
Looks
Pick Dispatch's type, accent color, home page hero, nav and story layout, or make your own accent.
You pick the look in one file, src/theme.look.ts. It has five settings:
pairing: the type."modern"(Inter, the default),"classic"(Newsreader with Instrument Sans) or"fashion"(Instrument Serif with Geist). Only the chosen pairing’s fonts load.accent: the color of links, the focus ring and the Subscribe button, and nothing else."blue"(Deep blue),"green"(Slate green),"plum"or"teal", orundefinedfor none. None is the default: ink.hero: the top of the home page."rail"(a row of stories that scrolls sideways, the default),"big-photo"(one lead story on a full-width photo),"three-up"(three stories in one strip) or"title-first"(the site’s name in large type, an intro line and three photo cards).nav:"inline"(one row, the default) or"stacked"(a centered masthead with the links under it, from tablet width).post: the story page."centered"(one reading column, the default) or"side"(a side column with the writer, “On this page” and the series).
For example:
export const pairing: Pairing = "classic";
export const accent: Accent | undefined = "plum";
export const hero: Hero = "big-photo";
pnpm check and the build stop on an unknown value. The build’s error names the bad value and lists the correct ones.
The photo heroes need stories with a photo. With fewer than three, the rail and the photo heroes fall back to Title first. A story shows once per page: a story in the hero does not come back lower down.
Make your own accent
- Copy a file in
src/styles/accents/, for exampleblue.csstored.css. - In the new file, change the id in each selector (
data-accent="red") and change the colors. Set the light colors and the dark colors. The dark colors are in two places. Keep them the same. - Add the accent to
src/styles/accents/accents.json: itsid, alabel, its light accent (swatch) and its dark accent (dark). These two values must match the--ui-accentvalues in the CSS file. - Add the id to
ACCENTSinsrc/utils/look.ts, and import the file insrc/styles/global.css, after the other accents. - Run
pnpm test:skins. It checks that each accent inaccents.jsonhas a file and an import, that the values match, and that the colors have enough contrast (WCAG AA, 4.5:1) on the page and on the band, in light and dark mode.
Favicon and share images
public/favicon.svg uses the ink colors: #0f1114 in light mode and #f2f4f7 in dark mode. The favicon does not change with the accent. If you use an accent, change these two colors yourself.
Every public page gets a share image. Its font and colors are in src/share-card.ts, and its accent follows your look.
Light and dark mode
Light and dark mode follow the visitor’s system setting. The moon button in the nav bar lets them pick: one press shows the other mode, and a press back to the mode their system shows lets the site follow the system again. On a phone the button sits in the bar, before Subscribe and the menu button; on a phone narrower than 360px the bar has no room for it, so it moves into the menu, as a “Dark mode” button.
- The choice is saved in the visitor’s browser (
localStorage, keyaui-theme) and applies on every page. A small script at the top of<head>insrc/layouts/Base.astro(modeScript) puts it on<html>before the page paints, so a visitor who chose dark never sees a light page first. - Without JavaScript the button is hidden, and the site follows the system setting.
- Turn the button off: set
modeSwitchtofalseinsrc/theme.look.ts. The button and its script are gone, and the site follows each visitor’s system setting. A choice a visitor saved before is no longer read, so nobody is left stuck in a mode they cannot change. - Force one mode: turn the button off, then set
data-theme="light"ordata-theme="dark"on<html>insrc/layouts/Base.astro.