Allow specifying how many items go into the feed

Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
Jacob Kiers 2024-06-27 17:46:49 +02:00
parent 4710996e50
commit 595977388f
2 changed files with 8 additions and 1 deletions

View File

@ -31,6 +31,9 @@ pub(crate) struct FeedBuilderSettings {
/// Create an HTML file for each message
#[clap(short, long, value_parser, default_value_t = false)]
pub include_html: bool,
/// Maximum number of items in the feed (default: unlimited)
#[clap(short = 'n', long, value_parser)]
pub max_items: Option<usize>,
}
#[derive(Subcommand)]

View File

@ -41,6 +41,7 @@ fn main() -> Result<(), Box<dyn Error>> {
&settings.filename,
&settings.hostname,
settings.include_html,
settings.max_items
),
cli::Command::Update => command::update::self_update(),
@ -63,6 +64,7 @@ fn build_feed(
filename: &PathBuf,
hostname: &String,
include_html: bool,
max_items_in_feed: Option<usize>
) -> Result<(), Box<dyn Error>> {
let dir = filename.parent().ok_or(format!(
"Could not get parent directory of {}",
@ -87,7 +89,9 @@ fn build_feed(
let mut reader = DataDirectoryMessageReader::new(Path::new("data").to_path_buf());
for msg in reader.read_rfc822_messages() {
let max_items_in_feed = max_items_in_feed.unwrap_or_else(|| usize::MAX);
for msg in reader.read_rfc822_messages().take(max_items_in_feed) {
let parsed = msg.get_parsed().expect("A parsed messsage.");
let date = parsed.date().ok_or(format!(