diff --git a/src/hooks/useLinks.hook.ts b/src/hooks/useLinks.hook.ts index bed2cfd..e424323 100644 --- a/src/hooks/useLinks.hook.ts +++ b/src/hooks/useLinks.hook.ts @@ -38,6 +38,22 @@ export const useLinks = (className: string, sha?: string) => { removeListeners() const elements = document.querySelectorAll(selector) + elements.forEach((element) => { + const href = element.getAttribute('href') + + if (!href) { + return + } + + const isExternalLink = + LINKS.some((link) => href.startsWith(link)) && + !href.startsWith(location.origin) + + if (isExternalLink) { + element.classList.add('external-link') + } + }) + elements.forEach((element) => { element.addEventListener('click', linkNote) }) diff --git a/src/styles/app.scss b/src/styles/app.scss index 79abc51..6b09415 100644 --- a/src/styles/app.scss +++ b/src/styles/app.scss @@ -39,3 +39,7 @@ body { height: 100vh; display: flex; } + +a.external-link { + text-decoration: underline; +}