A podcast told in seasons can be listed one season at a time (#482)

GET /api/feeds/{id}/seasons counts a podcast's episodes and unread by
season, from the same FROM as its list, so a count is what picking it
shows; season= on its entries narrows the list to one, or to the
episodes naming none. The page puts the seasons under the tabs, as the
tabs' own track, when a podcast is told in them: two or more, holding
most of its episodes. That leaves out Ken and Robin, whose "seasons" are
years on a quarter of 767 episodes, and The Vintage RPG Podcast's 2 of
366. Listed all together by date, a heading marks where each season
starts.

A fixture podcast in seasons is in the browser suite, which now
configures six feeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RqkrVAJFkEgz9cXG3jG1Zy
This commit is contained in:
2026-11-19 09:04:57 -05:00
parent 9ece0ff17c
commit a57820a078
17 changed files with 329 additions and 22 deletions

50
web/src/seasons.ts Normal file
View File

@@ -0,0 +1,50 @@
/* ---------------- seasons (#482) ---------------- */
/// A podcast's seasons, by feed id, as its page last fetched them, so going back to it draws its
/// picker at once while the counts are asked for again.
const seasonsOf=new Map<string,SeasonCount[]>();
/// Whether a podcast is told in seasons: two or more of them, holding most of its episodes. A few
/// numbered among hundreds (The Vintage RPG Podcast's 2 of 366), or years given as seasons on a
/// quarter of them (Ken and Robin's), are no seasons worth a picker.
function seasonsShown(list: SeasonCount[]|undefined): boolean{
if(!list) return false;
const numbered=list.filter(s=>s.season!=null);
const inOne=numbered.reduce((n,s)=>n+s.episodes,0), all=list.reduce((n,s)=>n+s.episodes,0);
return numbered.length>=2 && inOne*2>=all;
}
/// What the picker sends for a season: its number, or `none` for the episodes that name none.
const seasonKey=(s: SeasonCount)=>s.season==null?'none':String(s.season);
const seasonName=(s: number|null|undefined)=>s==null?'Other episodes':`Season ${s}`;
/// The picker, under the tabs: every season, one of them, or the episodes naming none.
function seasonsHTML(list: SeasonCount[]): string{
const chip=(key: string,label: string,title: string)=>
`<button data-season="${key}" class="${S.season===key?'on':''}" aria-pressed="${S.season===key}" title="${title}">${label}</button>`;
return `<div class="tabs seasons" role="group" aria-label="Seasons">${chip('','All seasons','Every season')}${
list.map(s=>chip(seasonKey(s),s.season==null?'Other':`Season ${s.season}`,
`${plural(s.episodes,'episode')}, ${s.unread} unread`)).join('')}</div>`;
}
function drawSeasons(f: Feed, list: SeasonCount[]|undefined){
const bar=$('#content .toolbar'); if(!bar||S.feed!==f.id) return;
bar.querySelector('.seasons')?.remove();
if(!list||!seasonsShown(list)) return;
bar.insertAdjacentHTML('beforeend',seasonsHTML(list));
$$<HTMLButtonElement>('.seasons button',bar).forEach(b=>b.onclick=()=>{
S.season=b.dataset.season!; S.offset=0;
renderFeed(); loadEntries();
});
// The dividers in the list wait on knowing the podcast is told in seasons.
if(S.entries.length) renderEntries();
}
/// A podcast's seasons onto its page: kept ones at once, then the server's.
async function loadSeasons(f: Feed){
drawSeasons(f,seasonsOf.get(f.id));
try{
const got: SeasonCount[]=await api(`/api/feeds/${encodeURIComponent(f.id)}/seasons`);
seasonsOf.set(f.id,got);
drawSeasons(f,got);
}catch{}
}
/// Where a season starts in the list, said above its first episode: only for every season at
/// once, newest or oldest first, where the episodes run season by season.
function seasonBreaks(): boolean{
return !S.season && S.sort.col==='published' && seasonsShown(seasonsOf.get(S.feed ?? ''));
}