Create a default index section if there is none

This commit is contained in:
Vincent Prouillet 2017-05-12 16:30:01 +09:00
parent aa7ddef123
commit 005990a928
3 changed files with 28 additions and 3 deletions

View file

@ -150,7 +150,7 @@ impl Default for FrontMatter {
template: None, template: None,
paginate_by: None, paginate_by: None,
paginate_path: None, paginate_path: None,
render: None, render: Some(true),
extra: None, extra: None,
} }
} }

View file

@ -131,3 +131,21 @@ impl ser::Serialize for Section {
state.end() state.end()
} }
} }
impl Default for Section {
/// Used to create a default index section if there is no _index.md
fn default() -> Section {
Section {
file_path: PathBuf::new(),
relative_path: "".to_string(),
parent_path: PathBuf::new(),
components: vec![],
path: "".to_string(),
permalink: "".to_string(),
meta: FrontMatter::default(),
pages: vec![],
ignored_pages: vec![],
subsections: vec![],
}
}
}

View file

@ -171,6 +171,12 @@ impl Site {
self.add_page(path)?; self.add_page(path)?;
} }
} }
// Insert a default index section so we don't need to create a _index.md to render
// the index page
let index_path = self.base_path.join("content");
if !self.sections.contains_key(&index_path) {
self.sections.insert(index_path, Section::default());
}
// A map of all .md files (section and pages) and their permalink // A map of all .md files (section and pages) and their permalink
// We need that if there are relative links in the content that need to be resolved // We need that if there are relative links in the content that need to be resolved
@ -234,8 +240,9 @@ impl Site {
let mut grandparent_paths = HashMap::new(); let mut grandparent_paths = HashMap::new();
for section in self.sections.values() { for section in self.sections.values() {
let grand_parent = section.parent_path.parent().unwrap().to_path_buf(); if let Some(grand_parent) = section.parent_path.parent() {
grandparent_paths.entry(grand_parent).or_insert_with(|| vec![]).push(section.clone()); grandparent_paths.entry(grand_parent.to_path_buf()).or_insert_with(|| vec![]).push(section.clone());
}
} }
for (parent_path, section) in &mut self.sections { for (parent_path, section) in &mut self.sections {