UNPKG

@gouvfr/dsfr-roller

Version:

Le module `dsfr-roller` permet de publier le site de documentation du Système de Design de l’État - DSFR

17 lines (16 loc) 537 B
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; };