From dbd914d6b5e0d1a566ffa12489f6327dc0eacc47 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 20 May 2023 19:36:54 +0530 Subject: support relative links in entries --- src/feed.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/feed.rs b/src/feed.rs index 2875667..c3c5408 100644 --- a/src/feed.rs +++ b/src/feed.rs @@ -83,7 +83,7 @@ impl Feed { let (entries, errors): (Vec<_>, Vec<_>) = channel .entries .iter() - .map(Entry::try_from) + .map(|e| Entry::try_from(e, &self.link)) .partition(Result::is_ok); // pull status @@ -102,7 +102,7 @@ impl Feed { impl fmt::Display for Feed { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.title) + write!(f, "{}", self.title.to_lowercase()) } } @@ -114,9 +114,8 @@ pub struct Entry { pub unread: bool, } -impl TryFrom<&ChannelEntry> for Entry { - type Error = EntryError; - fn try_from(e: &ChannelEntry) -> Result { +impl Entry { + fn try_from(e: &ChannelEntry, feed_url: &Url) -> Result { let title = e .title .as_ref() @@ -127,7 +126,9 @@ impl TryFrom<&ChannelEntry> for Entry { .first() .map(|l| l.href.clone()) .ok_or(EntryError::MissingLink)?; - let link = Url::parse(&raw_link).map_err(|_| EntryError::InvalidLink)?; + let link = Url::parse(&raw_link) + .or_else(|_| feed_url.join(&raw_link)) + .map_err(|_| EntryError::InvalidLink)?; let published = e .published .or(e.updated) @@ -144,6 +145,12 @@ impl TryFrom<&ChannelEntry> for Entry { impl fmt::Display for Entry { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{} {} {}", self.link, self.title, self.published) + write!( + f, + "{} {} {}", + self.published.format("%v"), + self.link, + self.title.to_lowercase(), + ) } } -- cgit v1.2.3