Skip to content

Commit

Permalink
Add a temporary check for old custom pages to assist in the migration…
Browse files Browse the repository at this point in the history
… to the new naming convention.
  • Loading branch information
zedseven committed Feb 11, 2024
1 parent 5d809e7 commit 378dca4
Showing 1 changed file with 28 additions and 0 deletions.
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
}
});
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

0 comments on commit 378dca4

Please sign in to comment.