json-theme-even-fork/components/link.js

17 lines
425 B
JavaScript
Raw Permalink Normal View History

import html from '../utils/html.js'
/**
* @param {string} url
* @returns {string}
*/
const formatURL = url => url.replace(/^(https?:|)\/\//, '').replace(/\/$/, '')
/**
* @param {string} [url]
* @param {string} [name]
* @returns {string | undefined}
*/
export default function Link(url, name) {
return name ? (url ? html`<a href="${url}">${name}</a>` : name) : url && html`<a href="${url}">${formatURL(url)}</a>`
}