rss-exclusive notes, improvements, 2019-02-02 bread added

This commit is contained in:
2019-02-02 21:25:17 +01:00
parent 03a34e0e09
commit f876c590f3
6 changed files with 62 additions and 23 deletions
+23 -1
View File
@@ -27,6 +27,7 @@ struct Bread {
rel_path: PathBuf,
date: chrono::NaiveDate,
note: String,
rss_note: String,
images: Vec<PathBuf>,
}
@@ -50,13 +51,19 @@ impl Bread {
fn parse(base_dir : &PathBuf, bread_dir : &DirEntry) -> Result<Bread, std::io::Error> {
let bpath = bread_dir.path();
let mut note = String::new();
let mut rss_note = String::new();
let mut note_path = bpath.join("note.txt");
let mut rss_note_path = bpath.join("rss.txt");
// try a md one as a fallback
if !note_path.exists() {
note_path = bpath.join("note.md");
}
if !rss_note_path.exists() {
rss_note_path = bpath.join("rss.md");
}
if note_path.exists() {
let mut note_file = File::open(note_path)?;
@@ -64,6 +71,12 @@ impl Bread {
note = markdown::to_html(&note);
}
if rss_note_path.exists() {
let mut note_file = File::open(rss_note_path)?;
note_file.read_to_string(&mut rss_note)?;
rss_note = markdown::to_html(&rss_note);
}
let mut bread_files: Vec<DirEntry> = fs::read_dir(&bpath)?.map(|e| e.unwrap()).collect();
bread_files.sort_by(|x, y| x.file_name().cmp(&y.file_name()));
@@ -82,6 +95,7 @@ impl Bread {
rel_path: bpath.strip_prefix(base_dir).unwrap().to_path_buf(),
path: bpath,
note,
rss_note,
images
});
}
@@ -139,6 +153,7 @@ fn main() {
let (img_path, img_alt) = bread.thumb_photo();
let note = if bread.note.is_empty() { "<i>There's no note about this bread.</i>" } else { &bread.note };
let rss_note = &bread.rss_note;
let thumb_fname = date_slug.clone() + "." + Path::new(&img_path).extension().unwrap().to_str().unwrap();
let thumb_path = thumbs_path.join(&thumb_fname);
@@ -191,11 +206,18 @@ fn main() {
let date_formatted : Date<Utc> = chrono::Utc.from_local_date(&bread.date).unwrap();
let dt = date_formatted.and_hms(12,0,0);
let mut descr = String::new();
if !rss_note.is_empty() {
descr.push_str(&(rss_note.to_string() + "<hr>"));
}
descr.push_str(note);
descr.push_str(&format!("<img src=\"{}\" alt=\"{}\"><p><i>Open the link for full-res photos ({} total)</i>", image_url, img_alt, bread.images.len()));
channel_items.push(ItemBuilder::default()
.title(date.clone())
.link(link.clone())
.description(note.to_string() + &format!("<img src=\"{}\" alt=\"{}\"><p>Open the link for more...</p>", image_url, img_alt))
.description(descr)
.guid(guid)
.pub_date(dt.to_rfc2822())
.build().unwrap());