Finally got header and streak working
This commit is contained in:
17
src/main.rs
17
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) {
|
fn update_streak(daily_filepath: &str, file: &mut File) {
|
||||||
// Get filepath from yesterday. If does not exist, return 0.
|
// 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 yesterday_filepath = get_yesterday_filepath();
|
||||||
let today = Local::now();
|
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();
|
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 ();
|
return ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +119,8 @@ fn update_streak(daily_filepath: &str, file: &mut File) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let stringified_yaml = serde_yaml::to_string(&today_metadata).unwrap();
|
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 ();
|
return ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,9 +128,11 @@ fn update_streak(daily_filepath: &str, file: &mut File) {
|
|||||||
let today_metadata = DailyPostMetadata {
|
let today_metadata = DailyPostMetadata {
|
||||||
streak: prev_metadata.streak + 1,
|
streak: prev_metadata.streak + 1,
|
||||||
};
|
};
|
||||||
|
println!("two");
|
||||||
|
|
||||||
let stringified_yaml = serde_yaml::to_string(&today_metadata).unwrap();
|
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() {
|
fn main() {
|
||||||
@@ -146,6 +151,7 @@ fn main() {
|
|||||||
let file_exists = directory_iterator.any(|filename| *filename.unwrap().file_name() == *file_name);
|
let file_exists = directory_iterator.any(|filename| *filename.unwrap().file_name() == *file_name);
|
||||||
|
|
||||||
if !file_exists {
|
if !file_exists {
|
||||||
|
println!("file does not exist");
|
||||||
// Create a new file
|
// Create a new file
|
||||||
let mut file = File::create(&file_path).unwrap();
|
let mut file = File::create(&file_path).unwrap();
|
||||||
|
|
||||||
@@ -153,8 +159,9 @@ fn main() {
|
|||||||
let curent_streak = update_streak(&DAILY_FILEPATH, &mut file);
|
let curent_streak = update_streak(&DAILY_FILEPATH, &mut file);
|
||||||
|
|
||||||
// Write date at the start
|
// Write date at the start
|
||||||
let date_header = format!("#{}", &today_date_str);
|
let date_header = format!("# {}", &today_date_str);
|
||||||
writeln!(&mut file, "{}", &date_header);
|
writeln!(&mut file, "{}", &date_header);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user