Implement automatic IDs

This commit is contained in:
Juno Takano 2025-12-10 09:58:44 -03:00
commit 400eb02efc
5 changed files with 26 additions and 32 deletions

View file

@ -7,8 +7,9 @@ It works by ingesting a TOML file containing your node specification and serving
## Roadmap
- [x] Array syntax for lightweight connections
- [x] Automatic IDs
- [ ] Automatic titles
- [ ] Automatic anchors
- [ ] Automatic IDs
- [ ] Mismatch between TOML ID and provided ID
## Motivation

View file

@ -55,6 +55,7 @@ fn modulate_nodes(old_nodes: HashMap<String, Node>) -> HashMap<String, Node> {
}
let new_node = Node {
id: key.clone(),
connections: Some(new_edges),
..node.clone()
};

View file

@ -95,11 +95,11 @@ async fn node_view(Path(id): Path<String>) -> impl IntoResponse {
let node: &Node = nodes.get(&id).unwrap_or(&empty_node);
context.insert("id", &node.id);
context.insert("id", &id);
context.insert("title", &node.title);
context.insert("body", &node.body);
context.insert("connections", &node.connections.clone());
context.insert("incoming", &graph.incoming.get(&node.id));
context.insert("incoming", &graph.incoming.get(&id));
template_handler(
"node.html",
@ -109,9 +109,9 @@ async fn node_view(Path(id): Path<String>) -> impl IntoResponse {
r#"Failed to generate page for node {} (ID {}) with {} outgoing,
{} incoming connections and body "{}""#,
node.title,
node.id,
id,
node.connections.iter().len(),
graph.incoming.get(&node.id).iter().len(),
graph.incoming.get(&id).iter().len(),
node.body,
),
)
@ -121,7 +121,7 @@ async fn index() -> Html<String> {
let mut context = tera::Context::new();
let graph = populate_graph();
let root_node = graph.get_root();
let root_node = graph.get_root().unwrap_or_default();
let nodes: Vec<Node> = graph.nodes.into_values().collect();
context.insert("nodes", &nodes);
@ -134,7 +134,7 @@ async fn tree() -> Html<String> {
let mut context = tera::Context::new();
let graph = populate_graph();
let root_node = graph.get_root();
let root_node = graph.get_root().unwrap_or_default();
let nodes: Vec<Node> = graph.nodes.into_values().collect();
context.insert("nodes", &nodes);

View file

@ -1,7 +1,7 @@
use serde::{Serialize, Deserialize};
use std::collections::HashMap;
#[derive(Serialize, Deserialize, Clone, Default)]
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
pub struct Graph {
pub messages: Vec<String>,
pub root_node: String,
@ -10,7 +10,19 @@ pub struct Graph {
pub incoming: HashMap<String, Vec<Edge>>,
}
#[derive(Serialize, Clone, Default, PartialEq, Deserialize)]
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
pub struct Node {
pub title: String,
pub body: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub connections: Option<Vec<Edge>>,
#[serde(default)]
pub links: Vec<String>,
#[serde(default)]
pub id: String,
}
#[derive(Serialize, Clone, Default, PartialEq, Deserialize, Debug)]
pub struct Edge {
pub to: String,
#[serde(default)]
@ -21,22 +33,11 @@ pub struct Edge {
pub detached: bool,
}
#[derive(Serialize, Deserialize, Clone, Default)]
pub struct Node {
pub title: String,
pub id: String,
pub body: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub connections: Option<Vec<Edge>>,
#[serde(default)]
pub links: Vec<String>,
}
impl Graph {
pub fn new(message: Option<String>) -> Graph {
Self {
nodes: HashMap::new(),
root_node: "".to_string(),
root_node: "VoidNode".to_string(),
incoming: HashMap::new(),
messages: vec![message
.unwrap_or("This graph is empty or in error".to_string())],
@ -54,8 +55,8 @@ impl Graph {
impl Node {
pub fn new(message: Option<String>) -> Node {
Self {
title: "Empty Node".to_string(),
id: "EmptyNode".to_string(),
id: "VoidNode".to_string(),
title: "Pure Void".to_string(),
body: match message {
Some(s) => s,
None => "Node is empty, missing or wasn't found.".to_string()

View file

@ -3,7 +3,6 @@ root_node = "Interface"
[nodes.Interface]
title = "Interface"
id = "Interface"
body = """
An interface is a point of contact between the inside and the outside of something. Contrast with intraface.
"""
@ -12,7 +11,6 @@ links = ["Intraface"]
[nodes.Intraface]
title = "Intraface"
id = "Intraface"
body = """
The intraface is the reflexive process of communicating, creating, thinking, that does not or cannot get shared with others. Contrast with interface.
"""
@ -21,14 +19,12 @@ links = ["Thinking", "Interface"]
[nodes.Thinking]
title = "Thinking"
id = "Thinking"
body = """
Thinking is a process by which some beings create and manipulate mental constructs.
"""
[nodes.Paradigm]
title = "Paradigm"
id = "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.
"""
@ -37,7 +33,6 @@ links = [ "Principle", "Belief", "Method", "Position", "Praxis" ]
[nodes.Principle]
title = "Principle"
id = "Principle"
body = """
A principle is a belief that implies commitment and necessity.
@ -56,7 +51,6 @@ to = "Identity"
[nodes.Religion]
title = "Religion"
id = "Religion"
body = """
A religion is a paradigm that involves unfalsifiable beliefs, particularly those in the domain of morality.
@ -86,7 +80,6 @@ links = [
[nodes.Identity]
title = "Identity"
id = "Identity"
body = """
Identity is how individuals construe their sameness and otherness from each other and from nothingness.
"""
@ -99,7 +92,6 @@ to = "Emptiness"
[nodes.Emptiness]
title = "Emptiness"
id = "Emptiness"
body = """
Emptiness is the vacuous base in which entities exist.
"""
@ -108,7 +100,6 @@ links = [ "Entity" ]
[nodes.Entity]
title = "Entity"
id = "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.
"""