From 9717476273e05379ada099946307ae2682b8abef Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sat, 18 Jan 2025 10:00:44 +1300 Subject: Allow redirects to point to external websites If the path in a .redirect file contains any scheme (detected as ://), the path is used as-is instead of trying to resolve to the name of an internal page. --- src/main.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index a742cfe..0fccc2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -125,12 +125,17 @@ fn main() { for redirect in &website.redirects { let mut destination = destination.clone(); destination.push(&redirect.full_url); - if let Some(path) = website.has_page(redirect, &redirect.redirect, "html") { - if args.html { + let path = &redirect.redirect; + if args.html { + if !path.contains("://") { + if let Some(path) = website.has_page(redirect, &path, "html") { + write_file(&generate_html_redirect(&path), &destination, "html"); + } else { + warn!("Redirect {:?} links to nonexistent page {path:?}", redirect.name); + } + } else { write_file(&generate_html_redirect(&path), &destination, "html"); } - } else { - warn!("Redirect {:?} links to nonexistent page {:?}", redirect.name, redirect.redirect); } } } -- cgit v1.2.3-70-g09d2