Add missing static routes for favicon, about and acknowledgments

This commit is contained in:
Juno Takano 2025-12-11 02:15:14 -03:00
commit 2b1683700f
5 changed files with 147 additions and 2 deletions

View file

@ -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<String> {
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(

89
static/favicon.svg Normal file
View file

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
version="1.1"
id="svg1"
width="81.269844"
height="81.269844"
viewBox="0 0 81.269844 81.269844"
sodipodi:docname="favicon.svg"
inkscape:export-filename="favicon.png"
inkscape:export-xdpi="37.799999"
inkscape:export-ydpi="37.799999"
inkscape:version="1.4.2 (ebf0e940d0, 2025-05-08)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs1">
<marker
markerWidth="0.52499998"
markerHeight="0.99999994"
refX="0"
refY="0"
orient="auto-start-reverse"
id="CapTriangle-7"
viewBox="0 0 0.525 1"
inkscape:stockid="Triangle cap"
style="overflow:visible"
preserveAspectRatio="xMidYMid"
inkscape:isstock="true"
inkscape:collect="always">
<path
style="fill:context-stroke;stroke-linecap:butt"
d="M 0,-1 1,0 0,1 -0.05,0 Z"
sodipodi:nodetypes="sssssscsss"
transform="scale(0.5)"
id="path61-5" />
</marker>
<marker
markerWidth="1.05"
markerHeight="0.99999994"
refX="0"
refY="0"
orient="auto-start-reverse"
id="marker9-3"
viewBox="0 0 1.05 1"
inkscape:stockid="Ribbon cap"
style="overflow:visible"
preserveAspectRatio="xMidYMid"
inkscape:isstock="true"
inkscape:collect="always">
<path
style="fill:context-stroke;stroke-linecap:butt"
d="M 0,-1 H 2 L 1,0 2,1 H 0 L -0.1,0 Z"
sodipodi:nodetypes="sssssscsss"
transform="scale(0.5)"
id="path9-5" />
</marker>
</defs>
<sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:zoom="4"
inkscape:cx="40.375"
inkscape:cy="54.125"
inkscape:window-width="1600"
inkscape:window-height="967"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="g1" />
<g
inkscape:groupmode="layer"
inkscape:label="Image"
id="g1">
<path
id="path1-9"
style="fill:none;stroke:#00a1a1;stroke-width:12.8582;stroke-linejoin:bevel;marker-start:url(#CapTriangle-7);marker-end:url(#marker9-3)"
d="M 37.70862,74.079434 A 33.497973,33.497973 0 0 1 7.3082947,44.02826 33.497973,33.497973 0 0 1 31.187861,8.5737925 33.497973,33.497973 0 0 1 70.461787,25.450155 33.497973,33.497973 0 0 1 61.176338,67.175846" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

20
templates/about.html Normal file
View file

@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block title %}About{% endblock title %}
{%- block body %}
<h1>About</h1>
<p>en is a program to create a connected collection of texts.</p>
<p>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.</p>
<p>If you'd like to learn more:</p>
<ul>
<li><a href="https://en.jutty.dev">Website</a></li>
<li><a href="https://en.jutty.dev/docs">Documentation</a></li>
<li><a href="https://codeberg.org/jutty/en">Source code repository</a></li>
</ul>
{%- endblock body %}

View file

@ -0,0 +1,19 @@
{% extends "base.html" %}
{% block title %}Acknowledgments{% endblock title %}
{%- block body %}
<h1>Acknowledgments</h1>
<p>en is only possible thanks to a number of projects and people:</p>
<ul>
<li><a href="https://rust-lang.org/">The Rust Programing Language</a></li>
<li><a href="https://tokio.rs/">Tokio</a> and
<a href="https://github.com/tokio-rs/axum">Axum</a></li>
<li><a href="https://keats.github.io/tera/">Tera</a></li>
<li><a href="https://serde.rs/">Serde</a> and the
<a href="https://github.com/toml-rs/toml">toml crate</a></li>
</ul>
{%- endblock body %}

View file

@ -5,6 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/style.css" rel="stylesheet">
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
{% block head %}
{% endblock head %}
</head>