💄 (link) underline external links.

This commit is contained in:
Julien Calixte
2021-03-21 11:14:35 +01:00
parent 4a812e78dc
commit b2721763ac
2 changed files with 20 additions and 0 deletions

View File

@@ -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)
})