generate document title based on first line

This commit is contained in:
yggverse 2025-06-28 09:58:04 +03:00
parent 5c3f41c054
commit 1fa8f3f29d
2 changed files with 18 additions and 4 deletions

View File

@ -61,11 +61,12 @@ impl Text {
} }
pub fn nex(actions: (&Rc<WindowAction>, &Rc<ItemAction>), base: &Uri, data: &str) -> Self { pub fn nex(actions: (&Rc<WindowAction>, &Rc<ItemAction>), base: &Uri, data: &str) -> Self {
let text_view = TextView::nex(actions, base, data); let mut title = None;
let text_view = TextView::nex(actions, base, data, &mut title);
Self { Self {
scrolled_window: reader(&text_view), scrolled_window: reader(&text_view),
text_view, text_view,
meta: Meta { title: None }, meta: Meta { title },
} }
} }

View File

@ -14,7 +14,12 @@ use gutter::Gutter;
use std::{cell::Cell, collections::HashMap, rc::Rc}; use std::{cell::Cell, collections::HashMap, rc::Rc};
pub trait Nex { pub trait Nex {
fn nex(actions: (&Rc<WindowAction>, &Rc<ItemAction>), base: &Uri, data: &str) -> Self; fn nex(
actions: (&Rc<WindowAction>, &Rc<ItemAction>),
base: &Uri,
data: &str,
title: &mut Option<String>,
) -> Self;
} }
impl Nex for TextView { impl Nex for TextView {
@ -22,6 +27,7 @@ impl Nex for TextView {
(window_action, item_action): (&Rc<WindowAction>, &Rc<ItemAction>), (window_action, item_action): (&Rc<WindowAction>, &Rc<ItemAction>),
base: &Uri, base: &Uri,
data: &str, data: &str,
title: &mut Option<String>,
) -> Self { ) -> Self {
pub const NEW_LINE: &str = "\n"; pub const NEW_LINE: &str = "\n";
@ -50,7 +56,14 @@ impl Nex for TextView {
let buffer = TextBuffer::new(Some(&tags)); let buffer = TextBuffer::new(Some(&tags));
// Collect links // Collect links
for line in data.lines() { for (i, line) in data.lines().enumerate() {
// Generate document title based on first line
if i == 0 {
let l = line.trim();
if !l.starts_with("=>") {
*title = Some(l.into())
}
}
// * skip links processing when the current location does not contain trailing slash // * skip links processing when the current location does not contain trailing slash
// it may be confusing: gemini://bbs.geminispace.org/s/nex/29641 // it may be confusing: gemini://bbs.geminispace.org/s/nex/29641
if base.to_string().ends_with("/") { if base.to_string().ends_with("/") {