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
## 0.17.1 (unreleased)
- Fix bugs with colocated directories in the root `content` directory
## 0.17.0 (2023-02-16)
### Breaking

View file

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

View file

@ -157,7 +157,7 @@ impl Page {
}
} else {
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()
} else {
page.slug.clone()

View file

@ -277,8 +277,8 @@ impl Site {
if page.file.filename == "index.md" {
let is_invalid = match page.components.last() {
Some(last) => components.contains(last),
// content/index.md is always invalid
None => true,
// content/index.md is always invalid, but content/colocated/index.md is ok
None => page.file.colocated_path.is_none(),
};
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());
if render_md {
let insert_anchor =

View file

@ -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(), 33);
assert_eq!(library.pages.len(), 34);
let posts_path = path.join("content").join("posts");
// 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
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(), 3);
assert_eq!(index_section.pages.len(), 4);
assert!(index_section.ancestors.is_empty());
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",
"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]

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" %}
{% block content %}
{{ page.title | safe }}
{{ page.content | safe }}
{{ page.relative_path | safe }}
{{ page.toc }}