Allow specifying how many items go into the feed
Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
parent
4710996e50
commit
595977388f
@ -31,6 +31,9 @@ pub(crate) struct FeedBuilderSettings {
|
|||||||
/// Create an HTML file for each message
|
/// Create an HTML file for each message
|
||||||
#[clap(short, long, value_parser, default_value_t = false)]
|
#[clap(short, long, value_parser, default_value_t = false)]
|
||||||
pub include_html: bool,
|
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)]
|
#[derive(Subcommand)]
|
||||||
|
@ -41,6 +41,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
&settings.filename,
|
&settings.filename,
|
||||||
&settings.hostname,
|
&settings.hostname,
|
||||||
settings.include_html,
|
settings.include_html,
|
||||||
|
settings.max_items
|
||||||
),
|
),
|
||||||
|
|
||||||
cli::Command::Update => command::update::self_update(),
|
cli::Command::Update => command::update::self_update(),
|
||||||
@ -63,6 +64,7 @@ fn build_feed(
|
|||||||
filename: &PathBuf,
|
filename: &PathBuf,
|
||||||
hostname: &String,
|
hostname: &String,
|
||||||
include_html: bool,
|
include_html: bool,
|
||||||
|
max_items_in_feed: Option<usize>
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
let dir = filename.parent().ok_or(format!(
|
let dir = filename.parent().ok_or(format!(
|
||||||
"Could not get parent directory of {}",
|
"Could not get parent directory of {}",
|
||||||
@ -87,7 +89,9 @@ fn build_feed(
|
|||||||
|
|
||||||
let mut reader = DataDirectoryMessageReader::new(Path::new("data").to_path_buf());
|
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 parsed = msg.get_parsed().expect("A parsed messsage.");
|
||||||
|
|
||||||
let date = parsed.date().ok_or(format!(
|
let date = parsed.date().ok_or(format!(
|
||||||
|
Loading…
Reference in New Issue
Block a user