diff options
author | Colin Reeder <colin@vpzom.click> | 2020-06-10 21:21:34 -0600 |
---|---|---|
committer | Colin Reeder <colin@vpzom.click> | 2020-06-10 21:21:34 -0600 |
commit | d502022425d811b2df51928fadac51d5e467d382 (patch) | |
tree | 76dd80eae0d74d5b8682554543a9f0322594869e | |
parent | 24d53276155e4e4fbb3746e787bc5b449999f7c1 (diff) |
Separate post link from post href
-rw-r--r-- | src/routes/mod.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/routes/mod.rs b/src/routes/mod.rs index ec8d713..f37f576 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -144,6 +144,9 @@ fn HTPage<'base_data, Children: render::Render>( <> <render::html::HTML5Doctype /> <html> + <head> + <meta charset={"utf-8"} /> + </head> <body> <header class={"mainHeader"}> <div><a href={"/"}>{"lotide"}</a></div> @@ -167,14 +170,37 @@ fn HTPage<'base_data, Children: render::Render>( } } +fn abbreviate_link(href: &str) -> &str { + // Attempt to find the hostname from the URL + match href.find("://") { + Some(idx1) => match href[(idx1 + 3)..].find('/') { + Some(idx2) => Some(&href[(idx1 + 3)..(idx1 + 3 + idx2)]), + None => None, + }, + None => None, + } + .unwrap_or(href) +} + #[render::component] fn PostItem<'post>(post: &'post RespPostListPost<'post>, in_community: bool) { - let post_link = format!("/posts/{}", post.id).into(); render::rsx! { <li> - <a href={post.href.map(Cow::from).unwrap_or(post_link)}> + <a href={format!("/posts/{}", post.id)}> {post.title} </a> + { + if let Some(href) = post.href { + Some(render::rsx! { + <> + {" "} + <em><a href={href}>{abbreviate_link(href)}{" ↗"}</a></em> + </> + }) + } else { + None + } + } <br /> {"Submitted by "}<UserLink user={post.author.as_ref()} /> { |