diff --git a/src/post.rs b/src/post.rs index 1f53d4a..f6f13dc 100644 --- a/src/post.rs +++ b/src/post.rs @@ -43,6 +43,9 @@ async fn render(id: String, sort: String) -> Result { } .render() .unwrap(); + + // println!("{}", s); + Ok(HttpResponse::Ok().content_type("text/html").body(s)) } @@ -80,13 +83,6 @@ async fn media(data: &serde_json::Value) -> String { } } -fn html_escape(input: String) -> String { - input - .replace("&", "&") - .replace("’", "'") - .replace("\"", """) -} - // POSTS async fn fetch_post (id: &String) -> Post { let url: String = format!("https://reddit.com/{}.json", id); @@ -100,9 +96,9 @@ async fn fetch_post (id: &String) -> Post { let score = post_data["data"]["score"].as_i64().unwrap(); Post { - title: html_escape(val(post_data, "title").await), + title: val(post_data, "title").await, community: val(post_data, "subreddit").await, - body: html_escape(markdown_to_html(post_data["data"]["selftext"].as_str().unwrap(), &ComrakOptions::default())), + body: markdown_to_html(post_data["data"]["selftext"].as_str().unwrap(), &ComrakOptions::default()), author: val(post_data, "author").await, url: val(post_data, "permalink").await, score: if score>1000 {format!("{}k",score/1000)} else {score.to_string()}, @@ -127,8 +123,10 @@ async fn fetch_comments (id: String, sort: &String) -> Result, Box< let score = comment["data"]["score"].as_i64().unwrap_or(0); let body = markdown_to_html(comment["data"]["body"].as_str().unwrap_or(""), &ComrakOptions::default()); + // println!("{}", body); + comments.push(Comment { - body: html_escape(body), + body: body, author: val(comment, "author").await, score: if score>1000 {format!("{}k",score/1000)} else {score.to_string()}, time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string() diff --git a/src/subreddit.rs b/src/subreddit.rs index 8505721..7f3f9af 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -62,13 +62,6 @@ async fn sorted(web::Path((sub, sort)): web::Path<(String, String)>) -> Result String { String::from(j["data"][k].as_str().unwrap_or("")) } -fn html_escape(input: String) -> String { - input - .replace("&", "&") - .replace("’", "'") - .replace("\"", """) -} - // SUBREDDIT async fn subreddit(sub: &String) -> Subreddit { let url: String = format!("https://www.reddit.com/r/{}/about.json", sub); @@ -82,8 +75,8 @@ async fn subreddit(sub: &String) -> Subreddit { Subreddit { name: val(&data, "display_name").await, - title: html_escape(val(&data, "title").await), - description: html_escape(val(&data, "public_description").await), + title: val(&data, "title").await, + description: val(&data, "public_description").await, icon: String::from(icon_parts[0]), } } @@ -103,7 +96,7 @@ pub async fn posts(sub: String, sort: &String) -> Vec { let unix_time: i64 = post["data"]["created_utc"].as_f64().unwrap().round() as i64; let score = post["data"]["score"].as_i64().unwrap(); posts.push(Post { - title: html_escape(val(post, "title").await), + title: val(post, "title").await, community: val(post, "subreddit").await, author: val(post, "author").await, score: if score>1000 {format!("{}k",score/1000)} else {score.to_string()}, diff --git a/src/user.rs b/src/user.rs index 6c33829..407e0b6 100644 --- a/src/user.rs +++ b/src/user.rs @@ -61,13 +61,6 @@ async fn sorted(web::Path((username, sort)): web::Path<(String, String)>) -> Res async fn user_val (j: &serde_json::Value, k: &str) -> String { String::from(j["data"]["subreddit"][k].as_str().unwrap()) } async fn post_val (j: &serde_json::Value, k: &str) -> String { String::from(j["data"][k].as_str().unwrap_or("Comment")) } -fn html_escape(input: String) -> String { - input - .replace("&", "&") - .replace("’", "'") - .replace("\"", """) -} - // USER async fn user(name: &String) -> User { let url: String = format!("https://www.reddit.com/user/{}/about.json", name); @@ -80,7 +73,7 @@ async fn user(name: &String) -> User { icon: user_val(&data, "icon_img").await, karma: data["data"]["total_karma"].as_i64().unwrap(), banner: user_val(&data, "banner_img").await, - description: html_escape(user_val(&data, "public_description").await) + description: user_val(&data, "public_description").await } } @@ -99,7 +92,7 @@ async fn posts(sub: String, sort: &String) -> Vec { let unix_time: i64 = post["data"]["created_utc"].as_f64().unwrap().round() as i64; let score = post["data"]["score"].as_i64().unwrap(); posts.push(Post { - title: html_escape(post_val(post, "title").await), + title: post_val(post, "title").await, community: post_val(post, "subreddit").await, author: post_val(post, "author").await, score: if score>1000 {format!("{}k",score/1000)} else {score.to_string()}, diff --git a/static/style.css b/static/style.css index 1530a50..5ca516c 100644 --- a/static/style.css +++ b/static/style.css @@ -263,6 +263,7 @@ span { } .comment_right { + word-wrap: anywhere; padding: 20px 25px; flex-grow: 1; flex-shrink: 1; diff --git a/templates/popular.html b/templates/popular.html index 372e9ab..1a3c399 100644 --- a/templates/popular.html +++ b/templates/popular.html @@ -2,7 +2,14 @@ Libreddit + +
diff --git a/templates/post.html b/templates/post.html index 3e345f7..65f83ec 100644 --- a/templates/post.html +++ b/templates/post.html @@ -3,12 +3,13 @@ {{ post.title }} - r/{{ post.community }} + diff --git a/templates/subreddit.html b/templates/subreddit.html index 20dc879..af862bb 100644 --- a/templates/subreddit.html +++ b/templates/subreddit.html @@ -2,7 +2,14 @@ r/{{ sub.name }}: {{ sub.description }} + +
diff --git a/templates/user.html b/templates/user.html index 81bdde3..3b54d87 100644 --- a/templates/user.html +++ b/templates/user.html @@ -2,7 +2,14 @@ Libreddit: u/{{ user.name }} + +