From 2b1683700fb5295c1e7f191ae32ca40e5acc7bb8 Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 11 Dec 2025 02:15:14 -0300 Subject: [PATCH] Add missing static routes for favicon, about and acknowledgments --- src/main.rs | 20 +++++++- static/favicon.svg | 89 ++++++++++++++++++++++++++++++++++ templates/about.html | 20 ++++++++ templates/acknowledgments.html | 19 ++++++++ templates/base.html | 1 + 5 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 static/favicon.svg create mode 100644 templates/about.html create mode 100644 templates/acknowledgments.html diff --git a/src/main.rs b/src/main.rs index 63293d6..ce07ec5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,8 +36,11 @@ async fn main() { .route("/graph/toml", get(toml_graph)) .route("/graph/json", get(json_graph)) .route("/static/style.css", get(stylesheet)) + .route("/static/favicon.svg", get(favicon)) .route("/node/{node_id}", get(node_view).post(node_view)) .route("/tree", get(tree)) + .route("/about", get(|| static_template_handler("about.html"))) + .route("/acknowledgments", get(|| static_template_handler("acknowledgments.html"))) .fallback(not_found) ; @@ -165,6 +168,10 @@ async fn tree() -> Html { context.insert("root_node", &root_node); template_handler("tree.html", context, 500, "Failed to render template") + +#[expect(clippy::unused_async)] +async fn static_template_handler(name: &str) -> impl IntoResponse { + template_handler(name, tera::Context::new(), 500, None, false) } #[derive(serde::Deserialize)] @@ -189,12 +196,21 @@ async fn toml_graph() -> impl IntoResponse { } async fn stylesheet() -> impl IntoResponse { - let body = match std::fs::read_to_string("./static/style.css") { + let content = match std::fs::read_to_string("./static/style.css") { Ok(s) => s, Err(e) => format!("Error: {e}"), }; - ([(header::CONTENT_TYPE, "text/css")], body) + ([(header::CONTENT_TYPE, "text/css")], content) +} + +async fn favicon() -> impl IntoResponse { + let content = match std::fs::read("./static/favicon.svg") { + Ok(b) => b, + Err(e) => { eprintln!("Error: {e}"); vec![] } + }; + + ([(header::CONTENT_TYPE, "image/svg+xml")], content) } fn make_error_body( diff --git a/static/favicon.svg b/static/favicon.svg new file mode 100644 index 0000000..111612f --- /dev/null +++ b/static/favicon.svg @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + diff --git a/templates/about.html b/templates/about.html new file mode 100644 index 0000000..9c7d15a --- /dev/null +++ b/templates/about.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} + +{% block title %}About{% endblock title %} + +{%- block body %} +

About

+ +

en is a program to create a connected collection of texts.

+ +

You define your graph using a plain-text configuration file and then en reads this file and generates a webpage like the one you are seeing right now.

+ +

If you'd like to learn more:

+ + + +{%- endblock body %} diff --git a/templates/acknowledgments.html b/templates/acknowledgments.html new file mode 100644 index 0000000..098e895 --- /dev/null +++ b/templates/acknowledgments.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block title %}Acknowledgments{% endblock title %} + +{%- block body %} +

Acknowledgments

+ +

en is only possible thanks to a number of projects and people:

+ + + +{%- endblock body %} diff --git a/templates/base.html b/templates/base.html index 51f0685..b7b42d8 100644 --- a/templates/base.html +++ b/templates/base.html @@ -5,6 +5,7 @@ + {% block head %} {% endblock head %}