diff --git a/src/utils.rs b/src/utils.rs index 6b96b0d..7379bee 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -124,11 +124,11 @@ pub fn param(path: &str, value: &str) -> String { // Direct urls to proxy if proxy is enabled pub fn format_url(url: String) -> String { - if url.is_empty() { - return String::new(); - }; - - format!("/proxy/{}", encode(url).as_str()) + if url.is_empty() || url == "self" || url == "default" { + String::new() + } else { + format!("/proxy/{}", encode(url).as_str()) + } } // Rewrite Reddit links to Libreddit in body of text @@ -185,12 +185,9 @@ pub async fn fetch_posts(path: &str, fallback_title: String) -> Result<(Vec = Vec::new(); + // For each post from posts list for post in post_list { - let img = if val(post, "thumbnail").starts_with("https:/") { - format_url(val(post, "thumbnail")) - } else { - String::new() - }; + let img = format_url(val(post, "thumbnail")); let unix_time: i64 = post["data"]["created_utc"].as_f64().unwrap_or_default().round() as i64; let score = post["data"]["score"].as_i64().unwrap_or_default(); let ratio: f64 = post["data"]["upvote_ratio"].as_f64().unwrap_or(1.0) * 100.0; @@ -221,23 +218,22 @@ pub async fn fetch_posts(path: &str, fallback_title: String) -> Result<(Vec HttpResponse { - let msg = if message.is_empty() { "Page not found".to_string() } else { message }; +pub async fn error(msg: String) -> HttpResponse { let body = ErrorTemplate { message: msg }.render().unwrap_or_default(); HttpResponse::NotFound().content_type("text/html").body(body) } @@ -246,26 +242,7 @@ pub async fn error(message: String) -> HttpResponse { pub async fn request(path: &str) -> Result { let url = format!("https://www.reddit.com/{}", path); - // --- actix-web::client --- - // let client = actix_web::client::Client::default(); - // let res = client - // .get(url) - // .send() - // .await? - // .body() - // .limit(1000000) - // .await?; - - // let body = std::str::from_utf8(res.as_ref())?; // .as_ref converts Bytes to [u8] - - // --- surf --- - // let req = get(&url).header("User-Agent", "libreddit"); - // let client = client().with(Redirect::new(5)); - // let mut res = client.send(req).await.unwrap(); - // let success = res.status().is_success(); - // let body = res.body_string().await.unwrap(); - - // --- reqwest --- + // Send request using reqwest match reqwest::get(&url).await { Ok(res) => { // Read the status from the response @@ -281,13 +258,15 @@ pub async fn request(path: &str) -> Result { } } } + // If Reddit returns error, tell user Page Not Found false => { #[cfg(debug_assertions)] dbg!(format!("{} - Page not found", url)); Err("Page not found") } } - }, + } + // If can't send request to Reddit, return this to user Err(e) => { #[cfg(debug_assertions)] dbg!(format!("{} - {}", url, e)); diff --git a/static/style.css b/static/style.css index 2a4c1c2..b9a1f0a 100644 --- a/static/style.css +++ b/static/style.css @@ -97,6 +97,11 @@ aside { border: 1px solid var(--highlighted); } +.dot { + font-size: 12px; + opacity: 0.5; +} + /* User & Subreddit */ #user, #subreddit, #sidebar { @@ -304,6 +309,10 @@ input[type="submit"]:hover { color: var(--accent); } margin: 20px 0; } +.post.highlighted > .post_right { + flex-direction: column; +} + .post:hover { background: var(--foreground); } @@ -314,7 +323,6 @@ input[type="submit"]:hover { color: var(--accent); } .post_left, .post_right { display: flex; - flex-direction: column; overflow-wrap: break-word; } @@ -322,13 +330,13 @@ input[type="submit"]:hover { color: var(--accent); } text-align: center; background: var(--foreground); border-radius: 5px 0 0 5px; + flex-direction: column; min-width: 50px; } .post_score { margin-top: 20px; color: var(--accent); - font-size: 16px; } #post_footer { @@ -356,12 +364,19 @@ input[type="submit"]:hover { color: var(--accent); } .post_title { font-size: 16px; line-height: 1.5; + margin-top: 10px; +} + +.post_text { + padding: 15px 20px; + display: flex; + flex-direction: column; } .post_right { - padding: 15px 20px; flex-grow: 1; flex-shrink: 1; + justify-content: space-between; } .post_right > * { @@ -381,13 +396,13 @@ input[type="submit"]:hover { color: var(--accent); } #post_url { color: var(--accent); + margin-top: 10px; } .post_thumbnail { object-fit: cover; width: auto; flex-shrink: 0; - margin: 10px; border-radius: 5px; border: 1px solid var(--foreground); max-width: 20%; @@ -477,7 +492,7 @@ input[type="submit"]:hover { color: var(--accent); } } .comment_data > * { - margin: 5px; + margin-right: 5px; } .comment_image { @@ -515,7 +530,7 @@ input[type="submit"]:hover { color: var(--accent); } } .datetime { - opacity: 0.75; + opacity: 0.5; } .line { @@ -597,22 +612,18 @@ td, th { flex-direction: column-reverse; } + .post_header { + font-size: 14px; + } + .post_left { border-radius: 0 0 5px 5px; } - .post_right { - padding: 20px; - } - .post_score { margin: 5px 0; } - .post_thumbnail { - max-width: initial; - } - .replies > .comment { margin-left: -25px; padding: 5px 0; diff --git a/templates/post.html b/templates/post.html index 9fcc42e..45322c1 100644 --- a/templates/post.html +++ b/templates/post.html @@ -25,7 +25,8 @@ {% if item.flair.0 != "" %} {{ item.flair.0 }} {% endif %} - • {{ item.time }} + + {{ item.time }}

{{ item.body }}

{%- endmacro %} @@ -45,35 +46,41 @@ {% if post.flags.nsfw %}
NSFW
{% endif %}
-

- r/{{ post.community }} - • - - {% if post.author_flair.0 != "" %} - {{ post.author_flair.0 }} +

+

+ r/{{ post.community }} + + + {% if post.author_flair.0 != "" %} + {{ post.author_flair.0 }} + {% endif %} + {{ post.time }} +

+ + {{ post.title }} + {% if post.flair.0 != "" %} + {{ post.flair.0 }} + {% endif %} + + + + {% if post.post_type == "image" %} + + {% else if post.post_type == "video" %} +
diff --git a/templates/search.html b/templates/search.html index 9423670..7d49f28 100644 --- a/templates/search.html +++ b/templates/search.html @@ -27,22 +27,25 @@ {% if post.flags.nsfw %}
NSFW
{% endif %}
-

- r/{{ post.community }} - • - {% if post.author_flair.0 != "" %} - {{ post.author_flair.0 }} - {% endif %} - {{ post.time }} -

-

- {% if post.flair.0 != "" %} - {{ post.flair.0 }} - {% endif %} - {{ post.title }} -

+
+

+ r/{{ post.community }} + + + {% if post.author_flair.0 != "" %} + {{ post.author_flair.0 }} + {% endif %} + {{ post.time }} +

+

+ {% if post.flair.0 != "" %} + {{ post.flair.0 }} + {% endif %} + {{ post.title }} +

+
+
- {% else %}
diff --git a/templates/subreddit.html b/templates/subreddit.html index bf32e5a..20c888f 100644 --- a/templates/subreddit.html +++ b/templates/subreddit.html @@ -34,22 +34,22 @@ {% if post.flags.nsfw %}
NSFW
{% endif %}
-

- r/{{ post.community }} - • - {% if post.author_flair.0 != "" %} - {{ post.author_flair.0 }} - {% endif %} - {{ post.time }} -

-

- {% if post.flair.0 != "" %} - {{ post.flair.0 }} - {% endif %} - {{ post.title }} -

+
+

+ r/{{ post.community }} + + + {{ post.time }} +

+

+ {% if post.flair.0 != "" %} + {{ post.flair.0 }} + {% endif %} + {{ post.title }} +

+
+
- {% endfor %} diff --git a/templates/user.html b/templates/user.html index bf81d1d..d81b4c9 100644 --- a/templates/user.html +++ b/templates/user.html @@ -24,24 +24,25 @@ {% if post.flags.nsfw %}
NSFW
{% endif %}
-

- r/{{ post.community }} - • - {% if post.author_flair.0 != "" %} - {{ post.author_flair.0 }} - {% endif %} - {{ post.time }} -

-

- {% if post.flair.0 == "Comment" %} - {% else if post.flair.0 == "" %} - {% else %} - {{ post.flair.0 }} - {% endif %} - {{ post.title }} -

+
+

+ r/{{ post.community }} + {% if post.author_flair.0 != "" %} + {{ post.author_flair.0 }} + {% endif %} + {{ post.time }} +

+

+ {% if post.flair.0 == "Comment" %} + {% else if post.flair.0 == "" %} + {% else %} + {{ post.flair.0 }} + {% endif %} + {{ post.title }} +

+
+
- {% else %}