Skip to content

Commit a4c3ce7

Browse files
committed
Fix colocated assets in content directory
Closes #2101
1 parent 6f683ce commit a4c3ce7

File tree

8 files changed

+25
-8
lines changed

8 files changed

+25
-8
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.17.1 (unreleased)
4+
5+
- Fix bugs with colocated directories in the root `content` directory
6+
37
## 0.17.0 (2023-02-16)
48

59
### Breaking

Diff for: components/content/src/file_info.rs

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl FileInfo {
7777
val.push('/');
7878
val
7979
});
80+
8081
components.pop();
8182
// also set parent_path to grandparent instead
8283
parent = parent.parent().unwrap().to_path_buf();

Diff for: components/content/src/page.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl Page {
157157
}
158158
} else {
159159
let mut path = if page.file.components.is_empty() {
160-
if page.file.name == "index" {
160+
if page.file.name == "index" && page.file.colocated_path.is_none() {
161161
String::new()
162162
} else {
163163
page.slug.clone()

Diff for: components/site/src/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ impl Site {
277277
if page.file.filename == "index.md" {
278278
let is_invalid = match page.components.last() {
279279
Some(last) => components.contains(last),
280-
// content/index.md is always invalid
281-
None => true,
280+
// content/index.md is always invalid, but content/colocated/index.md is ok
281+
None => page.file.colocated_path.is_none(),
282282
};
283283

284284
if is_invalid {
@@ -472,9 +472,6 @@ impl Site {
472472
}
473473
}
474474

475-
// We can't have a page called index.md when there is a _index.md in the same folder
476-
if page.file.filename == "index.md" {}
477-
478475
self.permalinks.insert(page.file.relative.clone(), page.permalink.clone());
479476
if render_md {
480477
let insert_anchor =

Diff for: components/site/tests/site.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn can_parse_site() {
2121
let library = site.library.read().unwrap();
2222

2323
// Correct number of pages (sections do not count as pages, draft are ignored)
24-
assert_eq!(library.pages.len(), 33);
24+
assert_eq!(library.pages.len(), 34);
2525
let posts_path = path.join("content").join("posts");
2626

2727
// Make sure the page with a url doesn't have any sections
@@ -39,7 +39,7 @@ fn can_parse_site() {
3939
// And that the sections are correct
4040
let index_section = library.sections.get(&path.join("content").join("_index.md")).unwrap();
4141
assert_eq!(index_section.subsections.len(), 5);
42-
assert_eq!(index_section.pages.len(), 3);
42+
assert_eq!(index_section.pages.len(), 4);
4343
assert!(index_section.ancestors.is_empty());
4444

4545
let posts_section = library.sections.get(&posts_path.join("_index.md")).unwrap();
@@ -221,6 +221,13 @@ fn can_build_site_without_live_reload() {
221221
"robots.txt",
222222
"Sitemap: https://replace-this-with-your-url.com/sitemap.xml"
223223
));
224+
225+
// And
226+
assert!(file_contains!(
227+
public,
228+
"colocated-assets/index.html",
229+
"Assets in root content directory"
230+
));
224231
}
225232

226233
#[test]

Diff for: docs/content/hello/index.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
+++
2+
+++
3+
4+
Hello

Diff for: test_site/content/colocated-assets/index.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
+++
2+
title = "Assets in root content directory"
3+
+++

Diff for: test_site/templates/page.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{% extends "index.html" %}
22

33
{% block content %}
4+
{{ page.title | safe }}
45
{{ page.content | safe }}
56
{{ page.relative_path | safe }}
67
{{ page.toc }}

0 commit comments

Comments
 (0)