From b40c687689763b5c7d6d33fe3c6149c38c6248bb Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sat, 18 Jan 2025 09:57:42 +1300 Subject: Fix internal links to headings on another page The heading section of the link wasn't being suffixed to the generated link target, so links to a heading on another page were just regular links to the top of that page. --- src/collect_files.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/collect_files.rs b/src/collect_files.rs index cf39ebe..dfcc847 100644 --- a/src/collect_files.rs +++ b/src/collect_files.rs @@ -296,13 +296,15 @@ impl Website { let path = make_url_safe(&segments.join("/")); for page in &self.pages { if page.full_url == path { + let root = from.root(); if let Some(heading) = heading { if !page.headings.iter().any(|h| h.url == make_url_safe(heading)) { warn!("Page {:?} contains link to nonexistent heading {heading:?} on page {path:?}", from.name()); } + return Some(format!("{root}{path}.{ext}#{heading}")); + } else { + return Some(format!("{root}{path}.{ext}")); } - let root = from.root(); - return Some(format!("{root}{path}.{ext}")); } } return None; -- cgit v1.2.3-70-g09d2