Compare commits
No commits in common. "3a4f7ba3a4a0f9c394c5c0b82b34b6a3f3adf4f1" and "aab2e0e358e7625b1c635589ede20c0efbfef067" have entirely different histories.
3a4f7ba3a4
...
aab2e0e358
|
@ -428,7 +428,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "gemfreely"
|
||||
version = "0.1.7"
|
||||
version = "0.1.6"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"atom_syndication",
|
||||
|
@ -478,14 +478,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "germ"
|
||||
version = "0.4.0"
|
||||
version = "0.3.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a44d21599b2d90136a258162d244267909f00073c4dce7ebda5a91b10f93f59"
|
||||
checksum = "e1a3b6e49850abb8a060002e2a3ec9a7e49626fc10192a93703f54e2589b9361"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"rustls 0.21.10",
|
||||
"tokio 1.36.0",
|
||||
"tokio-rustls 0.24.1",
|
||||
"url",
|
||||
]
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "gemfreely"
|
||||
version = "0.1.7"
|
||||
version = "0.1.6"
|
||||
edition = "2021"
|
||||
license = "AGPL-3.0-or-later"
|
||||
description = "Synchronize Gemini protocol blogs to the Fediverse"
|
||||
|
@ -12,7 +12,7 @@ atom_syndication = "0.12.2"
|
|||
chrono = "0.4.35"
|
||||
clap = { version = "4.5.3", features = ["derive"] }
|
||||
gemini-feed = "0.1.0"
|
||||
germ = {version = "0.4", features = ["blocking"] }
|
||||
germ = "0.3"
|
||||
once_cell = "1.19.0"
|
||||
regex = "1.10.3"
|
||||
tokio = {version = "1.36", features = [ "full" ] }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use chrono::{DateTime, NaiveDate, Utc};
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
use regex::Regex;
|
||||
use std::borrow::Cow;
|
||||
use std::path::PathBuf;
|
||||
use std::result::Result as StdResult;
|
||||
use std::slice::IterMut;
|
||||
|
@ -9,9 +10,7 @@ use anyhow::{anyhow, Error, Result};
|
|||
use atom_syndication::{Entry as AtomEntry, Feed as AtomFeed};
|
||||
use germ::ast::{Ast as GemtextAst, Node as GemtextNode};
|
||||
use germ::convert::{self as germ_convert, Target};
|
||||
use germ::meta::Meta as GeminiMeta;
|
||||
use germ::request::blocking::request as gemini_request;
|
||||
use germ::request::Response as GeminiResponse;
|
||||
use germ::request::{request as gemini_request, Response as GeminiResponse};
|
||||
use url::Url;
|
||||
|
||||
use crate::Cli;
|
||||
|
@ -20,9 +19,9 @@ static GEMFEED_POST_REGEX: Lazy<regex::Regex> =
|
|||
Lazy::new(|| Regex::new(r#"(\d\d\d\d-\d\d-\d\d)"#).unwrap());
|
||||
|
||||
fn is_header(level: usize) -> bool {
|
||||
level == 1
|
||||
// For some reason, Germ reports headers with an emoji as header level 0.
|
||||
level == 0 || level == 1
|
||||
}
|
||||
|
||||
fn is_gemfeed_post_link(node: &GemtextNode) -> bool {
|
||||
match node {
|
||||
GemtextNode::Link {
|
||||
|
@ -58,17 +57,17 @@ impl GemfeedType {
|
|||
const ATOM_MIME_TYPES: &'static [&'static str] = &["text/xml", "application/atom+xml"];
|
||||
}
|
||||
|
||||
impl From<GeminiMeta> for GemfeedType {
|
||||
impl From<Cow<'_, str>> for GemfeedType {
|
||||
// See https://github.com/gemrest/germ/issues/2. Will be converted
|
||||
// to use germ Meta struct after this is fixed.
|
||||
fn from(meta: GeminiMeta) -> Self {
|
||||
fn from(mime: Cow<'_, str>) -> Self {
|
||||
let is_atom = Self::ATOM_MIME_TYPES
|
||||
.into_iter()
|
||||
.any(|atom_mime| meta.mime().contains(atom_mime));
|
||||
.any(|atom_mime| mime.contains(atom_mime));
|
||||
|
||||
if is_atom {
|
||||
GemfeedType::Atom
|
||||
} else if meta.mime().contains("text/gemini") {
|
||||
} else if mime.contains("text/gemini") {
|
||||
GemfeedType::Gemtext
|
||||
} else {
|
||||
GemfeedType::Unknown
|
||||
|
@ -128,9 +127,7 @@ impl Gemfeed {
|
|||
|
||||
pub fn load_with_settings(url: &Url, settings: &GemfeedParserSettings) -> Result<Gemfeed> {
|
||||
let resp = gemini_request(url)?;
|
||||
let meta = GeminiMeta::from_string(resp.meta());
|
||||
|
||||
match GemfeedType::from(meta) {
|
||||
match GemfeedType::from(resp.meta()) {
|
||||
GemfeedType::Gemtext => Self::load_from_gemfeed(url, resp),
|
||||
GemfeedType::Atom => Self::load_from_atom(url, resp, &settings),
|
||||
_ => Err(anyhow!(
|
||||
|
|
Loading…
Reference in New Issue