From 0cd9e58a86b94cab7c5e484e7a1c24ace3dca565 Mon Sep 17 00:00:00 2001 From: Thomas Hurst Date: Thu, 1 Aug 2019 09:17:38 +0100 Subject: [PATCH] Allow relative paths in new_file()/new_section() (#763) These functions expect that file_path can have base_path stripped from it, but during reloading they can be given relative paths. Maybe this behaviour varies between the notify backends? This fixes two zola serve panics on FreeBSD (poll backend). --- components/library/src/content/file_info.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/library/src/content/file_info.rs b/components/library/src/content/file_info.rs index 8d58ebe..0348a7f 100644 --- a/components/library/src/content/file_info.rs +++ b/components/library/src/content/file_info.rs @@ -57,7 +57,7 @@ impl FileInfo { let mut parent = file_path.parent().expect("Get parent of page").to_path_buf(); let name = path.file_stem().unwrap().to_string_lossy().to_string(); let mut components = find_content_components( - &file_path.strip_prefix(base_path).expect("Strip base path prefix for page"), + &file_path.strip_prefix(base_path).unwrap_or(&file_path), ); let relative = if !components.is_empty() { format!("{}/{}.md", components.join("/"), name) @@ -92,7 +92,7 @@ impl FileInfo { let parent = path.parent().expect("Get parent of section").to_path_buf(); let name = path.file_stem().unwrap().to_string_lossy().to_string(); let components = find_content_components( - &file_path.strip_prefix(base_path).expect("Strip base path prefix for section"), + &file_path.strip_prefix(base_path).unwrap_or(&file_path), ); let relative = if !components.is_empty() { format!("{}/{}.md", components.join("/"), name)