Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change custom page files to use a .md extension. #322

Merged
merged 8 commits into from
Feb 15, 2024
28 changes: 28 additions & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ impl Cache {

// Look up custom page (<name>.page.md). If it exists, return it directly
if let Some(config_dir) = custom_pages_dir {
self.check_for_old_custom_pages(config_dir);

let custom_page = config_dir.join(custom_filename);
if custom_page.exists() && custom_page.is_file() {
return Some(PageLookupResult::with_page(custom_page));
Expand Down Expand Up @@ -407,6 +409,32 @@ impl Cache {

Ok(true)
}

fn check_for_old_custom_pages(&self, custom_pages_dir: &Path) {
let old_custom_pages_exist = WalkDir::new(custom_pages_dir)
.min_depth(1)
.max_depth(1)
.into_iter()
.filter_entry(|entry| entry.file_type().is_file())
.any(|entry| {
if let Ok(entry) = entry {
let extension = entry.path().extension();
if let Some(extension) = extension {
extension == "page" || extension == "patch"
} else {
false
}
} else {
false
}
});
dbrgn marked this conversation as resolved.
Show resolved Hide resolved
if old_custom_pages_exist {
eprintln!("Warning: Custom pages using the old naming convention were found.\n\
Please rename them to follow the new convention:\n\
\t- `<name>.page` → `<name>.page.md`\n\
\t- `<name>.patch` → `<name>.patch.md`\n");
}
}
}

/// Unit Tests for cache module
Expand Down
Loading