Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix index errors #2129

Merged
merged 3 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl Site {
// at the end to detect pages that are actually errors:
// when there is both a _index.md and index.md in the same folder
let mut pages = Vec::new();
let mut components = HashSet::new();
let mut sections = HashSet::new();

loop {
let entry: DirEntry = match dir_walker.next() {
Expand Down Expand Up @@ -248,7 +248,7 @@ impl Site {
for index_file in index_files {
let section =
Section::from_file(index_file.path(), &self.config, &self.base_path)?;
components.extend(section.file.components.clone());
sections.insert(section.components.join("/"));

// if the section is drafted we can skip the entire dir
if section.meta.draft && !self.include_drafts {
Expand All @@ -275,7 +275,7 @@ impl Site {
// all the components there.
if page.file.filename == "index.md" {
let is_invalid = match page.components.last() {
Some(last) => components.contains(last),
Some(_) => sections.contains(&page.components.join("/")),
// content/index.md is always invalid, but content/colocated/index.md is ok
None => page.file.colocated_path.is_none(),
};
Expand Down
12 changes: 6 additions & 6 deletions components/site/tests/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn can_parse_site() {
let library = site.library.read().unwrap();

// Correct number of pages (sections do not count as pages, draft are ignored)
assert_eq!(library.pages.len(), 34);
assert_eq!(library.pages.len(), 35);
let posts_path = path.join("content").join("posts");

// Make sure the page with a url doesn't have any sections
Expand All @@ -34,12 +34,12 @@ fn can_parse_site() {
assert_eq!(asset_folder_post.file.components, vec!["posts".to_string()]);

// That we have the right number of sections
assert_eq!(library.sections.len(), 12);
assert_eq!(library.sections.len(), 13);

// And that the sections are correct
let index_section = library.sections.get(&path.join("content").join("_index.md")).unwrap();
assert_eq!(index_section.subsections.len(), 5);
assert_eq!(index_section.pages.len(), 4);
assert_eq!(index_section.pages.len(), 5);
assert!(index_section.ancestors.is_empty());

let posts_section = library.sections.get(&posts_path.join("_index.md")).unwrap();
Expand Down Expand Up @@ -279,7 +279,7 @@ fn can_build_site_with_live_reload_and_drafts() {

// drafted sections are included
let library = site.library.read().unwrap();
assert_eq!(library.sections.len(), 14);
assert_eq!(library.sections.len(), 15);

assert!(file_exists!(public, "secret_section/index.html"));
assert!(file_exists!(public, "secret_section/draft-page/index.html"));
Expand Down Expand Up @@ -545,13 +545,13 @@ fn can_build_site_with_pagination_for_index() {
"page/1/index.html",
"<a href=\"https://replace-this-with-your-url.com/\">Click here</a>"
));
assert!(file_contains!(public, "index.html", "Num pages: 2"));
assert!(file_contains!(public, "index.html", "Num pages: 3"));
assert!(file_contains!(public, "index.html", "Current index: 1"));
assert!(file_contains!(public, "index.html", "First: https://replace-this-with-your-url.com/"));
assert!(file_contains!(
public,
"index.html",
"Last: https://replace-this-with-your-url.com/page/2/"
"Last: https://replace-this-with-your-url.com/page/3/"
));
assert!(!file_contains!(public, "index.html", "has_prev"));
assert!(file_contains!(public, "index.html", "has_next"));
Expand Down
3 changes: 3 additions & 0 deletions test_site/content/2018/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
+++
title = "index page in a direction with the same name as a section"
+++
3 changes: 3 additions & 0 deletions test_site/content/colocated-assets/with_subfolder/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
+++
title = "Assets in root content directory"
+++