Skip to content

Commit

Permalink
Pass content_path to populate_library
Browse files Browse the repository at this point in the history
  • Loading branch information
Keats committed Apr 27, 2022
1 parent 84951d3 commit 3a0800c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions components/content/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Library {

/// Find out the direct subsections of each subsection if there are some
/// as well as the pages for each section
pub fn populate_sections(&mut self, config: &Config) {
pub fn populate_sections(&mut self, config: &Config, content_path: &Path) {
let mut add_translation = |entry: &Path, path: &Path| {
if config.is_multilingual() {
self.translations
Expand All @@ -134,8 +134,6 @@ impl Library {
}
};

let root_path =
self.sections.values().find(|s| s.is_index()).map(|s| s.file.parent.clone()).unwrap();
let mut ancestors = AHashMap::new();
let mut subsections = AHashMap::new();
let mut sections_weight = AHashMap::new();
Expand All @@ -161,7 +159,7 @@ impl Library {
}

// Index section is the first ancestor of every single section
let mut cur_path = root_path.clone();
let mut cur_path = content_path.to_path_buf();
let mut parents = vec![section.file.filename.clone()];
for component in &section.file.components {
cur_path = cur_path.join(component);
Expand Down Expand Up @@ -223,7 +221,7 @@ impl Library {
// is [index, ..., parent] so we need to reverse it first
if page.meta.template.is_none() {
for ancestor in page.ancestors.iter().rev() {
let s = self.sections.get(&root_path.join(ancestor)).unwrap();
let s = self.sections.get(&content_path.join(ancestor)).unwrap();
if let Some(ref tpl) = s.meta.page_template {
page.meta.template = Some(tpl.clone());
break;
Expand Down Expand Up @@ -425,7 +423,7 @@ mod tests {
for (p, l, s) in pages.clone() {
library.insert_page(create_page(p, l, s));
}
library.populate_sections(&config);
library.populate_sections(&config, Path::new("content"));
assert_eq!(library.sections.len(), sections.len());
assert_eq!(library.pages.len(), pages.len());
let blog_section = &library.sections[&PathBuf::from("content/blog/_index.md")];
Expand Down
2 changes: 1 addition & 1 deletion components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ impl Site {
/// as well as the pages for each section
pub fn populate_sections(&mut self) {
let mut library = self.library.write().expect("Get lock for populate_sections");
library.populate_sections(&self.config);
library.populate_sections(&self.config, &self.content_path);
}

/// Find all the tags and categories if it's asked in the config
Expand Down

0 comments on commit 3a0800c

Please sign in to comment.