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

View File

@@ -99,6 +99,8 @@ function renderFeed(){
renderFeed(); loadEntries();
});
if(f) wireFailBanner(box,f);
// An OPML's page is many podcasts' episodes together, their seasons each their own.
if(f&&!kids.length) loadSeasons(f);
}
/// The item table's headings, each a button that sorts by its column. The first click goes the

View File

@@ -202,7 +202,7 @@ function renderFeeds(){
done();
}
function selectFeed(id: string){
S.feed=id; S.offset=0; S.sel=null; S.q=''; $<HTMLInputElement>('#epSearch').value='';
S.feed=id; S.offset=0; S.sel=null; S.q=''; S.season=''; $<HTMLInputElement>('#epSearch').value='';
try{ localStorage.setItem('ipx.feed',id); }catch{}
renderFeeds(); renderFeed(); loadEntries();
}

View File

@@ -14,10 +14,13 @@ const lists=new Map<string,ListPage>();
const LISTS_KEPT=40;
/// Lists on their way, so a click on one already being fetched ahead waits for that answer.
const fetching=new Map<string,Promise<ListPage>>();
const listKey=(feed: string, filter=S.filter)=>[feed,filter,S.sort.col,S.sort.dir,S.q].join('\n');
// A season is of the podcast open (#482): another feed's list, fetched ahead, is of every season.
const seasonFor=(feed: string)=>feed===S.feed?S.season:'';
const listKey=(feed: string, filter=S.filter)=>[feed,filter,S.sort.col,S.sort.dir,S.q,seasonFor(feed)].join('\n');
function listUrl(feed: string, filter=S.filter, offset=0){
const p=new URLSearchParams({offset:String(offset),limit:String(LIMIT),filter,sort:S.sort.col,dir:S.sort.dir});
if(S.q) p.set('q',S.q);
if(seasonFor(feed)) p.set('season',seasonFor(feed));
const sg=signalId(feed);
return feed===':all' ? `/api/entries?${p}`
: sg!==null ? `/api/signals/${sg}/entries?${p}`
@@ -155,7 +158,14 @@ function renderEntries(){
else if(sg&&S.filter==='all') box.innerHTML='<p class="empty">Nothing has come through yet. New items are read as your feeds are checked.</p>';
return;
}
for(const e of S.entries) box.appendChild(epEl(e));
const breaks=seasonBreaks();
let last: number|null|undefined;
S.entries.forEach((e,i)=>{
if(breaks&&(i===0||(e.season??null)!==(last??null)))
box.insertAdjacentHTML('beforeend',`<div class="sdiv" role="heading" aria-level="3">${seasonName(e.season)}</div>`);
last=e.season;
box.appendChild(epEl(e));
});
syncPlayButtons();
if(pane) pane.scrollTop=top;
if(hasMore()){

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 ?? ''));
}

View File

@@ -141,6 +141,9 @@ interface State {
/// Whether the server has more after the last page it sent, by that answer's own numbers.
more: boolean;
filter: string;
/// One season of the open podcast (#482): its number, `none` for the episodes naming none, or
/// empty for every season.
season: string;
q: string;
/// The selected item's guid.
sel: string | null;
@@ -148,6 +151,14 @@ interface State {
sort: {col: string, dir: 'asc' | 'desc'};
}
/// One season of a podcast, `/api/feeds/{id}/seasons` (db.rs SeasonCount, #482). No season is
/// the episodes that name none.
interface SeasonCount {
season?: number | null;
episodes: number;
unread: number;
}
/// A smart playlist, `/api/playlists` (db.rs PlaylistRow, #476).
interface Playlist {
id: number;

View File

@@ -345,7 +345,7 @@ const S: State = {
feed:(()=>{ try{ return localStorage.getItem('ipx.feed'); }catch{ return null; } })(),
entries:[], total:0, offset:0, more:false,
filter:(()=>{ try{ return localStorage.getItem('ipx.filter'); }catch{ return null; } })()||'all',
q:'', sel:null, me:null,
season:'', q:'', sel:null, me:null,
// The item table's order, kept across visits. The server sorts: a list arrives fifty at a time.
sort:(()=>{ try{ return JSON.parse(localStorage.getItem('ipx.sort')??'null'); }catch{ return null; } })()
||{col:'published',dir:'desc'},