Skip to content

Commit

Permalink
fix(links): improve fallback for link content
Browse files Browse the repository at this point in the history
A link to not yet published blog post would render as `/`.
Now we use the last path segment.
  • Loading branch information
fiji-flo committed Dec 10, 2024
1 parent 5ccf670 commit cdf0993
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/rari-doc/src/html/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cdf0993

Please sign in to comment.