Browse Source

Create a default index section if there is none

index-subcmd
Vincent Prouillet 7 years ago
parent
commit
005990a928
3 changed files with 28 additions and 3 deletions
  1. +1
    -1
      src/front_matter.rs
  2. +18
    -0
      src/section.rs
  3. +9
    -2
      src/site.rs

+ 1
- 1
src/front_matter.rs View File

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


+ 18
- 0
src/section.rs View File

@@ -131,3 +131,21 @@ impl ser::Serialize for Section {
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![],
}
}
}

+ 9
- 2
src/site.rs View File

@@ -171,6 +171,12 @@ impl Site {
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
// 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();
for section in self.sections.values() {
let grand_parent = section.parent_path.parent().unwrap().to_path_buf();
grandparent_paths.entry(grand_parent).or_insert_with(|| vec![]).push(section.clone());
if let Some(grand_parent) = section.parent_path.parent() {
grandparent_paths.entry(grand_parent.to_path_buf()).or_insert_with(|| vec![]).push(section.clone());
}
}

for (parent_path, section) in &mut self.sections {


Loading…
Cancel
Save