diff options
Diffstat (limited to 'src/parse.rs')
-rw-r--r-- | src/parse.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/parse.rs b/src/parse.rs index a896cc2..d751579 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,3 +1,4 @@ +use std::path::Path; use std::fs::File; use std::io::prelude::*; use std::str::FromStr; @@ -9,7 +10,7 @@ use crate::html_calendar::*; // Translates a Path into a vector of tasks. Panics if the path cannot be opened or read from. pub fn tasks_from_path(wtd_path: &WTDPath) -> Vec<Task> { - let path = wtd_path.path; + let path = Path::new(&wtd_path.path); let display = path.display(); // Open the path in read-only mode, returns `io::Result<File>` @@ -22,18 +23,19 @@ pub fn tasks_from_path(wtd_path: &WTDPath) -> Vec<Task> { let mut s = String::new(); match file.read_to_string(&mut s) { Err(why) => panic!("Couldn't read {}: {}", display, why), - Ok(_) => { - return parse_file_str(&s); - } + Ok(_) => return parse_file_str(&s, wtd_path.week_start), } } -fn parse_file_str(file_str: &str) -> Vec<Task> { +fn parse_file_str(file_str: &str, implicit_week: Option<NaiveDate>) -> Vec<Task> { let mut tasks = Vec::new(); - let mut start_date = None; + let mut start_date = implicit_week; let mut the_date = None; for l in file_str.split('\n') { if l.starts_with("# ") { + if implicit_week.is_some() { + panic!("Cannot use '# ' headers in a weekly.md or [week].md file!"); + } // '# 12/27/21', starts a new week block start_date = parse_date_line(l); } else if l.starts_with("## ") { |