2022-06-08 23:24:19 +03:00
|
|
|
import { AnyNode, Attrs, E } from "ren/node.ts";
|
|
|
|
|
2022-06-22 00:35:55 +03:00
|
|
|
export function Link(
|
|
|
|
text: string,
|
|
|
|
sourceAttrs: Attrs | Attrs[],
|
|
|
|
): AnyNode {
|
|
|
|
const attrs = Array.isArray(sourceAttrs) ? sourceAttrs : [sourceAttrs];
|
|
|
|
const isExternal = attrs.some((attr) =>
|
|
|
|
typeof attr.href === "string" && attr.href?.startsWith("http")
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isExternal) {
|
|
|
|
attrs.push({
|
|
|
|
target: "_blank",
|
|
|
|
rel: "external nofollow noopener noreferrer",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:24:19 +03:00
|
|
|
return E("a", attrs, text);
|
|
|
|
}
|