Files
kopyl.dev.v2/rehype/external-links.js
Anatoly Kopyl 8f819f3ab1
All checks were successful
Deploy / build-and-publish (push) Successful in 1m22s
Deploy / deploy (push) Successful in 14s
External links
2024-10-05 00:34:31 +03:00

18 lines
418 B
JavaScript

import {visit} from 'unist-util-visit'
export default () => {
return (tree) => {
visit(tree, 'element', function (node) {
if (
node.tagName === 'a' &&
typeof node.properties.href === 'string'
) {
const url = node.properties.href
if (url.startsWith('http://') || url.startsWith('https://')) {
node.properties.target = '_blank'
}
}
})
}
}