| 1 |
// A partner-authored link can't know the customer's host at authoring time. |
| 2 |
const withSiteHost = (link, host) => link?.replaceAll('{SITEURL}', host); |
| 3 |
|
| 4 |
export const resolveNotificationLink = (notification, host = '') => { |
| 5 |
const href = withSiteHost(notification?.link, host); |
| 6 |
if (!href) return {}; |
| 7 |
try { |
| 8 |
return { href, external: new URL(href).host !== host }; |
| 9 |
} catch { |
| 10 |
// URL() throws on relative paths, which are never external. |
| 11 |
return { href }; |
| 12 |
} |
| 13 |
}; |
| 14 |
|
| 15 |
// `rel` travels with `target`, or the new tab keeps a handle back to wp-admin. |
| 16 |
export const externalLinkProps = (external) => |
| 17 |
external ? { target: '_blank', rel: 'noreferrer' } : {}; |
| 18 |
|