diff options
author | Colin Reeder <colin@vpzom.click> | 2020-07-06 22:09:07 -0600 |
---|---|---|
committer | Colin Reeder <colin@vpzom.click> | 2020-07-06 22:09:07 -0600 |
commit | e993e8615558507c49ee239cf5b60704ff77e1b5 (patch) | |
tree | 0ec1ae775c81c83254068d69ddac047acf81d9e1 | |
parent | 829a62653ef0f2505960b959a970deecedd63f4c (diff) |
Add page titles (#40)
-rw-r--r-- | src/components/mod.rs | 6 | ||||
-rw-r--r-- | src/routes/communities.rs | 10 | ||||
-rw-r--r-- | src/routes/mod.rs | 22 | ||||
-rw-r--r-- | src/routes/posts.rs | 8 |
4 files changed, 27 insertions, 19 deletions
diff --git a/src/components/mod.rs b/src/components/mod.rs index eff9e40..18f227c 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -138,8 +138,9 @@ impl<'a, T: HavingContent + 'a> render::Render for Content<'a, T> { } #[render::component] -pub fn HTPage<'base_data, Children: render::Render>( - base_data: &'base_data PageBaseData, +pub fn HTPage<'a, Children: render::Render>( + base_data: &'a PageBaseData, + title: &'a str, children: Children, ) { render::rsx! { @@ -149,6 +150,7 @@ pub fn HTPage<'base_data, Children: render::Render>( <head> <meta charset={"utf-8"} /> <link rel={"stylesheet"} href={"/static/main.css"} /> + <title>{title}</title> </head> <body> <header class={"mainHeader"}> diff --git a/src/routes/communities.rs b/src/routes/communities.rs index 9240be5..c407677 100644 --- a/src/routes/communities.rs +++ b/src/routes/communities.rs @@ -27,7 +27,7 @@ async fn page_communities( let communities: Vec<RespMinimalCommunityInfo> = serde_json::from_slice(&api_res)?; Ok(html_response(render::html! { - <HTPage base_data={&base_data}> + <HTPage base_data={&base_data} title={"Communities"}> <h1>{"Communities"}</h1> <div> <h2>{"Local"}</h2> @@ -129,9 +129,11 @@ async fn page_community( let follow_url = format!("/communities/{}/follow", community_id); let new_post_url = format!("/communities/{}/new_post", community_id); + let title = community_info.name.as_ref(); + Ok(html_response(render::html! { - <HTPage base_data={&base_data}> - <h1>{community_info.name.as_ref()}</h1> + <HTPage base_data={&base_data} title> + <h1>{title}</h1> <p> <form method={"POST"} action={&follow_url}> <button r#type={"submit"}>{"Follow"}</button> @@ -195,7 +197,7 @@ async fn page_community_new_post( let submit_url = format!("/communities/{}/new_post/submit", community_id); Ok(html_response(render::html! { - <HTPage base_data={&base_data}> + <HTPage base_data={&base_data} title={"New Post"}> <h1>{"New Post"}</h1> <form method={"POST"} action={&submit_url}> <div> diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 7774a4c..283d496 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -106,7 +106,7 @@ async fn page_about( let base_data = fetch_base_data(&ctx.backend_host, &ctx.http_client, &cookies).await?; Ok(html_response(render::html! { - <HTPage base_data={&base_data}> + <HTPage base_data={&base_data} title={"About lotide"}> <h2>{"What is lotide?"}</h2> <p> {"lotide is an attempt to build a federated forum. "} @@ -159,7 +159,7 @@ async fn page_comment_inner( let comment: RespPostCommentInfo<'_> = serde_json::from_slice(&api_res)?; Ok(html_response(render::html! { - <HTPage base_data={&base_data}> + <HTPage base_data={&base_data} title={"Comment"}> <p> <small><cite><UserLink user={comment.author.as_ref()} /></cite>{":"}</small> <Content src={&comment} /> @@ -218,7 +218,7 @@ async fn page_comment_delete_inner( let comment: RespPostCommentInfo<'_> = serde_json::from_slice(&api_res)?; Ok(html_response(render::html! { - <HTPage base_data={&base_data}> + <HTPage base_data={&base_data} title={"Delete Comment"}> <p> <small><cite><UserLink user={comment.author.as_ref()} /></cite>{":"}</small> <br /> @@ -383,7 +383,7 @@ async fn page_login_inner( let base_data = fetch_base_data(&ctx.backend_host, &ctx.http_client, &cookies).await?; Ok(html_response(render::html! { - <HTPage base_data={&base_data}> + <HTPage base_data={&base_data} title={"Login"}> { display_error.map(|msg| { render::rsx! { @@ -530,7 +530,7 @@ async fn page_lookup( .body("Redirecting…".into())?), api_res => { Ok(html_response(render::html! { - <HTPage base_data={&base_data}> + <HTPage base_data={&base_data} title={"Lookup"}> <h1>{"Lookup"}</h1> <form method={"GET"} action={"/lookup"}> <input r#type={"text"} name={"query"} value={query.as_deref().unwrap_or("")} /> @@ -574,7 +574,7 @@ async fn page_new_community_inner( let base_data = fetch_base_data(&ctx.backend_host, &ctx.http_client, &cookies).await?; Ok(html_response(render::html! { - <HTPage base_data={&base_data}> + <HTPage base_data={&base_data} title={"New Community"}> <h1>{"New Community"}</h1> { display_error.map(|msg| { @@ -671,7 +671,7 @@ async fn page_signup_inner( let base_data = fetch_base_data(&ctx.backend_host, &ctx.http_client, &cookies).await?; Ok(html_response(render::html! { - <HTPage base_data={&base_data}> + <HTPage base_data={&base_data} title={"Register"}> { display_error.map(|msg| { render::rsx! { @@ -768,9 +768,11 @@ async fn page_user( let api_res = hyper::body::to_bytes(api_res.into_body()).await?; let user: RespMinimalAuthorInfo<'_> = serde_json::from_slice(&api_res)?; + let title = user.username.as_ref(); + Ok(html_response(render::html! { - <HTPage base_data={&base_data}> - <h1>{user.username.as_ref()}</h1> + <HTPage base_data={&base_data} title> + <h1>{title}</h1> <p> <em>{"User post listing is not currently implemented."}</em> </p> @@ -808,7 +810,7 @@ async fn page_home( let api_res: Vec<RespPostListPost<'_>> = serde_json::from_slice(&api_res)?; Ok(html_response(render::html! { - <HTPage base_data={&base_data}> + <HTPage base_data={&base_data} title={"lotide"}> <ul> {api_res.iter().map(|post| { PostItem { post, in_community: false } diff --git a/src/routes/posts.rs b/src/routes/posts.rs index e5a42f7..25d7089 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -35,9 +35,11 @@ async fn page_post( let post: RespPostInfo = serde_json::from_slice(&api_res)?; + let title = post.as_ref().title.as_ref(); + Ok(html_response(render::html! { - <HTPage base_data={&base_data}> - <h1>{post.as_ref().title.as_ref()}</h1> + <HTPage base_data={&base_data} title={title}> + <h1>{title}</h1> <p> <em>{post.score.to_string()}{" points"}</em> {" "} @@ -138,7 +140,7 @@ async fn page_post_delete( let post: RespPostInfo = serde_json::from_slice(&api_res)?; Ok(html_response(render::html! { - <HTPage base_data={&base_data}> + <HTPage base_data={&base_data} title={"Delete Post"}> <h1>{post.as_ref().title.as_ref()}</h1> <h2>{"Delete this post?"}</h2> <form method={"POST"} action={format!("/posts/{}/delete/confirm", post.as_ref().id)}> |