Compare commits

...

1 Commits

Author SHA1 Message Date
Philipinho f010f6a83a fix: internal links 2026-05-21 17:01:20 +01:00
@@ -17,15 +17,27 @@ import ChatToolGroup from "./chat-tool-group";
import classes from "../styles/chat-message.module.css"; import classes from "../styles/chat-message.module.css";
import CopyTextButton from "@/components/common/copy.tsx"; import CopyTextButton from "@/components/common/copy.tsx";
const PAGE_PATH_RE = /\/s\/[^/?#]+\/p\/[^/?#]+/;
const chatSanitizer = DOMPurify(); const chatSanitizer = DOMPurify();
chatSanitizer.addHook("afterSanitizeAttributes", (node) => { chatSanitizer.addHook("afterSanitizeAttributes", (node) => {
if (node.tagName === "A") { if (node.tagName !== "A") return;
const href = node.getAttribute("href") || ""; const href = node.getAttribute("href") || "";
// Recover the canonical /s/{slug}/p/{slugId} path if the model wrapped it
// in a fabricated host (https://s/..., https://yoursite.com/s/..., //s/...).
const m = href.match(PAGE_PATH_RE);
if (m) {
node.setAttribute("href", m[0]);
node.removeAttribute("target");
node.removeAttribute("rel");
return;
}
if (href.startsWith("http://") || href.startsWith("https://")) { if (href.startsWith("http://") || href.startsWith("https://")) {
node.setAttribute("target", "_blank"); node.setAttribute("target", "_blank");
node.setAttribute("rel", "noopener noreferrer"); node.setAttribute("rel", "noopener noreferrer");
} }
}
}); });
const IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "webp", "gif"]; const IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "webp", "gif"];