Skip to content

Commit

Permalink
feat(manhuagui): add sorting methods (#384)
Browse files Browse the repository at this point in the history
* chore(manhuagui): update source's version

* fix(manhuagui): set appropriate `nsfw` value

* feat(manhuagui): add sorting methods

* chore(manhuagui): update `Cargo.lock`
  • Loading branch information
aphronyx authored Jul 15, 2023
1 parent c008554 commit c29568c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/rust/zh.manhuagui/res/filters.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,15 @@
"连载",
"完结"
]
},
{
"type": "sort",
"name": "排序方式",
"options": [
"最新发布",
"最新更新",
"人气最旺",
"评分最高"
]
}
]
4 changes: 2 additions & 2 deletions src/rust/zh.manhuagui/res/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"id": "zh.manhuagui",
"lang": "zh",
"name": "ManHuaGui",
"version": 1,
"version": 2,
"url": "https://www.manhuagui.com/",
"nsfw": 0
"nsfw": 1
}
}
11 changes: 10 additions & 1 deletion src/rust/zh.manhuagui/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const FILTER_AUDIENCE: [&str; 6] = [
"all", "shaonv", "shaonian", "qingnian", "ertong", "tongyong",
];
const FILTER_PROGRESS: [&str; 3] = ["all", "lianzai", "wanjie"];
const SORT: [&str; 4] = ["index", "update", "view", "rate"];

pub fn parse_home_page(html: Node) -> Result<MangaPageResult> {
let mut mangas: Vec<Manga> = Vec::new();
Expand Down Expand Up @@ -305,6 +306,7 @@ pub fn get_filtered_url(filters: Vec<Filter>, page: i32, url: &mut String) {
let mut genre: &str = "all";
let mut audience: &str = "all";
let mut progress: &str = "all";
let mut sort_by = SORT[0];

for filter in filters {
match filter.kind {
Expand All @@ -325,6 +327,13 @@ pub fn get_filtered_url(filters: Vec<Filter>, page: i32, url: &mut String) {
_ => continue,
};
}
FilterType::Sort => {
let Ok(obj) = filter.value.as_object() else {
continue;
};
let index = obj.get("index").as_int().unwrap_or(0) as usize;
sort_by = SORT[index];
}
_ => continue,
}
}
Expand All @@ -349,7 +358,7 @@ pub fn get_filtered_url(filters: Vec<Filter>, page: i32, url: &mut String) {
filter_str = format!("/{}", filter_str)
}

let page_str = format!("/index_p{}.html", page.to_string());
let page_str = format!("/{}_p{}.html", sort_by, page.to_string());

url.push_str(filter_str.as_str());
url.push_str(page_str.as_str())
Expand Down

0 comments on commit c29568c

Please sign in to comment.