Skip to content

Commit

Permalink
Merge pull request #327 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Fix slug calculation
  • Loading branch information
Ziedelth authored Mar 30, 2024
2 parents dbaab49 + 43112ab commit 25a00eb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/main/kotlin/fr/shikkanime/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import fr.shikkanime.services.MemberService
import fr.shikkanime.utils.Constant
import fr.shikkanime.utils.JobManager
import fr.shikkanime.utils.LoggerFactory
import fr.shikkanime.utils.StringUtils
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
Expand All @@ -35,7 +36,18 @@ fun initAll(adminPassword: AtomicReference<String>?, port: Int = 37100, wait: Bo
}
}

Constant.injector.getInstance(AnimeService::class.java).preIndex()
val animeService = Constant.injector.getInstance(AnimeService::class.java)
animeService.preIndex()

animeService.findAll().forEach {
val toSlug = StringUtils.toSlug(StringUtils.getShortName(it.name!!))

if (it.slug != toSlug) {
it.slug = toSlug
animeService.update(it)
}
}

ImageService.addAll()

logger.info("Starting jobs...")
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/fr/shikkanime/services/AnimeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class AnimeService : AbstractService<Anime, AnimeRepository>() {
val anime = find(uuid) ?: return null

parameters["name"]?.takeIf { it.isNotBlank() }?.let { anime.name = it }
parameters["slug"]?.takeIf { it.isNotBlank() }?.let { anime.slug = it }
parameters["releaseDateTime"]?.takeIf { it.isNotBlank() }
?.let { anime.releaseDateTime = ZonedDateTime.parse("$it:00Z") }

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/fr/shikkanime/utils/StringUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ object StringUtils {
val firstPart = split[0].trim()
val lastPart = split.subList(1, split.size).joinToString(" ").trim()

if (lastPart.count { it == ' ' } >= 2) {
if (lastPart.count { it == ' ' } >= 2 &&
(firstPart.split(" ").size > 1 || firstPart.length > 5)) {
shortName = firstPart
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/templates/admin/animes/edit.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
<input type="text" class="form-control" id="shortName" name="shortName"
value="${su.sanitizeXSS(anime.shortName)}" disabled>
</div>
<div class="col-md-6">
<label for="slug" class="form-label">Short name</label>
<input type="text" class="form-control" id="slug" name="slug"
value="${anime.slug}">
</div>
<div class="col-md-6">
<label for="releaseDateTime" class="form-label">Release date time</label>
<input type="datetime-local" class="form-control" id="releaseDateTime" name="releaseDateTime"
Expand Down
5 changes: 4 additions & 1 deletion src/test/kotlin/fr/shikkanime/utils/StringUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class StringUtilsTest {
"BIRDIE WING" to "BIRDIE WING -Golf Girls' Story-",
"Urusei Yatsura" to "Urusei Yatsura (2022)",
"Cherry Magic" to "Cherry Magic! Thirty Years of Virginity Can Make You a Wizard?!",
"KONOSUBA" to "KONOSUBA -God's blessing on this wonderful world!"
"KONOSUBA" to "KONOSUBA -God's blessing on this wonderful world!",
"Moi, quand je me réincarne en Slime" to "Moi, quand je me réincarne en Slime",
"Studio Apartment" to "Studio Apartment, Good Lighting, Angel Included",
)

list.forEach { (expected, input) ->
Expand All @@ -44,6 +46,7 @@ class StringUtilsTest {
fun toSlug() {
val list = listOf(
"Gloutons & Dragons" to "gloutons-dragons",
"Moi, quand je me réincarne en Slime" to "moi-quand-je-me-reincarne-en-slime",
)

list.forEach { (input, expected) ->
Expand Down

0 comments on commit 25a00eb

Please sign in to comment.