summary refs log tree commit diff stats
path: root/src/new/section.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/new/section.rs')
-rw-r--r--src/new/section.rs63
1 files changed, 13 insertions, 50 deletions
diff --git a/src/new/section.rs b/src/new/section.rs
index 5e9f08c..a350f71 100644
--- a/src/new/section.rs
+++ b/src/new/section.rs
@@ -1,57 +1,14 @@
-use std::{
-    fs,
-    path::Path,
-    time::{SystemTime, UNIX_EPOCH},
-};
+use std::{fs, path::Path};
 
 use anyhow::Context;
-use chrono::{Local, TimeDelta, TimeZone};
 use log::debug;
 
 use crate::{
     config_file::Config,
     file_tree::{FileTree, GeneratedFile},
-    new::MangledName,
+    new::{replacement::untemplatize_section, MangledName},
 };
 
-fn get_current_date() -> String {
-    let start = SystemTime::now();
-    let seconds_since_epoch: TimeDelta = TimeDelta::from_std(
-        start
-            .duration_since(UNIX_EPOCH)
-            .expect("Time went backwards"),
-    )
-    .expect("Time does not go backwards");
-
-    debug!(
-        "Adding a date with timestamp: {}",
-        seconds_since_epoch.num_seconds()
-    );
-
-    let our_date = format!(
-        "{}",
-        Local
-            .timestamp_opt(seconds_since_epoch.num_seconds(), 0)
-            // only has unwrap, no expect. But should always work
-            .unwrap()
-            .format("%Y-%m-%d %H:%M:%S%.f %:z")
-    );
-
-    // let date = Command::new("date")
-    //     .args(["-d", &format!("@{}", seconds_since_epoch.num_seconds())])
-    //     .output()
-    //     .unwrap()
-    //     .stdout;
-
-    // info!(
-    //     "This is dated: '{}' vs. our date: '{}'",
-    //     String::from_utf8(date).unwrap().strip_suffix('\n').unwrap(),
-    //     our_date
-    // );
-
-    our_date
-}
-
 pub fn generate_new_section(
     config: &Config,
     name: String,
@@ -63,11 +20,17 @@ pub fn generate_new_section(
 
     let mut file_tree = FileTree::new();
 
-    let new_section_text = config
-        .templates
-        .section
-        .replace("REPLACMENT_SECTION_TITLE", &name)
-        .replace("DATE", &get_current_date());
+    let display_chapter_name = MangledName::from_str_unsafe(
+        chapter_name
+            .chars()
+            .skip_while(|a: &char| a.is_digit(10) || *(a) == '_')
+            .collect::<String>()
+            .as_str(),
+    )
+    .try_unmangle();
+
+    let new_section_text =
+        untemplatize_section(&config.templates.section, &name, &display_chapter_name);
 
     file_tree.add_file(GeneratedFile::new_clobber(
         chapter_root