You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
772B

  1. use glob::glob;
  2. use tera::Tera;
  3. use config:: Config;
  4. use errors::{Result, ResultExt};
  5. use page::Page;
  6. pub fn build(config: Config) -> Result<()> {
  7. let tera = Tera::new("layouts/**/*").chain_err(|| "Error parsing templates")?;
  8. let mut pages: Vec<Page> = vec![];
  9. // hardcoded pattern so can't error
  10. for entry in glob("content/**/*.md").unwrap().filter_map(|e| e.ok()) {
  11. let path = entry.as_path();
  12. // Remove the content string from name
  13. let filepath = path.to_string_lossy().replace("content/", "");
  14. pages.push(Page::from_file(&filepath)?);
  15. }
  16. for page in pages {
  17. let html = page.render_html(&tera, &config)
  18. .chain_err(|| format!("Failed to render '{}'", page.filepath))?;
  19. }
  20. Ok(())
  21. }