Skip to content

Commit dff6186

Browse files
committed
Add pandoc converter
1 parent 92f07ef commit dff6186

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

generator/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ struct Cli {
1717

1818
fn main() -> Result<(), Error> {
1919
let cli = Cli::parse();
20-
println!("{}", reports::clone(cli.reports)?.display());
20+
let reports_org_path = reports::clone(cli.reports)?;
21+
let reports_org_list = reports::find(reports_org_path)?;
22+
for report in reports_org_list {
23+
dbg!(&report);
24+
let new_md_report = reports::convert(report)?;
25+
dbg!(new_md_report);
26+
// add_report_to_website(new_md_report)?;
27+
}
2128
Ok(())
2229
}

generator/src/reports.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use std::path::PathBuf;
2+
use std::process::Command;
3+
4+
use std::fs;
25

36
use git2::Repository;
47
use mktemp::Temp;
@@ -10,3 +13,28 @@ pub fn clone(reports_repo: String) -> Result<PathBuf, Error> {
1013
Repository::clone(&reports_repo, &path_to_repo)?;
1114
Ok(path_to_repo)
1215
}
16+
17+
pub fn find(reports_org_path: PathBuf) -> Result<Vec<PathBuf>, Error> {
18+
let mut results = Vec::new();
19+
for entry in fs::read_dir(reports_org_path)? {
20+
let entry = entry?;
21+
let path = entry.path();
22+
if let Some(Some("org")) = path.extension().map(|osstr| osstr.to_str()) {
23+
results.push(path);
24+
}
25+
}
26+
Ok(results)
27+
}
28+
29+
pub fn convert(report_org_path: PathBuf) -> Result<PathBuf, Error> {
30+
let mut report_md_path = report_org_path.clone();
31+
report_md_path.set_extension("md");
32+
Command::new("pandoc")
33+
.arg("--from=org")
34+
.arg("--to=gfm")
35+
.arg(report_org_path)
36+
.arg("-o")
37+
.arg(&report_md_path)
38+
.spawn()?;
39+
Ok(report_md_path)
40+
}

0 commit comments

Comments
 (0)