From c6fccd2d7b30eea7b5ee38fd7ddfab27af7aa448 Mon Sep 17 00:00:00 2001 From: jutty Date: Wed, 10 Dec 2025 10:19:51 -0300 Subject: [PATCH] Implement automatic titles --- README.md | 6 +++--- src/formats.rs | 27 ++++++++++++++++++--------- src/types.rs | 25 ++++++++++--------------- static/graph.toml | 10 ---------- 4 files changed, 31 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index c707a6d..020b146 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ It works by ingesting a TOML file containing your node specification and serving ## Roadmap +- [ ] Automatic anchors - [x] Array syntax for lightweight connections - [x] Automatic IDs -- [ ] Automatic titles -- [ ] Automatic anchors -- [ ] Mismatch between TOML ID and provided ID +- [x] Automatic titles +- [x] Mismatch between TOML ID and provided ID ## Motivation diff --git a/src/formats.rs b/src/formats.rs index 19b1132..7a288d4 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -28,15 +28,6 @@ fn modulate_nodes(old_nodes: HashMap) -> HashMap { let connections = node.connections.clone().unwrap_or_default(); let mut new_edges = connections.clone(); - for link in node.links.iter() { - new_edges.push(Edge { - from: key.to_string(), - to: link.to_string(), - anchor: String::new(), - detached: !old_nodes.contains_key(link), - }) - } - for (i, edge) in connections.iter().enumerate() { let mut new_edge = edge.clone(); @@ -54,8 +45,26 @@ fn modulate_nodes(old_nodes: HashMap) -> HashMap { new_edges[i] = new_edge; } + // Create connections for each link + for link in node.links.iter() { + new_edges.push(Edge { + from: key.to_string(), + to: link.to_string(), + anchor: String::new(), + detached: !old_nodes.contains_key(link), + }) + } + + // Populate empty titles with IDs + let new_title = if node.title.is_empty() { + key.clone() + } else { + node.title.clone() + }; + let new_node = Node { id: key.clone(), + title: new_title, connections: Some(new_edges), ..node.clone() }; diff --git a/src/types.rs b/src/types.rs index 1f3916e..0ce9a45 100644 --- a/src/types.rs +++ b/src/types.rs @@ -3,34 +3,29 @@ use std::collections::HashMap; #[derive(Serialize, Deserialize, Clone, Default, Debug)] pub struct Graph { - pub messages: Vec, - pub root_node: String, pub nodes: HashMap, - #[serde(skip)] - pub incoming: HashMap>, + pub root_node: String, + #[serde(default)] pub messages: Vec, + #[serde(skip)] pub incoming: HashMap>, } #[derive(Serialize, Deserialize, Clone, Default, Debug)] pub struct Node { - pub title: String, pub body: String, + #[serde(default)] pub title: String, + #[serde(default)] pub links: Vec, + #[serde(default)] pub id: String, + #[serde(skip_serializing_if = "Option::is_none")] pub connections: Option>, - #[serde(default)] - pub links: Vec, - #[serde(default)] - pub id: String, } #[derive(Serialize, Clone, Default, PartialEq, Deserialize, Debug)] pub struct Edge { pub to: String, - #[serde(default)] - pub anchor: String, - #[serde(default)] - pub from: String, - #[serde(default)] - pub detached: bool, + #[serde(default)] pub anchor: String, + #[serde(default)] pub from: String, + #[serde(default)] pub detached: bool, } impl Graph { diff --git a/static/graph.toml b/static/graph.toml index 262fdd8..7d99a7c 100644 --- a/static/graph.toml +++ b/static/graph.toml @@ -1,8 +1,6 @@ -messages = [] root_node = "Interface" [nodes.Interface] -title = "Interface" body = """ An interface is a point of contact between the inside and the outside of something. Contrast with intraface. """ @@ -10,7 +8,6 @@ An interface is a point of contact between the inside and the outside of somethi links = ["Intraface"] [nodes.Intraface] -title = "Intraface" body = """ The intraface is the reflexive process of communicating, creating, thinking, that does not or cannot get shared with others. Contrast with interface. """ @@ -18,13 +15,11 @@ The intraface is the reflexive process of communicating, creating, thinking, tha links = ["Thinking", "Interface"] [nodes.Thinking] -title = "Thinking" body = """ Thinking is a process by which some beings create and manipulate mental constructs. """ [nodes.Paradigm] -title = "Paradigm" body = """ A paradigm is a cohesive set of beliefs, methods and principles that serve both as justification for a given position and as guidance for how to pursue its praxis. """ @@ -32,7 +27,6 @@ A paradigm is a cohesive set of beliefs, methods and principles that serve both links = [ "Principle", "Belief", "Method", "Position", "Praxis" ] [nodes.Principle] -title = "Principle" body = """ A principle is a belief that implies commitment and necessity. @@ -50,7 +44,6 @@ anchor = "identifying" to = "Identity" [nodes.Religion] -title = "Religion" body = """ A religion is a paradigm that involves unfalsifiable beliefs, particularly those in the domain of morality. @@ -79,7 +72,6 @@ links = [ ] [nodes.Identity] -title = "Identity" body = """ Identity is how individuals construe their sameness and otherness from each other and from nothingness. """ @@ -91,7 +83,6 @@ anchor = "nothingness" to = "Emptiness" [nodes.Emptiness] -title = "Emptiness" body = """ Emptiness is the vacuous base in which entities exist. """ @@ -99,7 +90,6 @@ Emptiness is the vacuous base in which entities exist. links = [ "Entity" ] [nodes.Entity] -title = "Entity" body = """ An entity is anything except for actual emptiness. It does not have to be sentient, or physical. It can be an idea, a concept, a memory. The concept of emptiness is an entity, but emptiness itself is not. """