allow excluding paths from atom feed

this acts on resulting paths that end up in the feed
(something/hidden.html), not the input paths (something/hidden.org)
This commit is contained in:
xfnw 2024-04-28 10:38:27 -04:00
parent 5b442802b4
commit 6444bca63d
2 changed files with 19 additions and 3 deletions

View File

@ -2,7 +2,7 @@ use crate::git::ModifyMap;
use chrono::{DateTime, NaiveDateTime};
use html_escaper::Escape;
use std::{
collections::BTreeMap,
collections::{BTreeMap, BTreeSet},
fmt::{self, Write},
path::PathBuf,
};
@ -49,6 +49,7 @@ impl fmt::Display for AtomDateTime {
pub fn entries<'a>(
titles: &'a BTreeMap<PathBuf, (String, PathBuf)>,
mtime: &'a ModifyMap,
exclude: &'a Option<BTreeSet<String>>,
) -> Result<Vec<AtomEntry<'a>>, Box<dyn std::error::Error>> {
let mut entries = vec![];
@ -57,6 +58,13 @@ pub fn entries<'a>(
Some(p) => p,
None => continue,
};
if let Some(exclude) = exclude {
if exclude.contains(path) {
continue;
}
}
let (updated, author) = mtime.get(old).ok_or("missing modification info")?;
let updated = AtomDateTime::new(updated.seconds()).ok_or("broken modification date")?;

View File

@ -4,7 +4,14 @@ use clap::Parser;
use git2::{Object, Repository};
use orgize::ParseConfig;
use serde_derive::Deserialize;
use std::{cmp::min, collections::BTreeMap, error::Error, fs, io::Write, path::PathBuf};
use std::{
cmp::min,
collections::{BTreeMap, BTreeSet},
error::Error,
fs,
io::Write,
path::PathBuf,
};
mod atom;
mod git;
@ -24,6 +31,7 @@ struct ClamConfig {
title: String,
id: Option<String>,
url: String,
exclude: Option<BTreeSet<String>>,
}
fn generate(
@ -70,7 +78,7 @@ fn generate(
if let Ok(config) = fs::read_to_string(".clam.toml") {
let config: ClamConfig = toml::from_str(&config)?;
let feed = atom::entries(&titles, &mtime)?;
let feed = atom::entries(&titles, &mtime, &config.exclude)?;
let mut f = fs::File::create("feed.xml")?;
f.write_all(