2023-01-30 02:38:45 +01:00
|
|
|
import html from '../utils/html.js'
|
|
|
|
|
2023-09-28 02:50:43 +02:00
|
|
|
/**
|
|
|
|
* @param {string} url
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2023-01-30 02:38:45 +01:00
|
|
|
const formatURL = url => url.replace(/^(https?:|)\/\//, '').replace(/\/$/, '')
|
|
|
|
|
2023-09-28 02:50:43 +02:00
|
|
|
/**
|
|
|
|
* @param {string} [url]
|
|
|
|
* @param {string} [name]
|
|
|
|
* @returns {string | undefined}
|
|
|
|
*/
|
2023-01-30 02:38:45 +01:00
|
|
|
export default function Link(url, name) {
|
|
|
|
return name
|
|
|
|
? (url ? html`<a href="${url}">${name}</a>` : name)
|
|
|
|
: url && html`<a href="${url}">${formatURL(url)}</a>`
|
|
|
|
}
|