File "notification-link.js"

Full Path: /home/exogold/public_html/wp-content/plugins/extendify/src/Notifications/notification-link.js
File size: 649 bytes
MIME-type: text/plain
Charset: utf-8

// A partner-authored link can't know the customer's host at authoring time.
const withSiteHost = (link, host) => link?.replaceAll('{SITEURL}', host);

export const resolveNotificationLink = (notification, host = '') => {
	const href = withSiteHost(notification?.link, host);
	if (!href) return {};
	try {
		return { href, external: new URL(href).host !== host };
	} catch {
		// URL() throws on relative paths, which are never external.
		return { href };
	}
};

// `rel` travels with `target`, or the new tab keeps a handle back to wp-admin.
export const externalLinkProps = (external) =>
	external ? { target: '_blank', rel: 'noreferrer' } : {};