fix: break long ass links

This commit is contained in:
Alejandro Gómez
2025-12-15 16:53:01 +01:00
parent 6ff877e8a5
commit 001424b611
2 changed files with 37 additions and 3 deletions

View File

@@ -154,6 +154,8 @@ export function MarkdownContent({
content,
canonicalUrl = null,
}: MarkdownContentProps) {
const { addWindow } = useGrimoire();
// Helper to resolve relative URLs using canonical URL as base
const resolveUrl = useMemo(
() =>
@@ -214,7 +216,7 @@ export function MarkdownContent({
/>
);
},
// Handle nostr: links
// Handle links: nostr mentions, NIP links, and regular URLs
a: ({ href, children, ...props }) => {
if (!href) return null;
@@ -223,11 +225,42 @@ export function MarkdownContent({
return <NostrMention href={href} />;
}
// Regular links
// Check if it's a relative NIP link (e.g., "./01.md" or "01.md")
const isRelativeLink =
!href.startsWith("http://") && !href.startsWith("https://");
if (
isRelativeLink &&
(href.endsWith(".md") || href.includes(".md#"))
) {
// Extract NIP number from various formats (numeric 1-3 digits or hex A0-FF)
const nipMatch = href.match(/([0-9A-F]{1,3})\.md/i);
if (nipMatch) {
const nipNumber = nipMatch[1].toUpperCase();
return (
<a
href={`#nip-${nipNumber}`}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
addWindow(
"nip",
{ number: nipNumber },
`NIP ${nipNumber}`,
);
}}
className="text-accent underline decoration-dotted cursor-crosshair hover:text-accent/80"
>
{children}
</a>
);
}
}
// Regular links with break-all for long URLs
return (
<a
href={href}
className="text-accent underline decoration-dotted"
className="text-accent underline decoration-dotted break-all"
target="_blank"
rel="noopener noreferrer"
{...props}

View File

@@ -35,6 +35,7 @@ const kindRenderers: Record<number, React.ComponentType<BaseEventProps>> = {
7: Kind7Renderer, // Reaction
9: Kind9Renderer, // Chat Message (NIP-C7)
16: RepostRenderer, // Generic Repost
17: Kind7Renderer, // Reaction (NIP-25)
20: Kind20Renderer, // Picture (NIP-68)
21: Kind21Renderer, // Video Event (NIP-71)
22: Kind22Renderer, // Short Video (NIP-71)