From c7156a84f0ca4132c3380d75ba993f379a967cb5 Mon Sep 17 00:00:00 2001 From: cmal Date: Wed, 8 Aug 2018 10:51:40 +0200 Subject: [PATCH] Start implementing _index folder for section content/assets --- components/content/src/section.rs | 10 +++++++++- components/site/src/lib.rs | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/components/content/src/section.rs b/components/content/src/section.rs index 73727410..905c532a 100644 --- a/components/content/src/section.rs +++ b/components/content/src/section.rs @@ -82,9 +82,17 @@ impl Section { pub fn from_file>(path: P, config: &Config) -> Result
{ let path = path.as_ref(); let content = read_file(path)?; + println!("Parsing from file {:?}", path); let mut section = Section::parse(path, &content, config)?; - if section.file.name == "_index" { + println!("filename {:?}", section.file.name); + // I don't see any reason why, but section.file.name always is "_index"! ← bug + + let file_name = path.file_name().unwrap(); + + // Is this check really necessary? Should the else case happen at all? + if file_name == "_index.md" || file_name == "index.md" { + // In any case, we're looking for assets inside parent directory let parent_dir = path.parent().unwrap(); let assets = find_related_assets(parent_dir); diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 5d4236ac..b293b0ee 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -180,14 +180,20 @@ impl Site { let (section_entries, page_entries): (Vec<_>, Vec<_>) = glob(&content_glob) .unwrap() .filter_map(|e| e.ok()) - .partition(|entry| entry.as_path().file_name().unwrap() == "_index.md"); + // If file is _index.md and it doesn't have a sibling folder called _index containing an index.md (which have priority), we have a section + // If parent folder is _index and file is index.md then we have a section + .partition(|entry| ( (entry.as_path().file_name().unwrap() == "_index.md" && !entry.as_path().parent().unwrap().join("_index/index.md").is_file()) || (entry.as_path().parent().unwrap().file_name().unwrap() == "_index" && entry.as_path().file_name().unwrap() == "index.md"))); + + println!("Now section_entries"); + println!("{:?}", section_entries); let sections = { let config = &self.config; section_entries .into_par_iter() - .filter(|entry| entry.as_path().file_name().unwrap() == "_index.md") + // Is it really necessary to refilter for _index.md/index.md after the partition took place? + //.filter(|entry| entry.as_path().file_name().unwrap() == "_index.md") .map(|entry| { let path = entry.as_path(); Section::from_file(path, config) @@ -195,11 +201,15 @@ impl Site { .collect::>() }; + println!("Now sections:"); + println!("{:?}", sections); + let pages = { let config = &self.config; page_entries .into_par_iter() + // Same question. Do we have to refilter here given we have already partitioned results from the glob? .filter(|entry| entry.as_path().file_name().unwrap() != "_index.md") .map(|entry| { let path = entry.as_path(); @@ -216,7 +226,7 @@ impl Site { } // Insert a default index section if necessary so we don't need to create - // a _index.md to render the index page + // a _index.md to render the index page at the root of the site let index_path = self.index_section_path(); if let Some(ref index_section) = self.sections.get(&index_path) { if self.config.build_search_index && !index_section.meta.in_search_index {