diff options
| author | Ben Bridle <bridle.benjamin@gmail.com> | 2025-10-10 17:19:02 +1300 |
|---|---|---|
| committer | Ben Bridle <bridle.benjamin@gmail.com> | 2025-10-10 17:19:02 +1300 |
| commit | 1a51659875364217c60d68d694112c1c2ce1e2e1 (patch) | |
| tree | b54f19befe8bb61d24d1fbfa20c89845200b54f9 | |
| parent | 0848adc13790e276c6580c2b19042216a2b36067 (diff) | |
| download | toaster-1a51659875364217c60d68d694112c1c2ce1e2e1.zip | |
Allow folder names to contain a numeric prefix for sorting purposes
Markdown files could use a numeric prefix to force files to sort in a
particular order, with that prefix being stripped off and ignored by
toaster. This commit allows folders to also use a sorting prefix.
| -rw-r--r-- | src/collect_files.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/collect_files.rs b/src/collect_files.rs index 315a17e..cb785fc 100644 --- a/src/collect_files.rs +++ b/src/collect_files.rs @@ -137,11 +137,7 @@ impl Website { if entry.name.starts_with('.') { return } // Get name and extension. let (mut name, extension) = entry.split_name(); - if let Some((prefix, suffix)) = name.split_once(' ') { - if prefix.chars().all(|c| "0123456789-".contains(c)) { - name = suffix.to_string(); - } - } + name = strip_numeric_prefix(&name); let name_url = make_url_safe(&name); // Get last-modified time. let last_modified = entry.last_modified; @@ -150,7 +146,9 @@ impl Website { let relative_path = source_path.strip_prefix(prefix).unwrap_or_else( |_| fatal!("Path doesn't start with {prefix:?}: {source_path:?}")); let mut parents: Vec<_> = relative_path.components() - .map(|c| c.as_os_str().to_string_lossy().to_string()).collect(); + .map(|c| c.as_os_str().to_string_lossy().to_string()) + .map(|s| strip_numeric_prefix(&s)) + .collect(); parents.pop(); // Remove file segment. // Process each entry. @@ -419,3 +417,13 @@ fn collapse_path(path: &str) -> String { return segments.join("/"); } } + + +fn strip_numeric_prefix(name: &str) -> String { + if let Some((prefix, suffix)) = name.split_once(' ') { + if prefix.chars().all(|c| "0123456789-".contains(c)) { + return suffix.to_string(); + } + } + return name.to_string(); +} |
