Rotating words: {Next|Now} in titles and text cycles through its choices

Migration 084: site defaults for the motion (slide, flip, fade, type,
mirror), direction and seconds per word in Site settings, and a hero's
and a block's own. The hero's headline, section and band titles,
headings, paragraphs, callouts and quotes rotate; menus, tab titles,
search text and emails show the first word; less motion shows it still.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-17 00:43:59 -05:00
parent ab8dcdd608
commit a10ff6d75f
30 changed files with 411 additions and 37 deletions

View file

@ -346,6 +346,45 @@ export const HREF_HELP = {
video: "The video's page, eg. https://www.youtube.com/watch?v=…, or a video file",
};
/* Rotating words (084): text typed as {Next|Now|Rising} cycles
through its choices. These pick how, for a block or a hero; Site
settings → Animated words holds the defaults. */
export const WORD_MOTIONS = [
["slide", "Slide"],
["flip", "Flip, like a card"],
["fade", "Fade"],
["type", "Type, letter by letter"],
["mirror", "Mirror, turning round"],
];
export const WORD_DIRECTIONS = [
["bottom", "From the bottom"],
["top", "From the top"],
];
export const WORD_HELP = "Type choices in braces to rotate them, eg. {Next|Now|Rising} Generation of {Unity|New Thought}.";
/* The three fields, under `prefix` (eg. "hero."), shown `when`. */
export const wordFields = (prefix: string, label: string, when?: any) => [
{
path: `${prefix}word_motion`,
label: label ? `${label}rotating words` : "Rotating words",
widget: "select",
options: WORD_MOTIONS,
blankLabel: "Default: the site's (Site settings → Animated words)",
help: WORD_HELP,
when,
},
{
path: `${prefix}word_direction`,
label: label ? `${label}words come in` : "Words come in",
widget: "select",
options: WORD_DIRECTIONS,
blankLabel: "Default: the site's",
help: "For Slide and Flip",
when,
},
{ path: `${prefix}word_seconds`, label: label ? `${label}seconds per word` : "Seconds per word", widget: "number", help: "1 to 20. Default: the site's", when },
];
export const blocksChild = {
key: "content_blocks",
label: "Content blocks",
@ -441,6 +480,7 @@ export const blocksChild = {
help: "Shows the team's members as tiles, its leads first. People added as items show after it.",
when: { path: "type", value: "people" },
},
...wordFields("", "", { path: "type", value: ["heading", "subheading", "paragraph", "callout", "quote"] }),
],
children: [
{

View file

@ -11,7 +11,7 @@
every page offers them all. The Community blog's settings show on
the Community page only (its id), for now. */
import { FEATURED_KINDS, featuredCardsChild, blocksChild } from "./shared.ts";
import { FEATURED_KINDS, featuredCardsChild, blocksChild, wordFields } from "./shared.ts";
import { mediaUrl } from "../media.ts";
import { PATH_ICONS } from "../../data/pathIcons.ts";
@ -146,6 +146,7 @@ const BAND_FIELDS = [
help: "For the Featured event feature. A pinned event that's over falls back to the countdown's",
when: IS("hero"),
},
...wordFields("hero.", "Hero: ", IS("hero")),
{
path: "countdown.event_id",
label: "Count down to",

View file

@ -1,6 +1,7 @@
import siteConfiguration from "../../../site.json";
import { mediaUrl } from "../media.ts";
import { THEME_DEFAULTS } from "../../../server/src/themeDefaults.js";
import { WORD_DIRECTIONS, WORD_HELP, WORD_MOTIONS } from "./shared.ts";
/* ── Site settings (035_site_settings.sql) ───────────────────────
Overrides for site.json, superadmins only: every blank falls back
@ -158,6 +159,15 @@ export const siteSettings = {
},
],
},
{
legend: "Animated words",
note: WORD_HELP + " Works in the hero's headline, section titles, headings and paragraphs. These are the defaults; a hero or a block can set its own. Visitors who ask for less motion see the first word, still.",
fields: [
{ path: "word_motion", label: "Motion", widget: "select", options: WORD_MOTIONS, blankLabel: "Default: Slide" },
{ path: "word_direction", label: "Words come in", widget: "select", options: WORD_DIRECTIONS, blankLabel: "Default: from the bottom", help: "For Slide and Flip" },
{ path: "word_seconds", label: "Seconds per word", widget: "number", help: "1 to 20. Default: 3" },
],
},
{
legend: "Notices",
fields: [

View file

@ -13,6 +13,7 @@ import { useCallback } from 'react'
import { useSitePageHeadings } from './useSitePages.ts'
import { UNLISTED_PRESETS } from '../pages/sections/Bands.tsx'
import { firstWords } from '../lib/words.ts'
export type NavSection = { label: string; hash: string }
@ -23,7 +24,7 @@ export function useNavSections(): (path: string) => NavSection[] {
(path: string) =>
(sitePages?.[path] ?? [])
.filter((section) => !UNLISTED_PRESETS.includes(section.preset ?? ''))
.map((section) => ({ label: section.title, hash: `#${section.anchor}` })),
.map((section) => ({ label: firstWords(section.title), hash: `#${section.anchor}` })),
[sitePages],
)
}

View file

@ -38,6 +38,7 @@
import { readableOn } from './color.ts'
import { PLATFORMS } from './platforms.ts'
import { firstWords } from '../lib/words.ts'
export type NewsletterItem = {
title: string
@ -186,7 +187,8 @@ const imageTag = (src: string, alt: string) =>
`<img src="${escape(src)}" width="552" alt="${escape(alt)}" style="display:block;margin:0 auto;width:100%;max-width:552px;height:auto;border:0;">`
function blockHtml(block: NewsletterPart, n: Newsletter): string {
const text = block.text?.trim() ?? ''
// An email can't animate: rotating words ({Next|Now}) are their first.
const text = firstWords(block.text).trim()
const href = block.href ? safeHref(block.href, n) : null
const items = block.items ?? []
const align = alignOf(block)
@ -412,7 +414,7 @@ export function newsletterHtml(n: Newsletter): string {
}
function blockText(block: NewsletterPart, n: Newsletter): string[] {
const text = block.text?.trim() ?? ''
const text = firstWords(block.text).trim()
const items = block.items ?? []
const link = (url: string) => safeHref(url, n) ?? url
switch (block.type) {

View file

@ -40,6 +40,8 @@ export type Hero = {
video: { url: string; title?: string | null; captions?: string | null; still?: string | null } | null
/** With the 'event' feature: the pinned event, else the page's countdown's. */
event: HeroEvent | null
/** Its rotating words' own motion (084), else the site's. */
words?: { motion?: any; direction?: any; seconds?: number | null } | null
}
export type SectionStat = {

View file

@ -23,7 +23,10 @@
import siteConfiguration from '../../site.json'
type SiteText = { title?: string; requestFiles?: boolean }
/** How rotating words move (RotatingWords.tsx, 084). */
export type WordSettings = { motion: 'slide' | 'flip' | 'fade' | 'type' | 'mirror'; direction: 'top' | 'bottom'; seconds: number }
type SiteText = { title?: string; requestFiles?: boolean; words?: Partial<WordSettings> | null }
/* What the server wrote into the page, if it did. */
const fromServer: SiteText =
@ -33,6 +36,14 @@ export const SITE_NAME: string = fromServer.title || siteConfiguration.title
export const SITE_ORIGIN: string = siteConfiguration.url
/** Rotating words' defaults: Site settings → Animated words, else
* sliding up from the bottom, three seconds a word. */
export const WORD_DEFAULTS: WordSettings = {
motion: fromServer.words?.motion || 'slide',
direction: fromServer.words?.direction || 'bottom',
seconds: fromServer.words?.seconds || 3,
}
/** Whether the Request form takes files (Google Drive is set up on
* the server). Unknown (the Vite dev server) offers them, and the
* server says so if it can't. */

View file

@ -24,6 +24,8 @@ import type { EventSeries } from './eventSeries.ts'
export type ContentBlock = {
id?: number | string
slot?: 'card' | 'body'
/** Its rotating words' own motion (084), else the site's. */
words?: { motion?: any; direction?: any; seconds?: number | null } | null
type:
| 'heading'
| 'subheading'

10
src/lib/words.ts Normal file
View file

@ -0,0 +1,10 @@
/* Rotating words as plain text (src/components/RotatingWords.tsx
draws them moving): a group typed as {Next|Now|Rising}. */
/** {A|B} groups in a text. */
export const WORD_GROUP = /\{([^{}|\n]+(?:\|[^{}|\n]+)+)\}/g
/** The text as plain words, each group its first choice: for menus,
* tab titles, emails and anywhere that can't move. */
export const firstWords = (text?: string | null): string =>
(text ?? '').replace(WORD_GROUP, (_, group: string) => group.split('|')[0].trim())