zola/src/cmd/build.rs

29 lines
772 B
Rust
Raw Normal View History

use glob::glob;
use tera::Tera;
2016-12-06 08:27:03 +00:00
use config:: Config;
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<()> {
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(())
}