From 24b109448bc8f1d30c88bbb9d01a05eec74b3d51 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 5 Dec 2021 22:05:36 +0300 Subject: frontend: Added listing feeds to the header bar --- src/frontend/mod.rs | 11 +++++++++-- src/frontend/templates/mod.rs | 8 ++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/frontend') diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index 890879c..6194249 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -257,6 +257,7 @@ pub async fn mainpage(mut req: Request>) -> Resu webmention: None, microsub: None, }, + feeds: Vec::default(), content: OnboardingPage {}.to_string(), } .to_string(), @@ -281,6 +282,7 @@ pub async fn mainpage(mut req: Request>) -> Resu webmention: None, microsub: None, }, + feeds: backend.get_channels(hcard_url).await.unwrap_or_else(|_| Vec::default()), content: MainPage { feed: &feed?, card: &card?, @@ -335,6 +337,7 @@ pub async fn render_post(mut req: Request>) -> R } }; let origin = url.origin(); + let owner = origin.ascii_serialization() + "/"; Ok(Response::builder(200) .content_type("text/html; charset=utf-8") @@ -346,7 +349,7 @@ pub async fn render_post(mut req: Request>) -> R blog_name: &req .state() .storage - .get_setting("site_name", &(origin.ascii_serialization() + "/")) // XXX I'm pretty sure this is bound to cause issues with IDN-style domains + .get_setting("site_name", &owner) // XXX I'm pretty sure this is bound to cause issues with IDN-style domains .await .unwrap_or_else(|_| "Kitty Box!".to_string()), endpoints: IndiewebEndpoints { @@ -355,6 +358,7 @@ pub async fn render_post(mut req: Request>) -> R webmention: None, microsub: None, }, + feeds: req.state().storage.get_channels(&owner).await.unwrap_or_else(|e| Vec::default()), content: template, } .to_string(), @@ -376,12 +380,14 @@ where ) -> Result { let authorization_endpoint = request.state().authorization_endpoint.to_string(); let token_endpoint = request.state().token_endpoint.to_string(); + let owner = request.url().origin().ascii_serialization().clone() + "/"; let site_name = &request .state() .storage - .get_setting("site_name", &(request.url().origin().ascii_serialization().clone() + "/")) + .get_setting("site_name", &owner) .await .unwrap_or_else(|_| "Kitty Box!".to_string()); + let feeds = request.state().storage.get_channels(&owner).await.unwrap_or_else(|_| Vec::default()); let mut res = next.run(request).await; let mut code: Option = None; if let Some(err) = res.downcast_error::() { @@ -406,6 +412,7 @@ where webmention: None, microsub: None, }, + feeds: feeds, content: ErrorPage { code }.to_string(), } .to_string(), diff --git a/src/frontend/templates/mod.rs b/src/frontend/templates/mod.rs index 290e215..a7c01e0 100644 --- a/src/frontend/templates/mod.rs +++ b/src/frontend/templates/mod.rs @@ -1,4 +1,5 @@ -use super::IndiewebEndpoints; +use crate::database::MicropubChannel; +use crate::frontend::IndiewebEndpoints; use ellipse::Ellipse; use http_types::StatusCode; use log::error; @@ -24,7 +25,7 @@ mod onboarding; pub use onboarding::OnboardingPage; markup::define! { - Template<'a>(title: &'a str, blog_name: &'a str, endpoints: IndiewebEndpoints, content: String) { + Template<'a>(title: &'a str, blog_name: &'a str, endpoints: IndiewebEndpoints, feeds: Vec, content: String) { @markup::doctype() html { head { @@ -48,6 +49,9 @@ markup::define! { ul { // TODO print a list of feeds and allow jumping to them li { a#homepage[href="/"] { @blog_name } } + @for feed in feeds.iter() { + li { a[href=&feed.uid] { @feed.name } } + } li.shiftright { a#login[href="/login"] { "Login" } } } } -- cgit 1.4.1