From 0a85a819503cc4e937eb5c68cdd3fb73d8f30e8e Mon Sep 17 00:00:00 2001 From: mtrx Date: Sat, 10 Aug 2024 21:30:51 +0200 Subject: [PATCH] template error logging, css, better rendering --- site/content/static/css/blog.css | 11 ++++++++- site/content/templates/about.html | 2 +- site/content/templates/article.html.macro | 2 +- site/content/templates/base.html | 5 +++- site/content/templates/blog-all-posts.html | 2 +- site/content/templates/blog-by-id.html | 23 +++++++----------- site/content/templates/blog.html | 2 +- site/content/templates/edit-form.html | 15 ++++++------ site/src/routes.rs | 28 +++++++++++++--------- 9 files changed, 51 insertions(+), 39 deletions(-) diff --git a/site/content/static/css/blog.css b/site/content/static/css/blog.css index eb57754..a32a425 100644 --- a/site/content/static/css/blog.css +++ b/site/content/static/css/blog.css @@ -10,6 +10,10 @@ html { padding-left: 20%; } +.side-nav { + text-align: right; +} + .social-icon { height: 1rem; width: 1rem; @@ -20,11 +24,16 @@ html { padding: 20px 0px 20px 0px; } -article { +.blog-article { padding-top: 2rem; display: flex; } +.hidden-link { + text-decoration: none; + color: black; +} + .post-link { text-decoration: none; color: black; diff --git a/site/content/templates/about.html b/site/content/templates/about.html index f647ce1..6e6ec58 100644 --- a/site/content/templates/about.html +++ b/site/content/templates/about.html @@ -7,7 +7,7 @@ {% endblock head %} {% block content %} -

Hi, I'm {{ username }}

+

Hi, I'm {{ username }}

Back to the blog

diff --git a/site/content/templates/article.html.macro b/site/content/templates/article.html.macro index f250781..bd24fe7 100644 --- a/site/content/templates/article.html.macro +++ b/site/content/templates/article.html.macro @@ -1,5 +1,5 @@ {% macro article(id, title, body, publish_date) %} -
+

{{ title }}

diff --git a/site/content/templates/base.html b/site/content/templates/base.html index 3a994db..8217b2e 100644 --- a/site/content/templates/base.html +++ b/site/content/templates/base.html @@ -12,7 +12,10 @@ -
{% block content %}{% endblock content %}
+
+ {% block content %} + {% endblock content %} +
\ No newline at end of file diff --git a/site/content/templates/blog-all-posts.html b/site/content/templates/blog-all-posts.html index 4f3c563..b40a86a 100644 --- a/site/content/templates/blog-all-posts.html +++ b/site/content/templates/blog-all-posts.html @@ -11,7 +11,7 @@ {% block content %} -

{{ username }} blog

+

{{ username }} blog

About Last 5 posts diff --git a/site/content/templates/blog-by-id.html b/site/content/templates/blog-by-id.html index d755cc7..d4bcd8a 100644 --- a/site/content/templates/blog-by-id.html +++ b/site/content/templates/blog-by-id.html @@ -1,28 +1,21 @@ {% extends "base.html" %} +{% import "article.html.macro" as article_macro %} {% block head %} {{ super() }} - + {{ post.title }} | {{ username }}' blog {% endblock head %} {% block content %} -

{{ username }} blog

-

+

{{ username }} blog

+ + +{{ article_macro::article(id=post.id,title=post.title,body=post.body,publish_date=post.publish_date) }} + {% endblock content %} \ No newline at end of file diff --git a/site/content/templates/blog.html b/site/content/templates/blog.html index 751b75a..3153265 100644 --- a/site/content/templates/blog.html +++ b/site/content/templates/blog.html @@ -9,7 +9,7 @@ {% endblock head %} {% block content %} -

{{ username }} blog

+

{{ username }} blog

About All Posts diff --git a/site/content/templates/edit-form.html b/site/content/templates/edit-form.html index a8160a3..5952609 100644 --- a/site/content/templates/edit-form.html +++ b/site/content/templates/edit-form.html @@ -2,30 +2,31 @@ {% block head %} {{ super() }} -Edit '{{ title }}' - +Edit '{{ post.title }}' + {% endblock head %} {% block content %} -

+

{{ username }} blog

+

- +
- +
-
+
-
+
diff --git a/site/src/routes.rs b/site/src/routes.rs index 8d116fc..15c0071 100644 --- a/site/src/routes.rs +++ b/site/src/routes.rs @@ -64,7 +64,8 @@ async fn about(tmpl: web::Data) -> Result { let result = tmpl .render("about.html", &context) - .map_err(|e| error::ErrorInternalServerError(format!("Template error\n{}", e)))?; + .map_err(|err| error::ErrorInternalServerError(err)) + .unwrap(); Ok(HttpResponse::Ok().content_type("text/html").body(result)) } @@ -79,7 +80,8 @@ async fn blog(tmpl: web::Data) -> Result { let result = tmpl .render("blog.html", &context) - .map_err(|_| error::ErrorInternalServerError("Template error"))?; + .map_err(|err| error::ErrorInternalServerError(err)) + .unwrap(); Ok(HttpResponse::Ok().content_type("text/html").body(result)) } @@ -94,7 +96,8 @@ async fn blog_all(tmpl: web::Data) -> Result { let result = tmpl .render("blog-all-posts.html", &context) - .map_err(|_| error::ErrorInternalServerError("Template error"))?; + .map_err(|err| error::ErrorInternalServerError(err)) + .unwrap(); Ok(HttpResponse::Ok().content_type("text/html").body(result)) } @@ -113,12 +116,13 @@ async fn blog_by_id( } let mut context = Context::new(); - context.insert("post", &post); context.insert("username", &CONFIG.username); + context.insert("post", &post); let result = tmpl .render("blog-by-id.html", &context) - .map_err(|_| error::ErrorInternalServerError("Template error"))?; + .map_err(|err| error::ErrorInternalServerError(err)) + .unwrap(); return Ok(HttpResponse::Ok().content_type("text/html").body(result)); } else { @@ -134,7 +138,8 @@ async fn blog_submit(tmpl: web::Data) -> Result let result = tmpl .render("submit.html", &context) - .map_err(|_| error::ErrorInternalServerError("Template error"))?; + .map_err(|err| error::ErrorInternalServerError(err)) + .unwrap(); return Ok(HttpResponse::Ok().content_type("text/html").body(result)); } @@ -147,7 +152,8 @@ async fn blog_edit(tmpl: web::Data) -> Result { let result = tmpl .render("edit.html", &context) - .map_err(|_| error::ErrorInternalServerError("Template error"))?; + .map_err(|err| error::ErrorInternalServerError(err)) + .unwrap(); Ok(HttpResponse::Ok().content_type("text/html").body(result)) } @@ -165,13 +171,13 @@ async fn blog_edit_by_id( post.body = replace_br_tags(&post.body); let mut context = Context::new(); - context.insert("title", &post.title); - context.insert("body", &post.body); - context.insert("id", &id); + context.insert("username", &CONFIG.username); + context.insert("post", &post); let result = tmpl .render("edit-form.html", &context) - .map_err(|_| error::ErrorInternalServerError("Template error"))?; + .map_err(|err| error::ErrorInternalServerError(err)) + .unwrap(); Ok(HttpResponse::Ok().content_type("text/html").body(result)) } else {