Skip to content

Commit 11c32bd

Browse files
committed
Conform to new report name format
1 parent 7384304 commit 11c32bd

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

generator/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
pub enum Error {
33
CloneFail(git2::Error),
44
IO(std::io::Error),
5+
InvalidDatePrefix,
6+
NoDateInOrgReport,
57
}
68

79
impl From<git2::Error> for Error {

generator/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ fn main() -> Result<(), Error> {
2121
let reports_org_list = reports::find(reports_org_path)?;
2222
for report in reports_org_list {
2323
let report_md = reports::convert(report, &cli.website)?;
24-
// add_report_to_website(new_md_report)?;
2524
}
2625
Ok(())
2726
}

generator/src/reports.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,29 @@ pub fn find(reports_org_path: PathBuf) -> Result<Vec<PathBuf>, Error> {
2626
Ok(results)
2727
}
2828

29+
fn get_date(report_org_path: &Path) -> Result<String, Error> {
30+
let content = fs::read_to_string(report_org_path)?;
31+
for line in content.lines() {
32+
if line.starts_with("#+date:") {
33+
let date = line
34+
.split(':')
35+
.nth(1)
36+
.ok_or(Error::InvalidDatePrefix)?
37+
.trim()
38+
.to_string();
39+
return Ok(date);
40+
}
41+
}
42+
Err(Error::NoDateInOrgReport)
43+
}
44+
2945
pub fn convert(report_org_path: PathBuf, website: &Path) -> Result<PathBuf, Error> {
46+
let mut report_md_filename = get_date(&report_org_path)?;
47+
report_md_filename.push_str("-");
48+
report_md_filename.push_str(report_org_path.file_name().unwrap().to_str().unwrap());
3049
let mut report_md_path = website
31-
.join("reporting")
32-
.join(PathBuf::from(report_org_path.clone().file_name().unwrap()));
33-
dbg!(&report_md_path);
50+
.join("_posts")
51+
.join(PathBuf::from(report_md_filename));
3452
report_md_path.set_extension("md");
3553
Command::new("pandoc")
3654
.arg("--from=org")
@@ -39,5 +57,6 @@ pub fn convert(report_org_path: PathBuf, website: &Path) -> Result<PathBuf, Erro
3957
.arg("-o")
4058
.arg(&report_md_path)
4159
.spawn()?;
60+
dbg!(&report_md_path);
4261
Ok(report_md_path)
4362
}

0 commit comments

Comments
 (0)