| 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 siteHost = () => { |
| 5 |
try { |
| 6 |
return new URL(window.extSharedData?.homeUrl ?? '').host; |
| 7 |
} catch { |
| 8 |
return ''; |
| 9 |
} |
| 10 |
}; |
| 11 |
|
| 12 |
export const resolveNotificationLink = (notification, host = '') => { |
| 13 |
const href = withSiteHost(notification?.link, host); |
| 14 |
if (!href) return {}; |
| 15 |
try { |
| 16 |
return { href, external: new URL(href).host !== host }; |
| 17 |
} catch { |
| 18 |
// URL() throws on relative paths, which are never external. |
| 19 |
return { href }; |
| 20 |
} |
| 21 |
}; |
| 22 |
|
| 23 |
// `rel` travels with `target`, or the new tab keeps a handle back to wp-admin. |
| 24 |
export const externalLinkProps = (external) => |
| 25 |
external ? { target: '_blank', rel: 'noreferrer' } : {}; |
| 26 |
|