17 lines
425 B
JavaScript
17 lines
425 B
JavaScript
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>`
|
|
}
|