update ggemtext api

This commit is contained in:
yggverse 2025-03-17 21:56:13 +02:00
parent 28ffc08a25
commit 40299ab608

View file

@ -18,12 +18,11 @@ use gtk::{
UriLauncher, Window, WrapMode, UriLauncher, Window, WrapMode,
gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY, RGBA}, gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY, RGBA},
gio::Cancellable, gio::Cancellable,
glib::{TimeZone, Uri}, glib::Uri,
prelude::{TextBufferExt, TextBufferExtManual, TextTagExt, TextViewExt, WidgetExt}, prelude::{TextBufferExt, TextBufferExtManual, TextTagExt, TextViewExt, WidgetExt},
}; };
use std::{cell::Cell, collections::HashMap, rc::Rc}; use std::{cell::Cell, collections::HashMap, rc::Rc};
pub const DATE_FORMAT: &str = "%Y-%m-%d";
pub const NEW_LINE: &str = "\n"; pub const NEW_LINE: &str = "\n";
pub struct Gemini { pub struct Gemini {
@ -259,25 +258,17 @@ impl Gemini {
} }
// Is link // Is link
if let Some(link) = if let Some(link) = ggemtext::line::Link::parse(line) {
ggemtext::line::Link::from(line, Some(base), Some(&TimeZone::local())) if let Some(uri) = link.uri(Some(base)) {
{
let mut alt = Vec::new(); let mut alt = Vec::new();
if link.uri.scheme() != base.scheme() { if uri.scheme() != base.scheme() {
alt.push("".to_string()); alt.push("".to_string());
} }
if let Some(t) = link.timestamp {
// https://docs.gtk.org/glib/method.DateTime.format.html
if let Ok(f) = t.format(DATE_FORMAT) {
alt.push(f.to_string())
}
}
alt.push(match link.alt { alt.push(match link.alt {
Some(alt) => alt.to_string(), Some(alt) => alt.to_string(),
None => link.uri.to_string(), None => uri.to_string(),
}); });
let a = TextTag::builder() let a = TextTag::builder()
@ -294,7 +285,8 @@ impl Gemini {
buffer.insert_with_tags(&mut buffer.end_iter(), &alt.join(" "), &[&a]); buffer.insert_with_tags(&mut buffer.end_iter(), &alt.join(" "), &[&a]);
buffer.insert(&mut buffer.end_iter(), NEW_LINE); buffer.insert(&mut buffer.end_iter(), NEW_LINE);
links.insert(a, link.uri.clone()); links.insert(a, uri);
}
continue; continue;
} }