summaryrefslogtreecommitdiff
path: root/src/generate_html.rs
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2026-11-10 11:35:18 +1300
committerBen Bridle <ben@derelict.engineering>2026-11-10 11:35:42 +1300
commite7691befe7322df597c97d54c82d143eb1247555 (patch)
tree790d058d7ccd453873d520cfb775b25f6403ac5a /src/generate_html.rs
parentaecf433eb9725fb65f785d27d946fc58f7c76ea5 (diff)
downloadtoaster-e7691befe7322df597c97d54c82d143eb1247555.zip
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.
Diffstat (limited to 'src/generate_html.rs')
-rw-r--r--src/generate_html.rs20
1 files changed, 11 insertions, 9 deletions
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,