Skip to main content

rss_proxy/plugin/builtin/
limit.rs

1use crate::model::Feed;
2use crate::plugin::Plugin;
3use async_trait::async_trait;
4
5pub struct LimitPlugin {
6    pub max_items: usize,
7}
8
9impl LimitPlugin {
10    pub fn new(max_items: usize) -> Self {
11        Self { max_items }
12    }
13}
14
15#[async_trait]
16impl Plugin for LimitPlugin {
17    fn name(&self) -> &str {
18        "LimitPlugin"
19    }
20
21    async fn post_process_feed(&self, feed: &mut Feed) -> anyhow::Result<()> {
22        if feed.items.len() > self.max_items {
23            feed.items.truncate(self.max_items);
24        }
25        Ok(())
26    }
27}