From 6feb347c2724fb43f3f882233491eab1ff6d22e3 Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Tue, 9 Feb 2021 12:08:38 -0800 Subject: [PATCH] Fix post ID parsing --- src/main.rs | 16 ++++++++-------- templates/utils.html | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index b3dcd6e..1d2f0c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,6 @@ // Import Crates // use askama::filters::format; -use surf::utils::async_trait; -use tide::{utils::After, Middleware, Next, Request, Response}; +use tide::{Middleware, Next, Request, Response, utils::{After, async_trait}}; // Reference local files mod post; @@ -150,6 +149,7 @@ async fn main() -> tide::Result<()> { app.at("/manifest.json/").get(manifest); app.at("/logo.png/").get(pwa_logo); app.at("/touch-icon-iphone.png/").get(iphone_logo); + app.at("/apple-touch-icon.png/").get(iphone_logo); // Proxy media through Libreddit app.at("/proxy/*url/").get(proxy::handler); @@ -199,13 +199,13 @@ async fn main() -> tide::Result<()> { // Search all of Reddit app.at("/search/").get(search::find); - // Short link for post - // .route("/{sort:best|hot|new|top|rising|controversial}/", web::get().to(subreddit::page)) - // .route("/{id:.{5,6}}/", web::get().to(post::item)) app.at("/:id/").get(|req: Request<()>| async { - match req.param("id").unwrap_or_default() { - "best" | "hot" | "new" | "top" | "rising" | "controversial" => subreddit::page(req).await, - _ => post::item(req).await, + match req.param("id") { + // Sort front page + Ok("best") | Ok("hot") | Ok("new") | Ok("top") | Ok("rising") | Ok("controversial") => subreddit::page(req).await, + // Short link for post + Ok(id) if id.len() > 4 && id.len() < 7 => post::item(req).await, + _ => utils::error("Nothing here".to_string()).await } }); diff --git a/templates/utils.html b/templates/utils.html index ed48e1e..38fab64 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -36,7 +36,7 @@ {% macro render_flair(flair) -%} {% for flair_part in flair %} {% if flair_part.flair_part_type == "emoji" %} - {% else if flair_part.flair_part_type == "text" %}{{ flair_part.value }}{% endif %} + {% else if flair_part.flair_part_type == "text" && !flair_part.value.is_empty() %}{{ flair_part.value }}{% endif %} {% endfor %} {%- endmacro %}