mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
update content api, add common uri_to_title helper function
This commit is contained in:
parent
7757bc2283
commit
56744fd695
1 changed files with 27 additions and 9 deletions
|
|
@ -489,9 +489,8 @@ impl Page {
|
||||||
move |result|{
|
move |result|{
|
||||||
match result {
|
match result {
|
||||||
Ok(buffer) => {
|
Ok(buffer) => {
|
||||||
// Update page meta
|
//
|
||||||
meta.borrow_mut().status = Some(Status::Success);
|
let text_gemini = content.set_text_gemini(
|
||||||
meta.borrow_mut().title = content.set_text_gemini(
|
|
||||||
&uri,
|
&uri,
|
||||||
&match GString::from_utf8(buffer.to_utf8()) {
|
&match GString::from_utf8(buffer.to_utf8()) {
|
||||||
Ok(gemtext) => gemtext,
|
Ok(gemtext) => gemtext,
|
||||||
|
|
@ -499,6 +498,13 @@ impl Page {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Update page meta
|
||||||
|
meta.borrow_mut().status = Some(Status::Success);
|
||||||
|
meta.borrow_mut().title = Some(match text_gemini.meta_title() {
|
||||||
|
Some(title) => title.clone(),
|
||||||
|
None => uri_to_title(&uri)
|
||||||
|
});
|
||||||
|
|
||||||
// Update window components
|
// Update window components
|
||||||
action_update.activate(Some(&id));
|
action_update.activate(Some(&id));
|
||||||
}
|
}
|
||||||
|
|
@ -571,12 +577,7 @@ impl Page {
|
||||||
Ok(buffer) => {
|
Ok(buffer) => {
|
||||||
// Update page meta
|
// Update page meta
|
||||||
meta.borrow_mut().status = Some(Status::Success);
|
meta.borrow_mut().status = Some(Status::Success);
|
||||||
meta.borrow_mut().title = Some(
|
meta.borrow_mut().title = Some(uri_to_title(&uri));
|
||||||
match url.split('/').last() { // @TODO may be empty
|
|
||||||
Some(filename) => gformat!("{filename}"),
|
|
||||||
None => gformat!("Image")
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update page content
|
// Update page content
|
||||||
content.set_image(&buffer);
|
content.set_image(&buffer);
|
||||||
|
|
@ -825,3 +826,20 @@ impl Page {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tools
|
||||||
|
|
||||||
|
/// Helper function, extract readable title from [Uri](https://docs.gtk.org/glib/struct.Uri.html)
|
||||||
|
///
|
||||||
|
/// Useful as common placeholder when page title could not be detected
|
||||||
|
///
|
||||||
|
/// * this feature may be improved and moved outside @TODO
|
||||||
|
fn uri_to_title(uri: &Uri) -> GString {
|
||||||
|
match uri.path().split('/').last() {
|
||||||
|
Some(filename) => gformat!("{filename}"),
|
||||||
|
None => match uri.host() {
|
||||||
|
Some(host) => gformat!("{host}"),
|
||||||
|
None => gformat!("Untitled"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue