From e2e810588033ecd767147d9beb6c1bb794b508c5 Mon Sep 17 00:00:00 2001
From: rays
Date: Sat, 28 Nov 2026 10:49:32 -0500
Subject: [PATCH] An untitled item is named as it is stored, not by the page
each time (#502)
The page named an item its feed gave no title (the first 120 characters of
its text, else its file's name) every time it drew one, so the iOS
widget, CarPlay, search and Signals never saw a name, and the list had to
carry each item's whole text to name the untitled ones (#501).
The feed parser now names them the same way as it reads a feed, for ipx
and the directory alike, and ipx names the untitled items already stored
once, in batches, before making search text, which the name goes into.
The reader and the directory's preview leave off a title that is only the
opening of the text below it, as they did for an untitled item.
Co-Authored-By: Claude Opus 5.5
Claude-Session: https://claude.ai/code/session_01RqkrVCCH8YcP2Y3i8VNYWA
---
Cargo.lock | 1 +
crates/directory/CHANGELOG.md | 1 +
crates/feed/Cargo.toml | 1 +
crates/feed/src/lib.rs | 2 +-
crates/feed/src/parse.rs | 77 +++++++++++++++++++++++++++++++++-
crates/ipx/CHANGELOG.md | 1 +
crates/ipx/src/db.rs | 78 +++++++++++++++++++++++++++++++++++
crates/ipx/src/search.rs | 18 ++++++++
tests/page-unit.ts | 9 ++++
web/CHANGELOG.md | 1 +
web/src/dialogs.ts | 4 +-
web/src/items.ts | 8 +++-
12 files changed, 197 insertions(+), 4 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 82820ea..51d4920 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1752,6 +1752,7 @@ dependencies = [
"http",
"hyper-util",
"opml",
+ "percent-encoding",
"pulldown-cmark",
"quick-xml 0.42.0",
"reqwest",
diff --git a/crates/directory/CHANGELOG.md b/crates/directory/CHANGELOG.md
index dd08b2d..a7ee065 100644
--- a/crates/directory/CHANGELOG.md
+++ b/crates/directory/CHANGELOG.md
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
+- An episode its feed gives no title is named by the opening of its text or else its file's name, where it had none (#502).
- Its checks of YouTube channels go one at a time, two seconds apart, since YouTube refuses many asked together (#386).
- Its JSON log lines no longer carry their span, once on its own and again in a list, which said nothing the line's own fields did not (#363).
diff --git a/crates/feed/Cargo.toml b/crates/feed/Cargo.toml
index 986a507..80f112f 100644
--- a/crates/feed/Cargo.toml
+++ b/crates/feed/Cargo.toml
@@ -14,6 +14,7 @@ chrono.workspace = true
http.workspace = true
hyper-util.workspace = true
opml.workspace = true
+percent-encoding.workspace = true
pulldown-cmark.workspace = true
quick-xml.workspace = true
reqwest.workspace = true
diff --git a/crates/feed/src/lib.rs b/crates/feed/src/lib.rs
index c7a9fd5..4ad7ddd 100644
--- a/crates/feed/src/lib.rs
+++ b/crates/feed/src/lib.rs
@@ -21,7 +21,7 @@ pub use failure::{Failure, explain_failure, failure_kind, is_temporary_lookup_fa
pub use fetch::{FEED_SILENCE, FEED_TIMEOUT, FETCHED_BYTES, FETCHES, Fetched, fetch, is_youtube_feed};
pub use jev::{JEV_URL, classify};
pub use outlines::{collect_outlines, is_opml, opml_title, parse_opml, read_opml};
-pub use parse::{Enclosure, Entry, ParsedFeed, markdown_html, parse, same_file_key};
+pub use parse::{Enclosure, Entry, ParsedFeed, markdown_html, parse, same_file_key, untitled_name};
pub use patreon::{is_patreon_creator, patreon_shows, same_feed};
pub use privacy::{redact, redact_text, url_looks_private};
diff --git a/crates/feed/src/parse.rs b/crates/feed/src/parse.rs
index 5a35235..97454ee 100644
--- a/crates/feed/src/parse.rs
+++ b/crates/feed/src/parse.rs
@@ -62,9 +62,53 @@ pub struct Enclosure {
pub length: Option,
}
-/// RSS first, then Atom -- the same split the original made on `parsedFeed.version`.
+/// RSS first, then Atom -- the same split the original made on `parsedFeed.version`. An item
+/// without a title is named here, once, for everything that shows it (#502).
#[tracing::instrument(skip_all, fields(bytes = bytes.len()))]
pub fn parse(bytes: &[u8]) -> Result {
+ let mut feed = parse_any(bytes)?;
+ for e in &mut feed.entries {
+ if e.title.is_none() {
+ e.title = untitled_name(e.description.as_deref(), e.enclosures.first().map(|x| x.url.as_str()));
+ }
+ }
+ Ok(feed)
+}
+
+/// A name for an item its feed gave no title: the first words of its text, cut at a word near
+/// 120 characters, or else its file's name without the extension. What the page worked out each
+/// time it drew one, until the iOS widget, CarPlay and search, which never saw it, needed it too.
+pub fn untitled_name(description: Option<&str>, file: Option<&str>) -> Option {
+ // Entities decoded, spaces made single; a tag is a space, so "2010)
Recorded" stays apart.
+ let words = description
+ .and_then(|d| title_text(Some(&text_of(d).split_whitespace().collect::>().join(" "))))
+ .unwrap_or_default();
+ if !words.is_empty() {
+ let mut chars = words.chars();
+ let head: String = chars.by_ref().take(120).collect();
+ if chars.next().is_none() {
+ return Some(words);
+ }
+ // The word the cut fell in is dropped whole, as the page's /\s+\S*$/ did.
+ let cut = head.rfind(char::is_whitespace).map_or(head.as_str(), |at| head[..at].trim_end());
+ return Some(format!("{cut}\u{2026}"));
+ }
+ let path = file?.split(['?', '#']).next()?;
+ let last = path.rsplit('/').next().filter(|s| !s.is_empty())?;
+ let stem = match last.rsplit_once('.') {
+ Some((stem, ext))
+ if !stem.is_empty() && (1..=5).contains(&ext.len()) && ext.chars().all(|c| c.is_ascii_alphanumeric()) =>
+ {
+ stem
+ }
+ _ => last,
+ };
+ let name =
+ percent_encoding::percent_decode_str(stem).decode_utf8().map_or_else(|_| stem.to_owned(), |d| d.into_owned());
+ non_empty(Some(&name))
+}
+
+fn parse_any(bytes: &[u8]) -> Result {
if bytes.trim_ascii_start().starts_with(b"[")
&& let Ok(posts) = serde_json::from_slice::>(bytes)
{
@@ -613,6 +657,37 @@ mod tests {
use super::*;
use crate::failure;
+ #[test]
+ fn an_untitled_item_is_named_by_its_words_or_its_file() {
+ // Short text whole, decoded, the blocks kept apart.
+ assert_eq!(
+ untitled_name(Some("Fish & chips (2010)
Recorded
"), None).as_deref(),
+ Some("Fish & chips (2010) Recorded")
+ );
+ // Long text cut at the last whole word inside 120 characters.
+ let long = "word ".repeat(40);
+ let name = untitled_name(Some(&long), None).unwrap();
+ assert_eq!(name, format!("{}\u{2026}", "word ".repeat(24).trim_end()));
+ assert!(name.chars().count() <= 121);
+ // No text: the file's name, its query and extension gone, its escapes decoded.
+ assert_eq!(
+ untitled_name(Some("
"), Some("https://x.example/a/Ep%2042.mp3?t=1")).as_deref(),
+ Some("Ep 42")
+ );
+ assert_eq!(untitled_name(None, Some("https://x.example/")), None);
+ assert_eq!(untitled_name(None, None), None);
+ // Through parse: the feed's own title is kept, and only a missing one is made.
+ let feed = parse(
+ br#"t
+ - aHello there
+ - bKeptNot this
+ "#,
+ )
+ .unwrap();
+ let titles: Vec<_> = feed.entries.iter().map(|e| e.title.as_deref()).collect();
+ assert_eq!(titles, [Some("Hello there"), Some("Kept")]);
+ }
+
#[test]
fn parses_rss_with_itunes_extensions() {
let bytes = include_bytes!("../../../tests/data/rss2.xml");
diff --git a/crates/ipx/CHANGELOG.md b/crates/ipx/CHANGELOG.md
index 5853625..bd19839 100644
--- a/crates/ipx/CHANGELOG.md
+++ b/crates/ipx/CHANGELOG.md
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
+- An item its feed gives no title is named as it is stored, by the opening of its text or else its file's name, so search, Signals, the iOS widget and CarPlay show the same name the page does; the untitled items already stored are named once at start (#502).
- Torrents go to qBittorrent through its Web API, set in `[torrent]` (`qbittorrent_url`, `username`, `password`, `save_path`), which downloads and seeds them until the episode is deleted; ipx no longer runs a BitTorrent client of its own or listens on 6881, and `port_range` is gone. Without a qBittorrent set, torrents are held back as when they are turned off (#494, #495).
- The server's command is `ipxd`, not `ipx`: `ipxd daemon`, `ipxd status`, `ipxd user add` and the rest, in the container as `docker exec iPX ipxd ...`. `ipx` is now the reader in a terminal (#437).
diff --git a/crates/ipx/src/db.rs b/crates/ipx/src/db.rs
index 08a6a10..acd0cda 100644
--- a/crates/ipx/src/db.rs
+++ b/crates/ipx/src/db.rs
@@ -1147,6 +1147,48 @@ impl Db {
.collect()
}
+ /// Up to `limit` items stored without a title, after the item `after` in (feed, guid) order:
+ /// feed, guid, description and first file, for naming them (#502). In order, not by
+ /// `title IS NULL` alone, because one with neither text nor file stays untitled and would be
+ /// read again forever.
+ pub async fn untitled(
+ &self,
+ after: (&str, &str),
+ limit: i64,
+ ) -> Result, Option)>> {
+ self.rows(
+ "SELECT e.feed_id, e.guid, e.description,
+ (SELECT x.url FROM enclosures x WHERE x.feed_id = e.feed_id AND x.guid = e.guid
+ ORDER BY x.id LIMIT 1) AS file
+ FROM entries e
+ WHERE e.title IS NULL AND (e.feed_id > $1 OR (e.feed_id = $1 AND e.guid > $2))
+ ORDER BY e.feed_id, e.guid LIMIT $3",
+ vec![after.0.into(), after.1.into(), limit.into()],
+ )
+ .await?
+ .iter()
+ .map(|r| {
+ Ok((
+ r.try_get("", "feed_id")?,
+ r.try_get("", "guid")?,
+ r.try_get("", "description")?,
+ r.try_get("", "file")?,
+ ))
+ })
+ .collect()
+ }
+
+ /// Names an untitled item, unless a scan has titled it meanwhile, and leaves its search text to
+ /// be made again with the name in it.
+ pub async fn name_untitled(&self, feed_id: &str, guid: &str, title: &str) -> Result<()> {
+ self.exec(
+ "UPDATE entries SET title = $3, search_text = NULL WHERE feed_id = $1 AND guid = $2 AND title IS NULL",
+ vec![feed_id.into(), guid.into(), title.into()],
+ )
+ .await?;
+ Ok(())
+ }
+
pub async fn set_search_text(&self, feed_id: &str, guid: &str, text: &str) -> Result<()> {
self.exec(
"UPDATE entries SET search_text = $3 WHERE feed_id = $1 AND guid = $2",
@@ -3927,6 +3969,42 @@ mod tests {
assert!(!order_sql("x'; --", "asc").contains("x'"));
}
+ #[tokio::test]
+ async fn items_stored_untitled_are_named_once_from_their_words_or_file() {
+ let db = Db::memory().await.unwrap();
+ db.exec_for_test(
+ "INSERT INTO entries (feed_id, guid, title, description, first_seen, search_text) VALUES
+ ('f','words',NULL,'Hello there
',1,'x'), ('f','file',NULL,NULL,2,'x'),
+ ('f','none',NULL,NULL,3,'x'), ('f','kept','Mine','Other words',4,'x');
+ INSERT INTO enclosures (id, feed_id, guid, url, state) VALUES (1,'f','file','http://x/Ep%201.mp3','skipped');",
+ )
+ .await
+ .unwrap();
+ crate::search::name_untitled(&db).await.unwrap();
+ let rows = db.rows("SELECT guid, title, search_text FROM entries ORDER BY first_seen", vec![]).await.unwrap();
+ let got: Vec<(String, Option, Option)> = rows
+ .iter()
+ .map(|r| {
+ (r.try_get("", "guid").unwrap(), r.try_get("", "title").unwrap(), r.try_get("", "search_text").unwrap())
+ })
+ .collect();
+ let named = |g: &str, t: Option<&str>, search: Option<&str>| {
+ (g.to_owned(), t.map(str::to_owned), search.map(str::to_owned))
+ };
+ assert_eq!(
+ got,
+ [
+ named("words", Some("Hello there"), None),
+ named("file", Some("Ep 1"), None),
+ // Nothing to name it by: left alone, search text and all, and not looked at forever.
+ named("none", None, Some("x")),
+ named("kept", Some("Mine"), Some("x")),
+ ]
+ );
+ // A second pass finds nothing more to do.
+ crate::search::name_untitled(&db).await.unwrap();
+ }
+
#[tokio::test]
async fn the_feed_list_in_one_go_matches_asking_feed_by_feed() {
let db = Db::memory().await.unwrap();
diff --git a/crates/ipx/src/search.rs b/crates/ipx/src/search.rs
index 505d254..5553e30 100644
--- a/crates/ipx/src/search.rs
+++ b/crates/ipx/src/search.rs
@@ -55,6 +55,7 @@ pub async fn run(ctx: Arc, mut stop: tokio::sync::watch::Receiver) {
/// Every item without search text, given one, a batch at a time: how many.
async fn fill(ctx: &Ctx) -> anyhow::Result {
+ name_untitled(&ctx.db).await?;
let mut made = 0;
loop {
let batch = ctx.db.unsearched(BATCH).await?;
@@ -68,6 +69,23 @@ async fn fill(ctx: &Ctx) -> anyhow::Result {
}
}
+/// Names the items stored before a feed's untitled ones were named as they were read (#502),
+/// once, in batches; then finds none and costs one query a pass. Before the search text, which
+/// the name goes into.
+pub(crate) async fn name_untitled(db: &crate::db::Db) -> anyhow::Result<()> {
+ let mut after = (String::new(), String::new());
+ loop {
+ let batch = db.untitled((&after.0, &after.1), BATCH).await?;
+ let Some(last) = batch.last() else { return Ok(()) };
+ after = (last.0.clone(), last.1.clone());
+ for (feed, guid, description, file) in &batch {
+ if let Some(name) = crate::feed::untitled_name(description.as_deref(), file.as_deref()) {
+ db.name_untitled(feed, guid, &name).await?;
+ }
+ }
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/tests/page-unit.ts b/tests/page-unit.ts
index b4280be..cf58860 100644
--- a/tests/page-unit.ts
+++ b/tests/page-unit.ts
@@ -141,6 +141,15 @@ test('an item without a title is named by its file', () => {
assert.deepEqual({ ...name({ enclosures: [{ url: 'https://x/100%.mp3' }] }) }, { text: '100%', derived: true });
});
+test('a title that only opens the text is not shown above it again (#502)', () => {
+ const echoes = (e: object, words: string) => run(`titleEchoes(${JSON.stringify(e)}, ${JSON.stringify(words)})`);
+ assert.equal(echoes({ title: 'Hello there' }, 'Hello there'), true);
+ assert.equal(echoes({ title: 'A long post cut\u2026' }, 'A long post cut short here'), true);
+ assert.equal(echoes({ title: 'Episode 1' }, 'In this episode we talk'), false);
+ assert.equal(echoes({ title: 'Anything' }, ''), false);
+ assert.equal(echoes({}, 'Words'), false);
+});
+
test('the directory sorts by name as people read, and by subscribers', () => {
const sorted = (list: object[], by: string) => run(`${JSON.stringify(list)}.sort(${by}).map(p => p.title)`);
assert.deepEqual([...sorted([{ title: 'ep 10' }, { title: 'Ep 2' }, { title: 'ep 1' }], 'byName')], ['ep 1', 'Ep 2', 'ep 10']);
diff --git a/web/CHANGELOG.md b/web/CHANGELOG.md
index c9e6786..b15aa1a 100644
--- a/web/CHANGELOG.md
+++ b/web/CHANGELOG.md
@@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
+- A title that is only the opening of an item's own text, as ipx now names an untitled item, is not shown again above that text in the reader or a directory preview (#502).
- A folder's triangle in the feed list is at its row's end, before the count, so every feed lines up with the places above at the list's edge, and on a phone Playlists' and Signals' + button sits beside the title rather than on a line of its own (#486, #487).
- On a phone, an episode's title starts at the row's edge: the read and pin buttons are gone from the row, an unread episode has a dot before its title and a pinned one a pin under it, and both are changed from the reader's actions (#484).
- Podcasts are in order by name with a leading "The", "A" or "An" set aside, in the feed list, the Podcasts shelf, a playlist's choices and the Directory: The Rest Is Science is under R, not T (#481).
diff --git a/web/src/dialogs.ts b/web/src/dialogs.ts
index 7381697..a7711ed 100644
--- a/web/src/dialogs.ts
+++ b/web/src/dialogs.ts
@@ -279,7 +279,9 @@ async function fillShow(box: HTMLElement,p: DirFeed){
}
const items=got.items;
list.innerHTML=items.length?items.map(e=>{
- const name=entryName(e), text=name.derived?'':plainText(e.description).slice(0,500);
+ const name=entryName(e), words=plainText(e.description);
+ // No excerpt that only repeats the name ipx made from these same words (#502).
+ const text=name.derived||titleEchoes(e,words)?'':words.slice(0,500);
const when=[dateOf(e.published),e.duration&&clock(e.duration)].filter(Boolean);
return `${webUrl(e.link)?`${esc(name.text)}`:esc(name.text)}`
+(text?`${esc(text)}
`:'')
diff --git a/web/src/items.ts b/web/src/items.ts
index 6fda0c3..74cd134 100644
--- a/web/src/items.ts
+++ b/web/src/items.ts
@@ -284,6 +284,12 @@ const feedName=(id: string|null|undefined): string=>{ const f=S.feeds.find(x=>x.
const plainText=(html?: string|null)=>html
? (new DOMParser().parseFromString(html.replace(/<(br|\/p|\/div|\/li|\/h\d)\b[^>]*>/gi,' $&'),'text/html').body.textContent||'')
.replace(/\s+/g,' ').trim() : '';
+/// Whether the title is only the opening of the item's own text: the name ipx gives an untitled
+/// item as it stores it (#502), or a post titled by its first sentence. Shown above that text, it
+/// reads twice.
+const titleEchoes=(e: Partial, words=plainText(e.description))=>
+ !!e.title && !!words && words.startsWith(e.title.trim().replace(/\u2026$/,''));
+// ipx names an untitled item as it stores it (#502); this is for a list saved offline before then.
function entryName(e: Partial): {text: string, derived: boolean}{
if(e.title&&e.title.trim()) return {text:e.title, derived:false};
const words=plainText(e.description);
@@ -465,7 +471,7 @@ function detailHtml(e: Entry){
at hand anywhere in a long post, not only back at its top. */
narrow ? `${back}${acts}
` : back}
${/* A post without a title starts with its text: its own first words as a heading above
- themselves would read as a mistake. */ e.title&&e.title.trim() ? `${esc(e.title)}
` : ''}
+ themselves would read as a mistake. */ e.title&&e.title.trim()&&!titleEchoes(e) ? `${esc(e.title)}
` : ''}
${/* Joined, so a missing date or number leaves no stray dot behind. */
[f&&esc(f.title||f.id), num, dateOf(e.published), e.duration&&clock(e.duration),