Finally got header and streak working
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -92,7 +92,7 @@ fn read_daily_post_metadata(filepath: &str)-> Result<DailyPostMetadata, &str> {
|
||||
|
||||
fn update_streak(daily_filepath: &str, file: &mut File) {
|
||||
// Get filepath from yesterday. If does not exist, return 0.
|
||||
let mut streak: u32 = 0;
|
||||
let streak: u32 = 0;
|
||||
let yesterday_filepath = get_yesterday_filepath();
|
||||
let today = Local::now();
|
||||
|
||||
@@ -102,7 +102,9 @@ fn update_streak(daily_filepath: &str, file: &mut File) {
|
||||
};
|
||||
|
||||
let stringified_yaml = serde_yaml::to_string(&today_metadata).unwrap();
|
||||
file.write_all(stringified_yaml.as_bytes()).expect("Unable to write YAML metadata");
|
||||
let yaml = format!("---\n{}\n---\n", &stringified_yaml);
|
||||
file.write_all(yaml.as_bytes()).expect("Unable to write YAML metadata");
|
||||
|
||||
return ();
|
||||
}
|
||||
|
||||
@@ -117,7 +119,8 @@ fn update_streak(daily_filepath: &str, file: &mut File) {
|
||||
};
|
||||
|
||||
let stringified_yaml = serde_yaml::to_string(&today_metadata).unwrap();
|
||||
file.write_all(stringified_yaml.as_bytes()).expect("Unable to write YAML metadata");
|
||||
let yaml = format!("---\n{}\n---\n", &stringified_yaml);
|
||||
file.write_all(yaml.as_bytes()).expect("Unable to write YAML metadata");
|
||||
return ();
|
||||
}
|
||||
|
||||
@@ -125,9 +128,11 @@ fn update_streak(daily_filepath: &str, file: &mut File) {
|
||||
let today_metadata = DailyPostMetadata {
|
||||
streak: prev_metadata.streak + 1,
|
||||
};
|
||||
println!("two");
|
||||
|
||||
let stringified_yaml = serde_yaml::to_string(&today_metadata).unwrap();
|
||||
file.write_all(stringified_yaml.as_bytes()).expect("Unable to write YAML metadata");
|
||||
let yaml = format!("---\n{}\n---\n", &stringified_yaml);
|
||||
file.write_all(yaml.as_bytes()).expect("Unable to write YAML metadata");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -146,6 +151,7 @@ fn main() {
|
||||
let file_exists = directory_iterator.any(|filename| *filename.unwrap().file_name() == *file_name);
|
||||
|
||||
if !file_exists {
|
||||
println!("file does not exist");
|
||||
// Create a new file
|
||||
let mut file = File::create(&file_path).unwrap();
|
||||
|
||||
@@ -155,6 +161,7 @@ fn main() {
|
||||
// Write date at the start
|
||||
let date_header = format!("# {}", &today_date_str);
|
||||
writeln!(&mut file, "{}", &date_header);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user