about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2022-04-15 07:44:11 +0300
committerVika <vika@fireburn.ru>2022-04-15 07:44:11 +0300
commit2b89b35c0da959295fe9c90f62b0f94c617b8e31 (patch)
treefe44257f29d2664e52d692c9717f86530823ade5
parent0d58e14876ed8e4b2b4fc10b3ef67cd703dee1a1 (diff)
frontend: Made endpoints optional in templates
Sometimes it's cumbersome to include them, and I plan to make them
embedded in the app anyway. This is my reminder to do it ASAP.
-rw-r--r--src/frontend/mod.rs6
-rw-r--r--src/frontend/templates/mod.rs33
2 files changed, 27 insertions, 12 deletions
diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs
index 1069b92..daeebd9 100644
--- a/src/frontend/mod.rs
+++ b/src/frontend/mod.rs
@@ -278,7 +278,7 @@ pub fn homepage<D: Storage>(db: D, endpoints: IndiewebEndpoints) -> impl Filter<
                     Box::new(warp::reply::html(Template {
                         title: &blog_name,
                         blog_name: &blog_name,
-                        endpoints,
+                        endpoints: Some(endpoints),
                         feeds,
                         user: None, // TODO
                         content: MainPage { feed: &feed, card: &card }.to_string()
@@ -303,7 +303,7 @@ pub fn onboarding<D: Storage, T: hyper::client::connect::Connect + Clone + Send
         .map(move || warp::reply::html(Template {
             title: "Kittybox - Onboarding",
             blog_name: "Kittybox",
-            endpoints: endpoints.clone(),
+            endpoints: Some(endpoints.clone()),
             feeds: vec![],
             user: None,
             content: OnboardingPage {}.to_string()
@@ -408,7 +408,7 @@ pub fn catchall<D: Storage>(db: D, endpoints: IndiewebEndpoints) -> impl Filter<
             warp::reply::with_status(warp::reply::html(Template {
                 title: &title,
                 blog_name: &blog_name,
-                endpoints,
+                endpoints: Some(endpoints),
                 feeds,
                 user: None, // TODO
                 content,
diff --git a/src/frontend/templates/mod.rs b/src/frontend/templates/mod.rs
index 364a716..1f7ac6a 100644
--- a/src/frontend/templates/mod.rs
+++ b/src/frontend/templates/mod.rs
@@ -25,7 +25,7 @@ mod onboarding;
 pub use onboarding::OnboardingPage;
 
 markup::define! {
-    Template<'a>(title: &'a str, blog_name: &'a str, endpoints: IndiewebEndpoints, feeds: Vec<MicropubChannel>, user: Option<String>, content: String) {
+    Template<'a>(title: &'a str, blog_name: &'a str, endpoints: Option<IndiewebEndpoints>, feeds: Vec<MicropubChannel>, user: Option<String>, content: String) {
         @markup::doctype()
         html {
             head {
@@ -35,13 +35,15 @@ markup::define! {
                 meta[name="viewport", content="initial-scale=1, width=device-width"];
                 // TODO: link rel= for common IndieWeb APIs: webmention, microsub
                 link[rel="micropub", href="/micropub"]; // Static, because it's built into the server itself
-                link[rel="authorization_endpoint", href=&endpoints.authorization_endpoint];
-                link[rel="token_endpoint", href=&endpoints.token_endpoint];
-                @if endpoints.webmention.is_some() {
-                    link[rel="webmention", href=&endpoints.webmention.as_ref()];
-                }
-                @if endpoints.microsub.is_some() {
-                    link[rel="microsub", href=&endpoints.microsub.as_ref()];
+                @if let Some(endpoints) = endpoints {
+                    link[rel="authorization_endpoint", href=&endpoints.authorization_endpoint];
+                    link[rel="token_endpoint", href=&endpoints.token_endpoint];
+                    @if let Some(webmention) = &endpoints.webmention {
+                        link[rel="webmention", href=&webmention];
+                    }
+                    @if let Some(microsub) = &endpoints.microsub {
+                        link[rel="microsub", href=&microsub];
+                    }
                 }
             }
             body {
@@ -443,8 +445,21 @@ markup::define! {
                     }
                     Some(msg) => {
                         p {
-                            "There was a following error in your request: " @msg
+                            "There was a following error in your request:"
                         }
+                        blockquote { pre { @msg } }
+                    }
+                }
+            }
+            StatusCode::INTERNAL_SERVER_ERROR => {
+                @match msg {
+                    None => {
+                        p { "It seems like you have found an error. Not to worry, it has already been logged." }
+                    }
+                    Some(msg) => {
+                        p { "The server encountered an error while processing your request:" }
+                        blockquote { @msg }
+                        p { "Don't worry, it has already been logged." }
                     }
                 }
             }