Files
SlpSoftware/src/features/landing/data/resolveHero.ts
T

34 lines
1001 B
TypeScript

import { headingFromLines, titleLines, type CmsHero, type CmsHeroButton } from '../../../cms-client/hero';
import { heroContent } from './content';
/** What the hero components show: from the CMS when it delivered a hero, otherwise the baked texts. */
export interface ResolvedHero {
/** Text for screen readers and search engines (the sr-only part of the h1). */
heading: string;
/** The visible title, one entry per line. */
lines: string[];
lead: string | null;
buttons: CmsHeroButton[];
fromCms: boolean;
}
export function resolveHero(cms: CmsHero | null): ResolvedHero {
if (cms === null) {
return {
heading: heroContent.heading,
lines: heroContent.displayHeading,
lead: heroContent.lead,
buttons: heroContent.buttons,
fromCms: false,
};
}
const lines = titleLines(cms.title);
return {
heading: headingFromLines(lines, heroContent.headingPrefix),
lines,
lead: cms.lead,
buttons: cms.buttons,
fromCms: true,
};
}