Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process chapter list names for manga #3

Merged
merged 1 commit into from
Aug 10, 2023
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
5 changes: 3 additions & 2 deletions crates/tanoshi-web/src/manga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
32 changes: 32 additions & 0 deletions crates/tanoshi-web/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
Loading