💄 (link) underline external links.
This commit is contained in:
@@ -38,6 +38,22 @@ export const useLinks = (className: string, sha?: string) => {
|
|||||||
removeListeners()
|
removeListeners()
|
||||||
const elements = document.querySelectorAll(selector)
|
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) => {
|
elements.forEach((element) => {
|
||||||
element.addEventListener('click', linkNote)
|
element.addEventListener('click', linkNote)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -39,3 +39,7 @@ body {
|
|||||||
height: 100vh;
|
height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.external-link {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user