From e7691befe7322df597c97d54c82d143eb1247555 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 10 Nov 2026 11:35:18 +1300 Subject: Add support for other URL schemes If an external URL has a scheme that isn't either http, https, or mailto, the link label will contain the scheme in order to make it clear to viewers that the link is different to usual. This was added to support 'gemini://' links. --- src/generate_html.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/generate_html.rs b/src/generate_html.rs index cb2f1f3..353d1fb 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -510,17 +510,19 @@ fn parse_external_link(label: &str, path: &str, page: &Page, website: &Website) let from = &page; let mut path = path.to_owned(); let mut label = label.to_string(); - let mut is_internal = true; - for protocol in ["mailto:", "http://", "https://"] { - if let Some(stripped) = path.strip_prefix(protocol) { - is_internal = false; - if label.is_empty() { - label = stripped.to_string(); + + if let Some(stripped) = path.strip_prefix("mailto:") { + if label.is_empty() { + label = stripped.to_string(); + } + } else if let Some((scheme, stripped)) = path.split_once("://") { + if label.is_empty() { + label = stripped.to_string(); + if !scheme.contains("http") { + label = format!("{scheme}://{label}"); } - break; } - } - if is_internal { + } else { // Check that the linked static file exists. match website.has_static(page, &path) { Some(resolved) => path = resolved, -- cgit v1.3.1