Fix colocated assets in content directory

Closes #2101
This commit is contained in:
Vincent Prouillet 2023-02-16 22:41:01 +01:00 committed by Vincent Prouillet
parent 5f90ad1d33
commit c67655e29f
8 changed files with 25 additions and 8 deletions

View File

@ -1,5 +1,9 @@
# Changelog # Changelog
## 0.17.1 (unreleased)
- Fix bugs with colocated directories in the root `content` directory
## 0.17.0 (2023-02-16) ## 0.17.0 (2023-02-16)
### Breaking ### Breaking

View File

@ -77,6 +77,7 @@ impl FileInfo {
val.push('/'); val.push('/');
val val
}); });
components.pop(); components.pop();
// also set parent_path to grandparent instead // also set parent_path to grandparent instead
parent = parent.parent().unwrap().to_path_buf(); parent = parent.parent().unwrap().to_path_buf();

View File

@ -157,7 +157,7 @@ impl Page {
} }
} else { } else {
let mut path = if page.file.components.is_empty() { let mut path = if page.file.components.is_empty() {
if page.file.name == "index" { if page.file.name == "index" && page.file.colocated_path.is_none() {
String::new() String::new()
} else { } else {
page.slug.clone() page.slug.clone()

View File

@ -277,8 +277,8 @@ impl Site {
if page.file.filename == "index.md" { if page.file.filename == "index.md" {
let is_invalid = match page.components.last() { let is_invalid = match page.components.last() {
Some(last) => components.contains(last), Some(last) => components.contains(last),
// content/index.md is always invalid // content/index.md is always invalid, but content/colocated/index.md is ok
None => true, None => page.file.colocated_path.is_none(),
}; };
if is_invalid { if is_invalid {
@ -472,9 +472,6 @@ impl Site {
} }
} }
// We can't have a page called index.md when there is a _index.md in the same folder
if page.file.filename == "index.md" {}
self.permalinks.insert(page.file.relative.clone(), page.permalink.clone()); self.permalinks.insert(page.file.relative.clone(), page.permalink.clone());
if render_md { if render_md {
let insert_anchor = let insert_anchor =

View File

@ -21,7 +21,7 @@ fn can_parse_site() {
let library = site.library.read().unwrap(); let library = site.library.read().unwrap();
// Correct number of pages (sections do not count as pages, draft are ignored) // Correct number of pages (sections do not count as pages, draft are ignored)
assert_eq!(library.pages.len(), 33); assert_eq!(library.pages.len(), 34);
let posts_path = path.join("content").join("posts"); let posts_path = path.join("content").join("posts");
// Make sure the page with a url doesn't have any sections // Make sure the page with a url doesn't have any sections
@ -39,7 +39,7 @@ fn can_parse_site() {
// And that the sections are correct // And that the sections are correct
let index_section = library.sections.get(&path.join("content").join("_index.md")).unwrap(); let index_section = library.sections.get(&path.join("content").join("_index.md")).unwrap();
assert_eq!(index_section.subsections.len(), 5); assert_eq!(index_section.subsections.len(), 5);
assert_eq!(index_section.pages.len(), 3); assert_eq!(index_section.pages.len(), 4);
assert!(index_section.ancestors.is_empty()); assert!(index_section.ancestors.is_empty());
let posts_section = library.sections.get(&posts_path.join("_index.md")).unwrap(); let posts_section = library.sections.get(&posts_path.join("_index.md")).unwrap();
@ -221,6 +221,13 @@ fn can_build_site_without_live_reload() {
"robots.txt", "robots.txt",
"Sitemap: https://replace-this-with-your-url.com/sitemap.xml" "Sitemap: https://replace-this-with-your-url.com/sitemap.xml"
)); ));
// And
assert!(file_contains!(
public,
"colocated-assets/index.html",
"Assets in root content directory"
));
} }
#[test] #[test]

View File

@ -0,0 +1,4 @@
+++
+++
Hello

View File

@ -0,0 +1,3 @@
+++
title = "Assets in root content directory"
+++

View File

@ -1,6 +1,7 @@
{% extends "index.html" %} {% extends "index.html" %}
{% block content %} {% block content %}
{{ page.title | safe }}
{{ page.content | safe }} {{ page.content | safe }}
{{ page.relative_path | safe }} {{ page.relative_path | safe }}
{{ page.toc }} {{ page.toc }}