From 99b9feeb95c03e57b70e607a82c3ca86c44c7171 Mon Sep 17 00:00:00 2001 From: jutty Date: Wed, 17 Dec 2025 10:15:21 -0300 Subject: [PATCH] Extract config text parsing into the type --- src/handlers/graph.rs | 4 ++-- src/handlers/navigation.rs | 15 ++------------- src/types.rs | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/handlers/graph.rs b/src/handlers/graph.rs index 34013da..c954a4c 100644 --- a/src/handlers/graph.rs +++ b/src/handlers/graph.rs @@ -2,7 +2,7 @@ use axum::{body::Body, extract::Path, http::Response}; use crate::syntax::content::parsers::line::elements::paragraph::Paragraph; use crate::syntax::content; -use crate::syntax::content::parsers::word::elements::literal::Literal; +use crate::syntax::content::parsers::compound::elements::literal::Literal; use crate::{formats::populate_graph, handlers, types::Node}; pub async fn node(Path(id): Path) -> Response { @@ -15,7 +15,7 @@ pub async fn node(Path(id): Path) -> Response { context.insert("title", &node.title); context.insert("connections", &node.connections.clone()); context.insert("incoming", &graph.incoming.get(&id)); - context.insert("config", &graph.meta.config); + context.insert("config", &graph.meta.config.parse_text()); let out_text = content::parse::(&node.text); context.insert("text", &out_text); diff --git a/src/handlers/navigation.rs b/src/handlers/navigation.rs index a9e0751..548bed3 100644 --- a/src/handlers/navigation.rs +++ b/src/handlers/navigation.rs @@ -12,7 +12,7 @@ use crate::{ self, parsers::{ line::elements::{paragraph::Paragraph, span::Span}, - word::elements::literal::Literal, + compound::elements::literal::Literal, }, }, types::{Config, Node}, @@ -27,18 +27,7 @@ pub async fn page(template: &str) -> Response { context.insert("nodes", &nodes); context.insert("root_node", &root_node); - - let text_parsed_config = Config { - footer_text: content::parse::( - &graph.meta.config.footer_text, - ), - about_text: content::parse::( - &graph.meta.config.about_text, - ), - ..graph.meta.config - }; - - context.insert("config", &text_parsed_config); + context.insert("config", &graph.meta.config.parse_text()); handlers::template::by_filename(template, &context, 500, None, false) } diff --git a/src/types.rs b/src/types.rs index f8d2a55..5c8ea95 100644 --- a/src/types.rs +++ b/src/types.rs @@ -2,6 +2,8 @@ use std::collections::HashMap; use serde::{Serialize, Deserialize}; +use crate::syntax::content::parsers::{compound::elements::literal::Literal, line::elements::{paragraph::Paragraph, span::Span}}; + #[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, Debug)] pub struct Graph { pub nodes: HashMap, @@ -149,3 +151,19 @@ impl Node { } } } + +impl Config { + #[must_use] + pub fn parse_text(self) -> Config { + + Config { + footer_text: crate::syntax::content::parse::( + &self.footer_text, + ), + about_text: crate::syntax::content::parse::( + &self.about_text, + ), + ..self + } + } +}