diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2025-01-18 10:00:44 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2025-01-18 10:00:44 +1300 |
commit | 9717476273e05379ada099946307ae2682b8abef (patch) | |
tree | 59501ba894060a9639a0f603e0dd25b64540515a /src/main.rs | |
parent | a9d9f98283394d7edc0f5ed73569fefe1c15721b (diff) | |
download | toaster-9717476273e05379ada099946307ae2682b8abef.zip |
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.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 13 |
1 files changed, 9 insertions, 4 deletions
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); } } } |