Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Keats committed Jun 20, 2024
1 parent cb2a4b0 commit 9c1b004
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 27 deletions.
3 changes: 3 additions & 0 deletions components/content/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ impl Library {

// Then once we took care of the sections, we find the pages of each section
for (path, page) in self.pages.iter_mut() {
if !page.meta.render {
continue;
}
let parent_filename = &index_filename_by_lang[&page.lang];
add_translation(&page.file.canonical, path);
let mut parent_section_path = page.file.parent.join(parent_filename);
Expand Down
25 changes: 0 additions & 25 deletions components/content/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ impl Page {
page.word_count = Some(word_count);
page.reading_time = Some(reading_time);

if !page.meta.render {
return Ok(page);
}

let mut slug_from_dated_filename = None;

let file_path_for_slug = if page.file.name == "index" {
Expand Down Expand Up @@ -927,25 +923,4 @@ Bonjour le monde"#
assert_eq!(page.slug, "hello");
assert_eq!(page.permalink, "http://a-website.com/bonjour/");
}

#[test]
fn page_without_physical_path() {
let config = Config::default();
let content = r#"
+++
render = false
+++
Hello world
"#
.to_string();

let res = Page::parse(Path::new("hello.md"), &content, &config, &PathBuf::new());
assert!(res.is_ok());
let page = res.unwrap();
println!("{:#?}", page);
assert_eq!(page.slug, "");
assert_eq!(page.path, "");
assert_eq!(page.permalink, "");
assert_eq!(page.raw_content, "Hello world\n".to_string());
}
}
6 changes: 5 additions & 1 deletion components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,10 @@ impl Site {

/// Renders a single content page
pub fn render_page(&self, page: &Page) -> Result<()> {
if !page.meta.render {
return Ok(());
}

let output = page.render_html(&self.tera, &self.config, &self.library.read().unwrap())?;
let content = self.inject_livereload(output);
let components: Vec<&str> = page.path.split('/').collect();
Expand Down Expand Up @@ -1087,7 +1091,7 @@ impl Site {
}

// Copy any asset we found previously into the same directory as the index.html
self.copy_assets(&section.file.path.parent().unwrap(), &section.assets, &output_path)?;
self.copy_assets(section.file.path.parent().unwrap(), &section.assets, &output_path)?;

if render_pages {
section
Expand Down
2 changes: 1 addition & 1 deletion components/site/tests/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn can_parse_site() {

let posts_section = library.sections.get(&posts_path.join("_index.md")).unwrap();
assert_eq!(posts_section.subsections.len(), 2);
assert_eq!(posts_section.pages.len(), 11); // 12 with 1 draft == 11
assert_eq!(posts_section.pages.len(), 10); // 11 with 1 draft == 10
assert_eq!(posts_section.ancestors, vec![index_section.file.relative.clone()]);

// Make sure we remove all the pwd + content from the sections
Expand Down

0 comments on commit 9c1b004

Please sign in to comment.