parent
c5e2eeee2d
commit
ea58242b85
|
@ -87,6 +87,7 @@
|
||||||
import { store } from '../../_store/store'
|
import { store } from '../../_store/store'
|
||||||
import { classname } from '../../_utils/classname'
|
import { classname } from '../../_utils/classname'
|
||||||
import { massageUserText } from '../../_utils/massageUserText'
|
import { massageUserText } from '../../_utils/massageUserText'
|
||||||
|
import { urlIsCrossOrigin } from '../../_utils/urlIsCrossOrigin'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
oncreate () {
|
oncreate () {
|
||||||
|
@ -141,7 +142,7 @@
|
||||||
}
|
}
|
||||||
// hydrate external links
|
// hydrate external links
|
||||||
const href = anchor.getAttribute('href')
|
const href = anchor.getAttribute('href')
|
||||||
if (new URL(href, location.href).origin !== location.origin) {
|
if (urlIsCrossOrigin(href)) {
|
||||||
anchor.setAttribute('title', href)
|
anchor.setAttribute('title', href)
|
||||||
anchor.setAttribute('target', '_blank')
|
anchor.setAttribute('target', '_blank')
|
||||||
anchor.setAttribute('rel', 'nofollow noopener')
|
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