From ccee6b250011ce78bd7a2d58481968a888371d8f Mon Sep 17 00:00:00 2001 From: jutty Date: Sun, 11 Jan 2026 17:32:14 -0300 Subject: [PATCH] Prefer user-provided node summary if it exists --- src/syntax/serial.rs | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/syntax/serial.rs b/src/syntax/serial.rs index 0157333..4cf8e46 100644 --- a/src/syntax/serial.rs +++ b/src/syntax/serial.rs @@ -73,20 +73,31 @@ fn modulate_nodes(graph: &Graph) -> HashMap { node.title.clone() }; - let mut summary = if let Some(summary) = node.text.lines().next() { - if let Some(sentence) = node.text.split_once('.') { - format!("{}.", sentence.0) + // Populate empty summaries with the leading part of the node text + let summary = if node.summary.is_empty() { + let first_line = if let Some(first) = + node.text.lines().find(|s| !s.is_empty()) + { + String::from(first) } else { - String::from(summary) - } - } else { - node.text.clone() - }; + node.text.clone() + }; - if summary.len() > 300 { - summary.truncate(300); - summary.push('…'); - } + let mut candidate = + if let Some(dot_split) = first_line.split_once('.') { + format!("{}.", dot_split.0) + } else { + first_line + }; + + if candidate.len() > 300 { + candidate.truncate(300); + candidate.push('…'); + } + candidate + } else { + node.summary.clone() + }; let new_node = Node { id: key.clone(),