Implement automatic titles
This commit is contained in:
parent
400eb02efc
commit
c6fccd2d7b
4 changed files with 31 additions and 37 deletions
|
|
@ -28,15 +28,6 @@ fn modulate_nodes(old_nodes: HashMap<String, Node>) -> HashMap<String, Node> {
|
|||
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<String, Node>) -> HashMap<String, Node> {
|
|||
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()
|
||||
};
|
||||
|
|
|
|||
25
src/types.rs
25
src/types.rs
|
|
@ -3,34 +3,29 @@ use std::collections::HashMap;
|
|||
|
||||
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
|
||||
pub struct Graph {
|
||||
pub messages: Vec<String>,
|
||||
pub root_node: String,
|
||||
pub nodes: HashMap<String, Node>,
|
||||
#[serde(skip)]
|
||||
pub incoming: HashMap<String, Vec<Edge>>,
|
||||
pub root_node: String,
|
||||
#[serde(default)] pub messages: Vec<String>,
|
||||
#[serde(skip)] pub incoming: HashMap<String, Vec<Edge>>,
|
||||
}
|
||||
|
||||
#[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<String>,
|
||||
#[serde(default)] pub id: 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)]
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue