From 098cd3e4afd5824ad5d243e16c238e94b3bc4d90 Mon Sep 17 00:00:00 2001 From: luigi311 Date: Wed, 12 Jul 2023 03:34:31 -0600 Subject: [PATCH] Process chapter list names for manga Signed-off-by: luigi311 --- crates/tanoshi-web/src/manga.rs | 5 +++-- crates/tanoshi-web/src/utils.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/crates/tanoshi-web/src/manga.rs b/crates/tanoshi-web/src/manga.rs index f7d668e4..57a80ac6 100644 --- a/crates/tanoshi-web/src/manga.rs +++ b/crates/tanoshi-web/src/manga.rs @@ -3,7 +3,7 @@ use crate::{ ChapterSettings, ChapterSort, Filter, Order, Route, Sort, Spinner, snackbar, SelectCategoryModal, SelectTrackMangaModal, TrackerStatus, icons }, query, - utils::{AsyncLoader, proxied_image_url, window} + utils::{AsyncLoader, proxied_image_url, window, format_number_title} }; use chrono::NaiveDateTime; use dominator::{Dom, EventOptions, clone, events, html, routing, svg, with_node, text_signal}; @@ -713,6 +713,7 @@ impl Manga { let is_edit_chapter = manga.is_edit_chapter.clone(); let filter = manga.chapter_settings.filter.clone(); let touchmoved = Mutable::new(false); + html!("div", { .class("chapter-list") .attr("id", "chapters") @@ -821,7 +822,7 @@ impl Manga { html!("span", { .style("font-weight", "500") .style("margin-bottom", "0.5rem") - .text(&chapter.title) + .text(&format_number_title(chapter.number, &chapter.title)) }), html!("div", { .style("margin-bottom", "0.5rem") diff --git a/crates/tanoshi-web/src/utils.rs b/crates/tanoshi-web/src/utils.rs index 68201979..06d0357a 100644 --- a/crates/tanoshi-web/src/utils.rs +++ b/crates/tanoshi-web/src/utils.rs @@ -147,6 +147,38 @@ pub fn initialize_urls() { .with(|s| *s.borrow_mut() = format!("{}/ws", graphql_host.replace("http", "ws"))); } +pub fn format_number_title(number: f64, title: &str) -> String { + let check_formats_prefixes = ["Chapter "]; + + let mut cleaned_title = title.to_string(); + // remove format from title + for format in check_formats_prefixes.iter() { + if title.starts_with(format) { + cleaned_title = title.replacen(format, "", 1); + cleaned_title = cleaned_title.trim().to_string(); // Trim + } + break; + } + + if cleaned_title.starts_with(&format!("{}", number)) { + cleaned_title = cleaned_title.replacen(&format!("{}", number), "", 1); + cleaned_title = cleaned_title.trim().to_string(); // Trim + } + + // remove characters from title ":" "-" + let check_format_characters = [":", "-"]; + + for format in check_format_characters.iter() { + if cleaned_title.starts_with(format) { + cleaned_title = cleaned_title.replacen(format, "", 1); + cleaned_title = cleaned_title.trim().to_string(); // Trim + } + break; + } + + format!("Ch {}{}", number, if cleaned_title.is_empty() { "".to_string() } else { format!(": {}", cleaned_title) }) +} + pub fn is_tauri() -> bool { IS_TAURI.with(|v| *v.borrow()) }