mirror of
https://github.com/gotson/komga.git
synced 2025-01-09 04:08:00 +08:00
fix: strip accented characters for title sort when creating series
closes #188
This commit is contained in:
parent
d2123a5590
commit
6f1e36e7dc
@ -2,6 +2,7 @@ package org.gotson.komga.domain.service
|
||||
|
||||
import mu.KotlinLogging
|
||||
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
import org.gotson.komga.domain.model.Book
|
||||
import org.gotson.komga.domain.model.BookMetadata
|
||||
import org.gotson.komga.domain.model.Media
|
||||
@ -13,7 +14,7 @@ import org.gotson.komga.domain.persistence.MediaRepository
|
||||
import org.gotson.komga.domain.persistence.SeriesMetadataRepository
|
||||
import org.gotson.komga.domain.persistence.SeriesRepository
|
||||
import org.springframework.stereotype.Service
|
||||
import java.util.*
|
||||
import java.util.Comparator
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
private val natSortComparator: Comparator<String> = CaseInsensitiveSimpleNaturalComparator.getInstance()
|
||||
@ -74,6 +75,7 @@ class SeriesLifecycle(
|
||||
seriesMetadataRepository.insert(
|
||||
SeriesMetadata(
|
||||
title = createdSeries.name,
|
||||
titleSort = StringUtils.stripAccents(createdSeries.name),
|
||||
seriesId = createdSeries.id
|
||||
)
|
||||
)
|
||||
|
@ -6,6 +6,7 @@ import org.gotson.komga.domain.model.makeLibrary
|
||||
import org.gotson.komga.domain.model.makeSeries
|
||||
import org.gotson.komga.domain.persistence.BookRepository
|
||||
import org.gotson.komga.domain.persistence.LibraryRepository
|
||||
import org.gotson.komga.domain.persistence.SeriesMetadataRepository
|
||||
import org.gotson.komga.domain.persistence.SeriesRepository
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
@ -24,6 +25,7 @@ class SeriesLifecycleTest(
|
||||
@Autowired private val seriesLifecycle: SeriesLifecycle,
|
||||
@Autowired private val bookLifecycle: BookLifecycle,
|
||||
@Autowired private val seriesRepository: SeriesRepository,
|
||||
@Autowired private val seriesMetadataRepository: SeriesMetadataRepository,
|
||||
@Autowired private val bookRepository: BookRepository,
|
||||
@Autowired private val libraryRepository: LibraryRepository
|
||||
) {
|
||||
@ -130,4 +132,31 @@ class SeriesLifecycleTest(
|
||||
assertThat(savedBooks.map { it.name }).containsExactly("book 1", "book 2", "book 3", "book 4", "book 5")
|
||||
assertThat(savedBooks.map { it.number }).containsExactly(1, 2, 3, 4, 5)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given series name with diacritics when creating series then diacritics are stripped from metadata titlesort`() {
|
||||
// given
|
||||
val series1 = makeSeries("À l'assaut", library.id)
|
||||
val series2 = makeSeries("Être ou ne pas être", library.id)
|
||||
val series3 = makeSeries("Écarlate", library.id)
|
||||
|
||||
// when
|
||||
val created1 = seriesLifecycle.createSeries(series1)
|
||||
val created2 = seriesLifecycle.createSeries(series2)
|
||||
val created3 = seriesLifecycle.createSeries(series3)
|
||||
|
||||
// then
|
||||
with(seriesMetadataRepository.findById(created1.id)) {
|
||||
assertThat(title).isEqualTo(series1.name)
|
||||
assertThat(titleSort).isEqualTo("A l'assaut")
|
||||
}
|
||||
with(seriesMetadataRepository.findById(created2.id)) {
|
||||
assertThat(title).isEqualTo(series2.name)
|
||||
assertThat(titleSort).isEqualTo("Etre ou ne pas etre")
|
||||
}
|
||||
with(seriesMetadataRepository.findById(created3.id)) {
|
||||
assertThat(title).isEqualTo(series3.name)
|
||||
assertThat(titleSort).isEqualTo("Ecarlate")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user