From cdf09930a5bfa09cca6e270bb185bbcffe11c94c Mon Sep 17 00:00:00 2001 From: Florian Dieminger Date: Tue, 10 Dec 2024 10:10:20 +0100 Subject: [PATCH] fix(links): improve fallback for link content A link to not yet published blog post would render as `/`. Now we use the last path segment. --- crates/rari-doc/src/html/links.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/rari-doc/src/html/links.rs b/crates/rari-doc/src/html/links.rs index e5953c63..72a014a0 100644 --- a/crates/rari-doc/src/html/links.rs +++ b/crates/rari-doc/src/html/links.rs @@ -150,7 +150,12 @@ pub fn render_link_via_page( Cow::Borrowed(content) } } - None if url.starts_with('/') => Cow::Borrowed(&url[url.rfind('/').unwrap_or(0)..]), + None if url.starts_with('/') => { + // Fall back to last url path segment. + let clean_url = url.strip_suffix("/").unwrap_or(&url); + let content = &clean_url[clean_url.rfind('/').map(|i| i + 1).unwrap_or(0)..]; + Cow::Borrowed(content) + } _ => html_escape::encode_safe(&url), }; out.push_str(&url);