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) {
|
2023-10-08 01:23:03 +02:00
|
|
|
return name ? (url ? html`<a href="${url}">${name}</a>` : name) : url && html`<a href="${url}">${formatURL(url)}</a>`
|
2023-01-30 02:38:45 +01:00
|
|
|
}
|