diff --git a/src/esa-utils/external-link-replacer.ts b/src/esa-utils/external-link-replacer.ts index 46ef1c2..e10fb04 100644 --- a/src/esa-utils/external-link-replacer.ts +++ b/src/esa-utils/external-link-replacer.ts @@ -6,14 +6,23 @@ function isExternalLink(href: string): boolean { /** * @see https://docs.astro.build/ja/guides/environment-variables/ */ - if (href.startsWith(import.meta.env.SITE)) { + if (href.startsWith(import.meta.env.SITE) || href.startsWith("/")) { return false; } return true; } +function isZDKLink(href: string): boolean { + const prefixes = [ + "https://www.zdk.tsukuba.ac.jp/", + "https://www.stb.tsukuba.ac.jp/~zdk/", + ]; + return prefixes.some((prefix) => href.startsWith(prefix)); +} + export function externalLinkReplacer() { const externalLinkNodes: AnchorNode[] = []; + const noZdkLinkNodes: AnchorNode[] = []; return async (tree: Node) => { visit(tree, (node) => { if (isAnchor(node)) { @@ -21,6 +30,9 @@ export function externalLinkReplacer() { if (isExternalLink(properties.href)) { externalLinkNodes.push(node); } + if (!isZDKLink(properties.href)) { + noZdkLinkNodes.push(node); + } } }); @@ -28,5 +40,9 @@ export function externalLinkReplacer() { const { properties } = node; properties.target = "_blank"; } + for (const node of noZdkLinkNodes) { + const { properties } = node; + properties.rel = "noopener nofollow"; + } }; }