2016-12-11 06:05:03 +00:00
|
|
|
use glob::glob;
|
|
|
|
use tera::Tera;
|
2016-12-06 08:27:03 +00:00
|
|
|
|
|
|
|
use config:: Config;
|
2016-12-11 06:05:03 +00:00
|
|
|
use errors::{Result, ResultExt};
|
|
|
|
use page::Page;
|
2016-12-06 12:48:23 +00:00
|
|
|
|
|
|
|
|
2016-12-06 08:27:03 +00:00
|
|
|
|
|
|
|
pub fn build(config: Config) -> Result<()> {
|
2016-12-11 06:05:03 +00:00
|
|
|
let tera = Tera::new("layouts/**/*").chain_err(|| "Error parsing templates")?;
|
|
|
|
let mut pages: Vec<Page> = vec![];
|
|
|
|
|
|
|
|
// hardcoded pattern so can't error
|
|
|
|
for entry in glob("content/**/*.md").unwrap().filter_map(|e| e.ok()) {
|
|
|
|
let path = entry.as_path();
|
|
|
|
// Remove the content string from name
|
|
|
|
let filepath = path.to_string_lossy().replace("content/", "");
|
|
|
|
pages.push(Page::from_file(&filepath)?);
|
|
|
|
}
|
|
|
|
|
|
|
|
for page in pages {
|
|
|
|
let html = page.render_html(&tera, &config)
|
|
|
|
.chain_err(|| format!("Failed to render '{}'", page.filepath))?;
|
|
|
|
}
|
2016-12-06 08:27:03 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|