Skip to content

Commit

Permalink
Fix colocated assets in content directory
Browse files Browse the repository at this point in the history
Closes #2101
  • Loading branch information
Keats committed Feb 24, 2023
1 parent 5f90ad1 commit c67655e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions components/content/src/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion components/content/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 2 additions & 5 deletions components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 =
Expand Down
11 changes: 9 additions & 2 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(), 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
Expand All @@ -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();
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions docs/content/hello/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
+++
+++

Hello
3 changes: 3 additions & 0 deletions test_site/content/colocated-assets/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
+++
title = "Assets in root content directory"
+++
1 change: 1 addition & 0 deletions test_site/templates/page.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "index.html" %}

{% block content %}
{{ page.title | safe }}
{{ page.content | safe }}
{{ page.relative_path | safe }}
{{ page.toc }}
Expand Down

0 comments on commit c67655e

Please sign in to comment.