mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
parse canonical url once per feed init
This commit is contained in:
parent
1d4022f618
commit
04f4387534
2 changed files with 33 additions and 12 deletions
22
src/feed.rs
22
src/feed.rs
|
|
@ -1,10 +1,13 @@
|
|||
mod link;
|
||||
|
||||
use crate::Torrent;
|
||||
use link::Link;
|
||||
use url::Url;
|
||||
|
||||
/// Export crawl index to the RSS file
|
||||
pub struct Feed {
|
||||
buffer: String,
|
||||
canonical: Option<Url>,
|
||||
canonical: Link,
|
||||
}
|
||||
|
||||
impl Feed {
|
||||
|
|
@ -43,7 +46,11 @@ impl Feed {
|
|||
buffer.push_str(c.as_str());
|
||||
buffer.push_str("</link>")
|
||||
}
|
||||
Self { buffer, canonical }
|
||||
|
||||
Self {
|
||||
buffer,
|
||||
canonical: Link::from_url(canonical),
|
||||
}
|
||||
}
|
||||
|
||||
/// Append `item` to the feed `channel`
|
||||
|
|
@ -58,16 +65,7 @@ impl Feed {
|
|||
.map(|b| b.to_string())
|
||||
.unwrap_or("?".into()) // @TODO
|
||||
),
|
||||
self.canonical
|
||||
.clone()
|
||||
.map(|mut c| escape({
|
||||
c.set_path(&torrent.info_hash);
|
||||
c.set_fragment(None);
|
||||
c.set_query(None);
|
||||
c.as_str()
|
||||
}))
|
||||
.unwrap_or(escape(&torrent.info_hash)) // should be non-optional absolute URL
|
||||
// by the RSS specification @TODO
|
||||
self.canonical.link(&torrent.info_hash)
|
||||
));
|
||||
|
||||
self.buffer.push_str("<description>");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue