diff options
author | Akshay <[email protected]> | 2023-05-20 15:06:54 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2023-05-20 15:06:54 +0100 |
commit | dbd914d6b5e0d1a566ffa12489f6327dc0eacc47 (patch) | |
tree | 6eae691f94ae43d85b224473f3af100f34999cb9 /src | |
parent | dea860819e7c0439debfcdd3050408e1e6cef10f (diff) |
support relative links in entries
Diffstat (limited to 'src')
-rw-r--r-- | src/feed.rs | 21 |
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 | ||
103 | impl fmt::Display for Feed { | 103 | impl 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 | ||
117 | impl TryFrom<&ChannelEntry> for Entry { | 117 | impl 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 | ||
145 | impl fmt::Display for Entry { | 146 | impl 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 | } |