diff --git a/src/router.rs b/src/router.rs index c84ffa8..82f51c3 100644 --- a/src/router.rs +++ b/src/router.rs @@ -43,8 +43,7 @@ pub fn new(graph: &Graph) -> Router { } if graph.meta.config.tree { - router = router - .route("/tree", get(|| handlers::navigation::page("tree.html"))); + router = router.route("/tree", get(handlers::navigation::tree)); } if graph.meta.config.raw { diff --git a/src/router/handlers/error.rs b/src/router/handlers/error.rs index 26ee7d8..c4d8e84 100644 --- a/src/router/handlers/error.rs +++ b/src/router/handlers/error.rs @@ -24,9 +24,9 @@ pub(in crate::router::handlers) fn by_code( fn make_body(code: Option, message: Option<&str>) -> String { let mut context = tera::Context::default(); + let graph = Graph::load(); let out_code = code.unwrap_or(500); let out_message = &message.unwrap_or("Unknown error"); - let config = Graph::load().meta.config; context.insert( "title", @@ -35,9 +35,9 @@ fn make_body(code: Option, message: Option<&str>) -> String { .to_string(), ); + context.insert("graph", &graph); context.insert("message", out_message); context.insert("status_code", &out_code.to_string()); - context.insert("config", &config); handlers::template::render( "error.html", diff --git a/src/router/handlers/graph.rs b/src/router/handlers/graph.rs index f21a648..3a4a563 100644 --- a/src/router/handlers/graph.rs +++ b/src/router/handlers/graph.rs @@ -1,15 +1,12 @@ use axum::response::IntoResponse as _; use axum::{body::Body, extract::Path, http::Response, response::Redirect}; -use crate::graph::Edge; use crate::{graph::Graph, router::handlers, graph::Node}; pub async fn node(Path(id): Path) -> Response { let graph = Graph::load(); let result = graph.find_node(&id); let found = result.node.is_some(); - let nodes: Vec = graph.nodes.clone().into_values().collect(); - let not_found = result.node.is_none(); let node = result .node .unwrap_or(Node::new(Some(format!("Could not find node ID {id}.")))); @@ -27,24 +24,14 @@ pub async fn node(Path(id): Path) -> Response { } let mut context = tera::Context::default(); + context.insert("graph", &graph); context.insert("node", &node); - context.insert("nodes", &nodes); - context.insert( - "connections", - &node - .connections - .clone() - .unwrap_or_default() - .values() - .collect::>(), - ); context.insert("incoming", &graph.incoming.get(&id)); - context.insert("config", &graph.meta.config); handlers::template::by_filename( "node.html", &context, - if not_found { 404 } else { 500 }, + if found { 500 } else { 404 }, Some( format!( "Failed to generate page for node {} (ID {}).\n\ @@ -53,7 +40,7 @@ pub async fn node(Path(id): Path) -> Response { ) .to_owned(), ), - not_found, + !found, ) } diff --git a/src/router/handlers/navigation.rs b/src/router/handlers/navigation.rs index 924ec0b..795c29a 100644 --- a/src/router/handlers/navigation.rs +++ b/src/router/handlers/navigation.rs @@ -20,6 +20,28 @@ pub async fn page(template: &str) -> Response { handlers::template::by_filename(template, &context, 500, None, false) } +pub async fn tree() -> Response { + let mut context = tera::Context::default(); + let mut graph = Graph::load(); + + context.insert("graph", &graph); + if let Some(root_node) = graph.get_root() { + graph.nodes.remove(&root_node.id); + context.insert("root_node", &root_node); + context.insert( + "nodes", + &graph.nodes.values().cloned().collect::>(), + ); + } else { + context.insert( + "nodes", + &graph.nodes.values().cloned().collect::>(), + ); + } + + handlers::template::by_filename("tree.html", &context, 500, None, false) +} + pub async fn data() -> Response { let mut context = tera::Context::default(); let graph = Graph::load(); diff --git a/src/router/handlers/template.rs b/src/router/handlers/template.rs index 78dd2a3..323f6fe 100644 --- a/src/router/handlers/template.rs +++ b/src/router/handlers/template.rs @@ -157,10 +157,8 @@ mod tests { let node = crate::graph::Node::new(Some(payload.to_string())); let graph = Graph::load(); context.insert("node", &node); - context - .insert("text", &crate::syntax::content::parse(&node.text, &graph)); + context.insert("graph", &graph); context.insert("incoming", &graph.incoming.get(&node.id)); - context.insert("config", &graph.meta.config); let (body, status) = render("node.html", &context, None); assert_eq!(status, 200); assert!(body.matches(payload).count() == 1); diff --git a/static/style.css b/static/style.css index aed772c..a307adf 100644 --- a/static/style.css +++ b/static/style.css @@ -10,12 +10,17 @@ body { grid-template-rows: auto 1fr auto; } +main { + width: 90vw; + margin: 0 2.5vw; +} + pre { - max-width: 96vw; + max-width: 95%; overflow: auto; box-sizing: border-box; padding: 10px; - margin: 20px 2vw; + margin: 20px 2.5%; } @@ -39,7 +44,7 @@ a { a.detached { color: #595959; - text-decoration-color: none; + text-decoration-color: #444444; } a.external { @@ -75,6 +80,15 @@ span.label { font-size: 0.7em; } +span.root-label { + color: #fff; + font-weight: bolder; + background-color: #106363; + border: outset 1px #ffffff; + box-shadow: 2px 2px #00ffff; +} + + span.id-label { background-color: #e0e0e0; border: solid 1px #d0d0d0; @@ -86,10 +100,18 @@ span.hidden-label { border: solid 1px #d0d0d0; } + +h1, h2, h3 { + font-weight: lighter; + margin: 20px 0 12px; +} + h1.node-title { display: inline; - margin: 10px 0; - font-weight: 300; +} + +h3 { + font-size: 20px; } footer div { @@ -106,8 +128,17 @@ span.detached-connection { filter: opacity(60%); } +div.connections-container { + margin-bottom: 20px; +} + +hr.connections { + margin-top: 60px; +} + nav#nav-main { text-align: center; + margin-bottom: 20px; } #nav-main-spread { @@ -174,6 +205,14 @@ td, th { border: 0.5px dotted #666; } +summary { + margin-bottom: 15px; +} + +hr { + border: 1px dashed #555; +} + @media (prefers-color-scheme: dark) { * { background-color: #222222; @@ -226,3 +265,12 @@ td, th { margin: 0; } } + +@media (min-width: 601px) { + + div.connections-container { + width: 100%; + display: grid; + grid-template-columns: 1fr 1fr; + } +} diff --git a/templates/about.html b/templates/about.html index 25a1397..2746039 100644 --- a/templates/about.html +++ b/templates/about.html @@ -5,8 +5,8 @@ {%- block body %}

About

-{% if config.about_text %} -{{ config.about_text | safe }} +{% if graph.meta.config.about_text %} +{{ graph.meta.config.about_text | safe }} {% else %}

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

diff --git a/templates/base.html b/templates/base.html index d0b39ed..e04d34f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,12 +1,12 @@ -{% if config.content_language %} - +{% if graph.meta.config.content_language %} + {% else %} {% endif %} - {% if config.site_title %} - {% block title %}{% endblock title %} • {{config.site_title}} + {% if graph.meta.config.site_title %} + {% block title %}{% endblock title %} • {{graph.meta.config.site_title}} {% else %} {% block title %}{% endblock title %} • en {% endif %} @@ -19,33 +19,36 @@