Link not found
++ This short link may have expired or never existed. +
+ + Return to Prabhupāda Says → + ++ This short link may have expired or never existed. +
+ + Return to Prabhupāda Says → + ++ Redirecting to your highlight… +
+ +- {opt.key === "link" && copied ? "Link Copied!" : opt.label} + {linkLabel(opt.key, opt.label)}
{opt.description}
- {opt.key === "link" && copied ? "Link Copied!" : opt.label} + {linkLabel(opt.key, opt.label)}
{opt.description}
` page resolves
+ * back to the same `?hl=…` URL the existing TextHighlighter already knows
+ * how to process — no change to highlighting behavior.
+ *
+ * Falls back to the long URL on any failure so sharing never silently breaks.
+ *
+ * `buildHighlightUrl` (sync) is intentionally left in place so other callers
+ * (e.g. search-result navigation) keep working unchanged.
+ */
+export async function buildShortHighlightUrl(
+ selectedText: string,
+): Promise {
+ const longUrl = buildHighlightUrl(selectedText);
+ let u: URL;
+ try {
+ u = new URL(longUrl);
+ } catch {
+ return longUrl;
+ }
+ const relativePath = u.pathname + u.search + u.hash;
+
+ const { createShortLink } = await import("@/lib/share");
+ const code = await createShortLink(relativePath);
+ if (!code) return longUrl;
+
+ return new URL(`/share/${code}`, u.origin).toString();
+}
+
/**
* Find and highlight text in the DOM that matches a decoded text fragment.
* Returns true if found and highlighted.