parent
c5e2eeee2d
commit
ea58242b85
|
@ -87,6 +87,7 @@
|
|||
import { store } from '../../_store/store'
|
||||
import { classname } from '../../_utils/classname'
|
||||
import { massageUserText } from '../../_utils/massageUserText'
|
||||
import { urlIsCrossOrigin } from '../../_utils/urlIsCrossOrigin'
|
||||
|
||||
export default {
|
||||
oncreate () {
|
||||
|
@ -141,7 +142,7 @@
|
|||
}
|
||||
// hydrate external links
|
||||
const href = anchor.getAttribute('href')
|
||||
if (new URL(href, location.href).origin !== location.origin) {
|
||||
if (urlIsCrossOrigin(href)) {
|
||||
anchor.setAttribute('title', href)
|
||||
anchor.setAttribute('target', '_blank')
|
||||
anchor.setAttribute('rel', 'nofollow noopener')
|
||||
|
|
8
src/routes/_utils/urlIsCrossOrigin.js
Normal file
8
src/routes/_utils/urlIsCrossOrigin.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
export function urlIsCrossOrigin (href) {
|
||||
try {
|
||||
return new URL(href, location.href).origin !== location.origin
|
||||
} catch (e) {
|
||||
console.error('Ignoring malformed URL', href)
|
||||
return true
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue