Split subscription names by +
This commit is contained in:
parent
8785bc95f5
commit
fee2cb1b56
@ -89,11 +89,17 @@ pub async fn subscriptions(req: Request<()>) -> tide::Result {
|
|||||||
|
|
||||||
let mut sub_list = prefs(req).subs;
|
let mut sub_list = prefs(req).subs;
|
||||||
|
|
||||||
|
// Find each subreddit name (separated by '+') in sub parameter
|
||||||
|
let split = sub.split('+');
|
||||||
|
|
||||||
// Modify sub list based on action
|
// Modify sub list based on action
|
||||||
if action.contains(&"subscribe".to_string()) && !sub_list.contains(&sub) {
|
if action.contains(&"subscribe".to_string()) && !sub_list.contains(&sub) {
|
||||||
sub_list.push(sub.to_owned());
|
// Add each sub name to the subscribed list
|
||||||
|
split.map(|part| sub_list.push(part.to_owned())).min();
|
||||||
|
// Reorder sub names alphabettically
|
||||||
sub_list.sort_by_key(|a| a.to_lowercase())
|
sub_list.sort_by_key(|a| a.to_lowercase())
|
||||||
} else if action.contains(&"unsubscribe".to_string()) {
|
} else if action.contains(&"unsubscribe".to_string()) {
|
||||||
|
// Remove sub name from subscribed list
|
||||||
sub_list.retain(|s| s != &sub);
|
sub_list.retain(|s| s != &sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +143,7 @@ pub async fn wiki(req: Request<()>) -> tide::Result {
|
|||||||
match request(path).await {
|
match request(path).await {
|
||||||
Ok(res) => template(WikiTemplate {
|
Ok(res) => template(WikiTemplate {
|
||||||
sub,
|
sub,
|
||||||
wiki: rewrite_url(res["data"]["content_html"].as_str().unwrap_or_default()),
|
wiki: rewrite_urls(res["data"]["content_html"].as_str().unwrap_or_default()),
|
||||||
page,
|
page,
|
||||||
prefs: prefs(req),
|
prefs: prefs(req),
|
||||||
}),
|
}),
|
||||||
@ -172,7 +178,7 @@ async fn subreddit(sub: &str) -> Result<Subreddit, String> {
|
|||||||
name: val(&res, "display_name"),
|
name: val(&res, "display_name"),
|
||||||
title: val(&res, "title"),
|
title: val(&res, "title"),
|
||||||
description: val(&res, "public_description"),
|
description: val(&res, "public_description"),
|
||||||
info: rewrite_url(&val(&res, "description_html").replace("\\", "")),
|
info: rewrite_urls(&val(&res, "description_html").replace("\\", "")),
|
||||||
icon: format_url(icon.as_str()),
|
icon: format_url(icon.as_str()),
|
||||||
members: format_num(members),
|
members: format_num(members),
|
||||||
active: format_num(active),
|
active: format_num(active),
|
||||||
|
@ -192,7 +192,7 @@ pub fn format_url(url: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite Reddit links to Libreddit in body of text
|
// Rewrite Reddit links to Libreddit in body of text
|
||||||
pub fn rewrite_url(text: &str) -> String {
|
pub fn rewrite_urls(text: &str) -> String {
|
||||||
let re = Regex::new(r#"href="(https://|http://|)(www.|old.|np.|)(reddit).(com)/"#).unwrap();
|
let re = Regex::new(r#"href="(https://|http://|)(www.|old.|np.|)(reddit).(com)/"#).unwrap();
|
||||||
re.replace_all(text, r#"href="/"#).to_string()
|
re.replace_all(text, r#"href="/"#).to_string()
|
||||||
}
|
}
|
||||||
@ -369,7 +369,7 @@ pub async fn fetch_posts(path: &str, fallback_title: String) -> Result<(Vec<Post
|
|||||||
id: val(post, "id"),
|
id: val(post, "id"),
|
||||||
title: if title.is_empty() { fallback_title.to_owned() } else { title },
|
title: if title.is_empty() { fallback_title.to_owned() } else { title },
|
||||||
community: val(post, "subreddit"),
|
community: val(post, "subreddit"),
|
||||||
body: rewrite_url(&val(post, "body_html")),
|
body: rewrite_urls(&val(post, "body_html")),
|
||||||
author: Author {
|
author: Author {
|
||||||
name: val(post, "author"),
|
name: val(post, "author"),
|
||||||
flair: Flair {
|
flair: Flair {
|
||||||
|
Loading…
Reference in New Issue
Block a user