diff --git a/packages/starpod/src/assets/avatar.svg b/packages/starpod/src/assets/avatar.svg new file mode 100644 index 00000000..f219fb6d --- /dev/null +++ b/packages/starpod/src/assets/avatar.svg @@ -0,0 +1 @@ + diff --git a/packages/starpod/src/components/EpisodeStage.astro b/packages/starpod/src/components/EpisodeStage.astro new file mode 100644 index 00000000..9bd1e0fd --- /dev/null +++ b/packages/starpod/src/components/EpisodeStage.astro @@ -0,0 +1,214 @@ +--- +import { matchNames, sortCast, voiceFor, type CastPerson } from '../lib/cast'; +import { getEpisodeCues } from '../lib/episode-cues'; +import { optimizeImage } from '../lib/optimize-episode-image'; +import type { Episode, Show } from '../lib/rss'; +import { dasherize } from '../utils/dasherize'; +import { formatDuration, toPlayable } from '../utils/playable'; +import { ArrowOutIcon, HeadphonesIcon, VideoIcon } from './icons'; +import Sponsors from './episode/Sponsors.astro'; +import LiveScript from './media/LiveScript'; +import PersonFace from './PersonFace.astro'; +import StageControls from './media/StageControls'; + +import type { ImageMetadata } from 'astro'; +import { getImage } from 'astro:assets'; +import starpodConfig from 'virtual:starpod/config'; +// The face for someone without a photo, light or dark with the page. +import avatar from '../assets/avatar.svg?url'; + +export interface Props { + episode: Episode; + show: Show; + /** + * The episode's hosts and guests, from the guests/sponsors database. Empty + * (or absent) when the database isn't enabled: no cast is shown. + */ + people?: Array; + /** The episode's sponsors from the database; the row hides when empty. */ + sponsors?: Array<{ id: string; img: string | null; name: string; url: string }>; + /** `feature` on the home page (links on to the episode), `page` on its own page. */ + variant: 'feature' | 'page'; + /** + * Divide the stage between the picture and the live transcript with a + * draggable divider (desktop, when the episode has a transcript). See + * `episode/split.ts`. + */ + split?: boolean; +} + +const { episode, people = [], show, sponsors = [], split = false, variant } = Astro.props; +const playable = toPlayable(episode, show); +const Heading = variant === 'page' ? 'h1' : 'h2'; +const art = + (await optimizeImage(episode.episodeImage ?? show.image, { width: 960, height: 960 })) ?? + show.image; +const date = new Date(episode.published); +const titleId = `stage-title-${episode.id.replace(/[^a-z0-9]/gi, '')}`; +const scriptId = `stage-script-${episode.id.replace(/[^a-z0-9]/gi, '')}`; +const presets = [ + ['watch', 'Watch'], + ['balanced', 'Balanced'], + ['read', 'Read'] +]; + +// The cast: this episode's own hosts and guests, in credit order. Anyone who +// speaks as one of the transcript's two main voices wears that voice's face. +const photos = import.meta.glob<{ default: ImageMetadata }>( + '/src/img/people/*.{jpeg,jpg,png}' +); +const cues = people.length ? await getEpisodeCues(episode) : null; +const names = people.map((person) => person.name); +const speakerOf = matchNames(names, [...new Set(cues?.flatMap((cue) => (cue.n ? [cue.n] : [])))], { + surnames: true +}); +const cast = await Promise.all( + sortCast(people, starpodConfig.hosts.map((host) => host.name)).map(async (person) => { + const photo = + person.img && (await photos[`/src/img/people/${person.img}`]?.())?.default; + const image = photo + ? await getImage({ src: photo, width: 112, height: 112, format: 'webp' }) + : { src: avatar }; + return { + guest: !person.isHost, + name: person.name, + speaksAs: speakerOf.get(person.name), + src: image.src, + voice: voiceFor(person.name, cues, names) + }; + }) +); +--- + +
+
+
+ +
+ + {`${episode.title} +
+ +
+
+ +
+ + {episode.title} + +

+ {episode.episodeNumber === 'Bonus' ? 'Bonus' : `Episode ${episode.episodeNumber}`} + + {formatDuration(episode.duration)} + + {episode.video ? : } + {episode.video ? 'Video' : 'Audio'} + +

+ { + cast.length > 0 && ( +
    + {cast.map((person) => ( +
  • + + + {person.name} + + {person.guest ? 'Guest' : 'Host'} + + +
  • + ))} +
+ ) + } + +

{episode.description}

+ + { + variant === 'feature' && ( + + Show notes and transcript + + + ) + } +
+
+ + { + split && ( +