diff --git a/src/app/browser/window/tab/item/page/content/text.rs b/src/app/browser/window/tab/item/page/content/text.rs index a831440f..d47c9e65 100644 --- a/src/app/browser/window/tab/item/page/content/text.rs +++ b/src/app/browser/window/tab/item/page/content/text.rs @@ -61,11 +61,12 @@ impl Text { } pub fn nex(actions: (&Rc, &Rc), 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 { scrolled_window: reader(&text_view), text_view, - meta: Meta { title: None }, + meta: Meta { title }, } } diff --git a/src/app/browser/window/tab/item/page/content/text/nex.rs b/src/app/browser/window/tab/item/page/content/text/nex.rs index c2d9b2ef..67dc90c0 100644 --- a/src/app/browser/window/tab/item/page/content/text/nex.rs +++ b/src/app/browser/window/tab/item/page/content/text/nex.rs @@ -14,7 +14,12 @@ use gutter::Gutter; use std::{cell::Cell, collections::HashMap, rc::Rc}; pub trait Nex { - fn nex(actions: (&Rc, &Rc), base: &Uri, data: &str) -> Self; + fn nex( + actions: (&Rc, &Rc), + base: &Uri, + data: &str, + title: &mut Option, + ) -> Self; } impl Nex for TextView { @@ -22,6 +27,7 @@ impl Nex for TextView { (window_action, item_action): (&Rc, &Rc), base: &Uri, data: &str, + title: &mut Option, ) -> Self { pub const NEW_LINE: &str = "\n"; @@ -50,7 +56,14 @@ impl Nex for TextView { let buffer = TextBuffer::new(Some(&tags)); // 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 // it may be confusing: gemini://bbs.geminispace.org/s/nex/29641 if base.to_string().ends_with("/") {