From 3e74fb12842122af805a52e3a854250a12c6b68c Mon Sep 17 00:00:00 2001 From: Elie Gambache Date: Thu, 8 Oct 2026 12:24:03 +0300 Subject: [PATCH] fix(sefariasqlite): name the Maharsha in his Talmud commentaries' titles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sefaria titles the Maharsha's commentaries "חידושי הלכות/אגדות על <מסכת>", and the app lists a commentary by its title without " על ", so the reader saw "חידושי אגדות" with no hint it is the Maharsha. Prefix the display title with "מהרש\"א - " for the Chidushei Halachot and Chidushei Agadot collections (45 books). heTitle stays the natural key, so book ids are unchanged and the delta ships plain upsert_book rows. Fixes kdroidFilter/Zayit#440 Signed-off-by: Elie Gambache --- .../sefariasqlite/SefariaBookTitles.kt | 20 +++++++++++++ .../sefariasqlite/SefariaDirectImporter.kt | 2 +- .../sefariasqlite/SefariaBookTitlesTest.kt | 28 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 generator/sefariasqlite/src/jvmMain/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaBookTitles.kt create mode 100644 generator/sefariasqlite/src/jvmTest/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaBookTitlesTest.kt diff --git a/generator/sefariasqlite/src/jvmMain/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaBookTitles.kt b/generator/sefariasqlite/src/jvmMain/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaBookTitles.kt new file mode 100644 index 00000000..7080fc22 --- /dev/null +++ b/generator/sefariasqlite/src/jvmMain/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaBookTitles.kt @@ -0,0 +1,20 @@ +package io.github.kdroidfilter.seforimlibrary.sefariasqlite + +/** + * Author prefixes for Sefaria collections whose Hebrew title doesn't name the author, + * keyed by English collective title. The app shows a commentary by its title without + * " על ", so "חידושי אגדות" alone doesn't tell the reader it's the Maharsha. + */ +private val authorPrefixesByCollectiveTitle = mapOf( + "Chidushei Agadot" to "מהרש\"א", + "Chidushei Halachot" to "מהרש\"א", +) + +/** + * Title displayed for a Sefaria book: its Hebrew title, prefixed with the author when + * its collection needs it. Only the display title changes; `heTitle` stays the natural key. + */ +internal fun sefariaDisplayTitle(heTitle: String, collectiveTitleEn: String?): String { + val prefix = collectiveTitleEn?.let { authorPrefixesByCollectiveTitle[it] } ?: return heTitle + return if (heTitle.startsWith(prefix)) heTitle else "$prefix - $heTitle" +} diff --git a/generator/sefariasqlite/src/jvmMain/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaDirectImporter.kt b/generator/sefariasqlite/src/jvmMain/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaDirectImporter.kt index c3336e25..55772ae8 100644 --- a/generator/sefariasqlite/src/jvmMain/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaDirectImporter.kt +++ b/generator/sefariasqlite/src/jvmMain/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaDirectImporter.kt @@ -238,7 +238,7 @@ class SefariaDirectImporter( id = bookId, categoryId = catId, sourceId = sourceId, - title = payload.heTitle, + title = sefariaDisplayTitle(payload.heTitle, payload.collectiveTitleEn), heRef = payload.heTitle, authors = resolvedAuthors, pubPlaces = emptyList(), diff --git a/generator/sefariasqlite/src/jvmTest/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaBookTitlesTest.kt b/generator/sefariasqlite/src/jvmTest/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaBookTitlesTest.kt new file mode 100644 index 00000000..f49b0c22 --- /dev/null +++ b/generator/sefariasqlite/src/jvmTest/kotlin/io/github/kdroidfilter/seforimlibrary/sefariasqlite/SefariaBookTitlesTest.kt @@ -0,0 +1,28 @@ +package io.github.kdroidfilter.seforimlibrary.sefariasqlite + +import kotlin.test.Test +import kotlin.test.assertEquals + +/** + * Regression for https://github.com/kdroidFilter/Zayit/issues/440: the Maharsha's + * commentaries were listed as "חידושי הלכות" / "חידושי אגדות" without his name. + */ +class SefariaBookTitlesTest { + @Test + fun prefixesMaharshaCollections() { + assertEquals( + "מהרש\"א - חידושי אגדות על חולין", + sefariaDisplayTitle("חידושי אגדות על חולין", "Chidushei Agadot"), + ) + assertEquals( + "מהרש\"א - חידושי הלכות על שבת", + sefariaDisplayTitle("חידושי הלכות על שבת", "Chidushei Halachot"), + ) + } + + @Test + fun keepsOtherTitles() { + assertEquals("רש\"י על ברכות", sefariaDisplayTitle("רש\"י על ברכות", "Rashi")) + assertEquals("ברכות", sefariaDisplayTitle("ברכות", null)) + } +}