diff --git a/src/format.rs b/src/format.rs
index e6c46dc..b0c3d2b 100644
--- a/src/format.rs
+++ b/src/format.rs
@@ -97,14 +97,19 @@ fn format_attachments(depth: usize, attachments: &[Attachment]) -> String {
// line, breaking the desired formatting
fn apply_block_quote
", "\n\n"); let content = content.replace("
", ""); let content = content.replace("
", ""); + // TODO refactor into separate function + let content = content.replace("\\*", "*"); + let content = content.replace(":totoro:", "\\:totoro\\:"); // replace separately to avoid trailing spaces when replacing empty lines with the prefix let content = empty.replace_all(content.as_ref(), format!("\n{}\n", prefix.trim())); let content = non_empty.replace_all(&content, |c: &Captures| { diff --git a/src/main.rs b/src/main.rs index e00b043..62a9afa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,7 +127,7 @@ async fn main() -> Result<()> { Ok(exists) if exists => { debug!("Appending {}", output); let mut file = File::options().append(true).open(&output)?; - file.write("\n".as_bytes())?; + file.write("\n\n".as_bytes())?; file } _ => { @@ -138,30 +138,23 @@ async fn main() -> Result<()> { .open(&output) .with_context(|| format!("Failed to create {}", output))?; file.write(format!("# {}\n\n", day.end.format("%Y-%m-%d")).as_bytes())?; - // TODO extract into a more general function - let week_ago = day.end - Duration::days(7); - // TODO check if the file exists + + // TODO move to separate function + file.write(create_back_link(&day.end, "[One week ago](diary:{})\n", 7).as_bytes())?; file.write( - format!("[One week ago](diary:{})\n", week_ago.format("%Y-%m-%d")).as_bytes(), + create_back_link(&day.end, "[One month ago](diary:{})\n", 30).as_bytes(), )?; - let month_ago = day.end - Duration::days(30); - // TODO check if the file exists file.write( - format!("[One month ago](diary:{})\n", month_ago.format("%Y-%m-%d")).as_bytes(), + create_back_link(&day.end, "[Six months ago](diary:{})\n", 6 * 30).as_bytes(), )?; - let half_year_ago = day.end - Duration::days(6 * 30); - // TODO check if the file exists file.write( - format!( - "[Six months ago](diary:{})\n", - half_year_ago.format("%Y-%m-%d") - ) - .as_bytes(), + create_back_link(&day.end, "[One year ago](diary:{})\n", 365).as_bytes(), )?; - let year_ago = day.end - Duration::days(365); - // TODO check if the file exists file.write( - format!("[One year ago](diary:{})\n", year_ago.format("%Y-%m-%d")).as_bytes(), + create_back_link(&day.end, "[Two years ago](diary:{})\n", 365 * 2).as_bytes(), + )?; + file.write( + create_back_link(&day.end, "[Three years ago](diary:{})\n", 365 * 3).as_bytes(), )?; file } @@ -175,6 +168,16 @@ async fn main() -> Result<()> { Ok(()) } +fn create_back_link(day_end: &DateTime