summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/collect_files.rs20
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();
+}