Start implementing _index folder for section content/assets
This commit is contained in:
parent
15190962ba
commit
c7156a84f0
|
@ -82,9 +82,17 @@ impl Section {
|
|||
pub fn from_file<P: AsRef<Path>>(path: P, config: &Config) -> Result<Section> {
|
||||
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);
|
||||
|
||||
|
|
|
@ -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::<Vec<_>>()
|
||||
};
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue