export const formatLink = (link) => {
  if (!link) return undefined;
  const url = link.url ?? link.href;
  const segments = url && url.split('/');
  if (segments) link.id = link.id ?? `link-${segments.join('-')}`;
  if (/^(https:|http:|www\.)\S*$/.test(url)) link.blank = true;
  link.href = url;
  link.label = link.label ?? link.text;
  link.attributes = link.attributes || {};
  if (link.blank) {
    const title = `${link.label} - ${link.blankTitle}`
    link.attributes.title = title;
    link.title = title;
  }
  return link;
};
