Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
* " על <base book>", 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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
}
}
Loading