summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/feed.rs21
1 files changed, 14 insertions, 7 deletions
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 {
83 let (entries, errors): (Vec<_>, Vec<_>) = channel 83 let (entries, errors): (Vec<_>, Vec<_>) = channel
84 .entries 84 .entries
85 .iter() 85 .iter()
86 .map(Entry::try_from) 86 .map(|e| Entry::try_from(e, &self.link))
87 .partition(Result::is_ok); 87 .partition(Result::is_ok);
88 88
89 // pull status 89 // pull status
@@ -102,7 +102,7 @@ impl Feed {
102 102
103impl fmt::Display for Feed { 103impl fmt::Display for Feed {
104 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 104 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
105 write!(f, "{}", self.title) 105 write!(f, "{}", self.title.to_lowercase())
106 } 106 }
107} 107}
108 108
@@ -114,9 +114,8 @@ pub struct Entry {
114 pub unread: bool, 114 pub unread: bool,
115} 115}
116 116
117impl TryFrom<&ChannelEntry> for Entry { 117impl Entry {
118 type Error = EntryError; 118 fn try_from(e: &ChannelEntry, feed_url: &Url) -> Result<Self, EntryError> {
119 fn try_from(e: &ChannelEntry) -> Result<Self, Self::Error> {
120 let title = e 119 let title = e
121 .title 120 .title
122 .as_ref() 121 .as_ref()
@@ -127,7 +126,9 @@ impl TryFrom<&ChannelEntry> for Entry {
127 .first() 126 .first()
128 .map(|l| l.href.clone()) 127 .map(|l| l.href.clone())
129 .ok_or(EntryError::MissingLink)?; 128 .ok_or(EntryError::MissingLink)?;
130 let link = Url::parse(&raw_link).map_err(|_| EntryError::InvalidLink)?; 129 let link = Url::parse(&raw_link)
130 .or_else(|_| feed_url.join(&raw_link))
131 .map_err(|_| EntryError::InvalidLink)?;
131 let published = e 132 let published = e
132 .published 133 .published
133 .or(e.updated) 134 .or(e.updated)
@@ -144,6 +145,12 @@ impl TryFrom<&ChannelEntry> for Entry {
144 145
145impl fmt::Display for Entry { 146impl fmt::Display for Entry {
146 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 147 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
147 write!(f, "{} {} {}", self.link, self.title, self.published) 148 write!(
149 f,
150 "{} {} {}",
151 self.published.format("%v"),
152 self.link,
153 self.title.to_lowercase(),
154 )
148 } 155 }
149} 156}