Compare commits

...

3 Commits

Author SHA1 Message Date
projectmoon 3a4f7ba3a4 Verison 0.1.7: integrate Gemini library bugfixes
continuous-integration/drone/push Build is passing Details
2024-03-24 16:10:01 +01:00
projectmoon e9e04b1a0b Integrate germ bug fixes 2024-03-24 16:08:18 +01:00
projectmoon 8aa7369a12 upgrade to germ 0.4 2024-03-24 16:05:14 +01:00
3 changed files with 19 additions and 14 deletions

8
Cargo.lock generated
View File

@ -428,7 +428,7 @@ dependencies = [
[[package]] [[package]]
name = "gemfreely" name = "gemfreely"
version = "0.1.6" version = "0.1.7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"atom_syndication", "atom_syndication",
@ -478,12 +478,14 @@ dependencies = [
[[package]] [[package]]
name = "germ" name = "germ"
version = "0.3.10" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1a3b6e49850abb8a060002e2a3ec9a7e49626fc10192a93703f54e2589b9361" checksum = "6a44d21599b2d90136a258162d244267909f00073c4dce7ebda5a91b10f93f59"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"rustls 0.21.10", "rustls 0.21.10",
"tokio 1.36.0",
"tokio-rustls 0.24.1",
"url", "url",
] ]

View File

@ -1,6 +1,6 @@
[package] [package]
name = "gemfreely" name = "gemfreely"
version = "0.1.6" version = "0.1.7"
edition = "2021" edition = "2021"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
description = "Synchronize Gemini protocol blogs to the Fediverse" description = "Synchronize Gemini protocol blogs to the Fediverse"
@ -12,7 +12,7 @@ atom_syndication = "0.12.2"
chrono = "0.4.35" chrono = "0.4.35"
clap = { version = "4.5.3", features = ["derive"] } clap = { version = "4.5.3", features = ["derive"] }
gemini-feed = "0.1.0" gemini-feed = "0.1.0"
germ = "0.3" germ = {version = "0.4", features = ["blocking"] }
once_cell = "1.19.0" once_cell = "1.19.0"
regex = "1.10.3" regex = "1.10.3"
tokio = {version = "1.36", features = [ "full" ] } tokio = {version = "1.36", features = [ "full" ] }

View File

@ -1,7 +1,6 @@
use chrono::{DateTime, NaiveDate, Utc}; use chrono::{DateTime, NaiveDate, Utc};
use once_cell::sync::{Lazy, OnceCell}; use once_cell::sync::{Lazy, OnceCell};
use regex::Regex; use regex::Regex;
use std::borrow::Cow;
use std::path::PathBuf; use std::path::PathBuf;
use std::result::Result as StdResult; use std::result::Result as StdResult;
use std::slice::IterMut; use std::slice::IterMut;
@ -10,7 +9,9 @@ use anyhow::{anyhow, Error, Result};
use atom_syndication::{Entry as AtomEntry, Feed as AtomFeed}; use atom_syndication::{Entry as AtomEntry, Feed as AtomFeed};
use germ::ast::{Ast as GemtextAst, Node as GemtextNode}; use germ::ast::{Ast as GemtextAst, Node as GemtextNode};
use germ::convert::{self as germ_convert, Target}; use germ::convert::{self as germ_convert, Target};
use germ::request::{request as gemini_request, Response as GeminiResponse}; use germ::meta::Meta as GeminiMeta;
use germ::request::blocking::request as gemini_request;
use germ::request::Response as GeminiResponse;
use url::Url; use url::Url;
use crate::Cli; use crate::Cli;
@ -19,9 +20,9 @@ static GEMFEED_POST_REGEX: Lazy<regex::Regex> =
Lazy::new(|| Regex::new(r#"(\d\d\d\d-\d\d-\d\d)"#).unwrap()); Lazy::new(|| Regex::new(r#"(\d\d\d\d-\d\d-\d\d)"#).unwrap());
fn is_header(level: usize) -> bool { fn is_header(level: usize) -> bool {
// For some reason, Germ reports headers with an emoji as header level 0. level == 1
level == 0 || level == 1
} }
fn is_gemfeed_post_link(node: &GemtextNode) -> bool { fn is_gemfeed_post_link(node: &GemtextNode) -> bool {
match node { match node {
GemtextNode::Link { GemtextNode::Link {
@ -57,17 +58,17 @@ impl GemfeedType {
const ATOM_MIME_TYPES: &'static [&'static str] = &["text/xml", "application/atom+xml"]; const ATOM_MIME_TYPES: &'static [&'static str] = &["text/xml", "application/atom+xml"];
} }
impl From<Cow<'_, str>> for GemfeedType { impl From<GeminiMeta> for GemfeedType {
// See https://github.com/gemrest/germ/issues/2. Will be converted // See https://github.com/gemrest/germ/issues/2. Will be converted
// to use germ Meta struct after this is fixed. // to use germ Meta struct after this is fixed.
fn from(mime: Cow<'_, str>) -> Self { fn from(meta: GeminiMeta) -> Self {
let is_atom = Self::ATOM_MIME_TYPES let is_atom = Self::ATOM_MIME_TYPES
.into_iter() .into_iter()
.any(|atom_mime| mime.contains(atom_mime)); .any(|atom_mime| meta.mime().contains(atom_mime));
if is_atom { if is_atom {
GemfeedType::Atom GemfeedType::Atom
} else if mime.contains("text/gemini") { } else if meta.mime().contains("text/gemini") {
GemfeedType::Gemtext GemfeedType::Gemtext
} else { } else {
GemfeedType::Unknown GemfeedType::Unknown
@ -127,7 +128,9 @@ impl Gemfeed {
pub fn load_with_settings(url: &Url, settings: &GemfeedParserSettings) -> Result<Gemfeed> { pub fn load_with_settings(url: &Url, settings: &GemfeedParserSettings) -> Result<Gemfeed> {
let resp = gemini_request(url)?; let resp = gemini_request(url)?;
match GemfeedType::from(resp.meta()) { let meta = GeminiMeta::from_string(resp.meta());
match GemfeedType::from(meta) {
GemfeedType::Gemtext => Self::load_from_gemfeed(url, resp), GemfeedType::Gemtext => Self::load_from_gemfeed(url, resp),
GemfeedType::Atom => Self::load_from_atom(url, resp, &settings), GemfeedType::Atom => Self::load_from_atom(url, resp, &settings),
_ => Err(anyhow!( _ => Err(anyhow!(