pleshevski.ru/views/uikit/link.ts
Dmitriy Pleshevskiy b24e460ec7
All checks were successful
continuous-integration/drone/push Build is passing
add works from github
2022-06-22 00:36:11 +03:00

26 lines
670 B
TypeScript

import { AnyNode, Attrs, E } from "ren/node.ts";
export function RepoLink(name: string, repo: string): AnyNode {
const gitBase = new URL("https://git.pleshevski.ru");
return Link(name, { href: new URL(repo, gitBase).toString() });
}
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",
});
}
return E("a", attrs, text);
}