From 6b7bbadeb589261c9d9a304a024fd216667598ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Casta=C3=B1o=20Arteaga?= Date: Thu, 16 Apr 2026 08:16:31 +0200 Subject: [PATCH] Support mailto links in other_links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergio CastaƱo Arteaga --- crates/core/src/data/legacy.rs | 14 ++++++++++---- crates/core/src/util.rs | 19 +++++++++++++++++++ docs/config/data.yml | 3 ++- docs/config/schema/data.schema.json | 3 ++- ui/common/src/components/ExternalLink.tsx | 14 +++++++++++--- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/crates/core/src/data/legacy.rs b/crates/core/src/data/legacy.rs index 1c0db951..42272977 100644 --- a/crates/core/src/data/legacy.rs +++ b/crates/core/src/data/legacy.rs @@ -301,10 +301,16 @@ mod tests { ..Default::default() }]), blog_url: Some("https://blog.url".to_string()), - other_links: Some(vec![ItemLink { - name: "link".to_string(), - url: "https://link.url".to_string(), - }]), + other_links: Some(vec![ + ItemLink { + name: "email".to_string(), + url: "mailto:team@example.com".to_string(), + }, + ItemLink { + name: "link".to_string(), + url: "https://link.url".to_string(), + }, + ]), ..Default::default() }), ..Default::default() diff --git a/crates/core/src/util.rs b/crates/core/src/util.rs index b3fb061d..4155cb7f 100644 --- a/crates/core/src/util.rs +++ b/crates/core/src/util.rs @@ -58,6 +58,9 @@ pub(crate) fn validate_url(kind: &str, url: Option<&String>) -> Result<()> { }; // Check scheme + if kind == "other_link" && url.scheme() == "mailto" { + return Ok(()); + } if url.scheme() != "http" && url.scheme() != "https" { return invalid_url("invalid scheme"); } @@ -147,6 +150,11 @@ mod tests { } } + #[test] + fn validate_url_mailto_other_link_succeeds() { + validate_url("other_link", Some("mailto:team@example.com".to_string()).as_ref()).unwrap(); + } + #[test] #[should_panic(expected = "relative URL without a base")] fn validate_url_error_parsing() { @@ -188,4 +196,15 @@ mod tests { assert!(error.starts_with(expected_error.as_str())); } } + + #[test] + fn validate_url_mailto_other_field_fails() { + let error = validate_url( + "mailing_list", + Some("mailto:team@example.com".to_string()).as_ref(), + ) + .unwrap_err() + .to_string(); + assert_eq!(error, "invalid mailing_list url: invalid scheme"); + } } diff --git a/docs/config/data.yml b/docs/config/data.yml index 137965ad..881fa8eb 100644 --- a/docs/config/data.yml +++ b/docs/config/data.yml @@ -218,7 +218,8 @@ categories: # - # Name of the link (required). # name: Link name # # URL of the link (required). - # url: https://link.url + # # Supports `https://...` and `mailto:...`. + # url: mailto:team@example.com other_links: [] # Package manager URL (optional). Link to the package manager where the item is diff --git a/docs/config/schema/data.schema.json b/docs/config/schema/data.schema.json index 9e467a6c..174d9645 100644 --- a/docs/config/schema/data.schema.json +++ b/docs/config/schema/data.schema.json @@ -451,7 +451,8 @@ "type": "string", "format": "uri", "examples": [ - "https://link.url" + "https://link.url", + "mailto:team@example.com" ] } }, diff --git a/ui/common/src/components/ExternalLink.tsx b/ui/common/src/components/ExternalLink.tsx index e95def22..3c142a84 100644 --- a/ui/common/src/components/ExternalLink.tsx +++ b/ui/common/src/components/ExternalLink.tsx @@ -25,6 +25,10 @@ const LinkClass = css` `; export const ExternalLink = (props: Props) => { + const isMailtoLink = () => /^mailto:/i.test(props.href); + const linkRel = () => (isMailtoLink() ? undefined : 'noopener noreferrer'); + const linkTarget = () => (isMailtoLink() ? undefined : props.target || '_blank'); + const getData = () => { return ( <> @@ -54,7 +58,11 @@ export const ExternalLink = (props: Props) => { if (props.onClick) props.onClick(); if (isUndefined(props.disabled) || !props.disabled) { - window.open(props.href, props.target || '_blank'); + if (isMailtoLink()) { + window.location.href = props.href; + } else { + window.open(props.href, linkTarget()); + } } }} aria-label={props.label || 'Open external link'} @@ -68,8 +76,8 @@ export const ExternalLink = (props: Props) => { title={props.title} class={`link ${LinkClass} ${props.class}`} href={props.href} - target={props.target || '_blank'} - rel="noopener noreferrer" + target={linkTarget()} + rel={linkRel()} onClick={(e) => { e.stopPropagation();