diff options
Diffstat (limited to 'src/collect_files.rs')
-rw-r--r-- | src/collect_files.rs | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/collect_files.rs b/src/collect_files.rs index 18d75f1..ccdfc49 100644 --- a/src/collect_files.rs +++ b/src/collect_files.rs @@ -4,6 +4,7 @@ use highlight::*; use vagabond::*; use std::collections::HashMap; +use std::fmt::Debug; pub struct Website { @@ -49,7 +50,7 @@ pub struct Redirect { pub last_modified: Option<SystemTime>, // last-modified time of source file } -pub trait LinkFrom { +pub trait LinkFrom: Debug { fn name(&self) -> &str; fn parent_url(&self) -> &str; fn parents(&self) -> &[String]; @@ -60,6 +61,12 @@ pub trait LinkFrom { } return root; } + fn qualified_name(&self) -> String { + match self.parents().last() { + Some(parent) => format!("{parent}/{}", self.name()), + None => format!("/{}", self.name()), + } + } } pub struct Highlighters { @@ -77,6 +84,18 @@ impl Page { } } +impl Debug for Page { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + write!(f, "\"{}\"", self.qualified_name()) + } +} + +impl Debug for Redirect { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + write!(f, "\"{}\"", self.qualified_name()) + } +} + impl LinkFrom for Page { fn name(&self) -> &str { &self.name } fn parent_url(&self) -> &str { &self.parent_url } @@ -174,6 +193,10 @@ impl Website { self.config.insert(key, std::mem::take(&mut value)); } } else { + let full_name = match parents.last() { + Some(parent) => format!("{parent}/{name}"), + None => name.to_string(), + }; match extension.as_str() { "md" => { let markdown = std::fs::read_to_string(&source_path).unwrap(); @@ -193,7 +216,7 @@ impl Website { None }).collect(); for url in duplicates { - warn!("Page {name:?} contains multiple headings with ID \"#{url}\""); + warn!("Page {full_name:?} contains multiple headings with ID \"#{url}\""); } if name_url == "+index" { if parents.is_empty() { @@ -339,7 +362,7 @@ impl Website { if let Some(heading) = heading { let heading = make_url_safe(strip_appendix(heading)); if !page.headings.iter().any(|h| h.url == heading) { - warn!("Page {:?} contains link to nonexistent heading {heading:?} on page {path:?}", from.name()); + warn!("Page {from:?} contains link to nonexistent heading {heading:?} on page {path:?}"); } return Some(format!("{root}{path}.{ext}#{heading}")); } else { |