crabmail

Static HTML email archive viewer in Rust
git clone git://git.alexwennerberg.com/crabmail
Log | Files | Refs | README | LICENSE

commit 9774180fd72d3183e6cd47338e6761bb65b4cd12
parent dc47475c4de3c82970a8f915f1889c065a9c00e4
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Thu, 17 Mar 2022 21:48:19 -0700

fix path bug

Diffstat:
Msrc/main.rs | 21+++++++++++++++------
Msrc/templates/html.rs | 6+++---
2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -25,6 +25,17 @@ const PAGE_SIZE: i32 = 100; // TODO +use std::ffi::{OsStr, OsString}; +use std::path::Path; + +// stole it from the internet +pub fn append_ext(ext: impl AsRef<OsStr>, path: &PathBuf) -> PathBuf { + let mut os_string: OsString = path.into(); + os_string.push("."); + os_string.push(ext.as_ref()); + os_string.into() +} + impl Lists { fn write_lists(&mut self) { std::fs::create_dir_all(&self.out_dir); @@ -105,13 +116,11 @@ impl List { // Load thread let thread = Thread::new(thread_ids); let basepath = thread_dir.join(&thread.messages[0].pathescape_msg_id()); - write_if_unchanged( - &basepath.with_extension("html"), - thread.to_html().as_bytes(), - ); - write_if_unchanged(&basepath.with_extension("xml"), thread.to_xml().as_bytes()); + // hacky + write_if_unchanged(&append_ext("html", &basepath), thread.to_html().as_bytes()); + write_if_unchanged(&append_ext("xml", &basepath), thread.to_xml().as_bytes()); if Config::global().include_gemini { - write_if_unchanged(&basepath.with_extension("gmi"), thread.to_gmi().as_bytes()); + write_if_unchanged(&append_ext("gmi", &basepath), thread.to_gmi().as_bytes()); } // this is a bit awkward self.thread_topics.push(thread.messages[0].clone()); diff --git a/src/templates/html.rs b/src/templates/html.rs @@ -53,9 +53,9 @@ impl List { "#, &[ ("path_id", &x(thread.pathescape_msg_id().to_str().unwrap())), - ("subject", &thread.subject), - ("date", &thread.date), - ("preview", &thread.preview), + ("subject", &x(&thread.subject)), + ("date", &x(&thread.date)), + ("preview", &x(&thread.preview)), ], ) .unwrap(),