From 51b04c86147f1405c33829cc339b8c045dcafc4f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 30 Dec 2023 10:14:17 -0400 Subject: content: various higher-level attribute processing cleanup --- src/content/dependencies/linkTemplate.js | 52 ++++++++++++-------------------- 1 file changed, 19 insertions(+), 33 deletions(-) (limited to 'src/content/dependencies/linkTemplate.js') diff --git a/src/content/dependencies/linkTemplate.js b/src/content/dependencies/linkTemplate.js index a361a4e7..f3744bdf 100644 --- a/src/content/dependencies/linkTemplate.js +++ b/src/content/dependencies/linkTemplate.js @@ -30,26 +30,18 @@ export default { language, to, }) { - let href; - let style; - let title; + const attributes = html.attributes(); - if (slots.linkless) { - href = null; - } else { - if (slots.href) { - href = encodeURI(slots.href); - } else if (!empty(slots.path)) { - href = to(...slots.path); - } else { - href = ''; - } + if (!slots.linkless) { + let href = + (slots.href + ? encodeURI(slots.href) + : !empty(slots.path) + ? to(...slots.path) + : ''); if (appendIndexHTML) { - if ( - /^(?!https?:\/\/).+\/$/.test(href) && - href.endsWith('/') - ) { + if (/^(?!https?:\/\/).+\/$/.test(href) && href.endsWith('/')) { href += 'index.html'; } } @@ -57,23 +49,18 @@ export default { if (slots.hash) { href += (slots.hash.startsWith('#') ? '' : '#') + slots.hash; } + + attributes.add({href}); } if (slots.color) { const {primary, dim} = getColors(slots.color); - style = `--primary-color: ${primary}; --dim-color: ${dim}`; - } - - if (slots.attributes?.style) { - if (style) { - style += '; ' + slots.attributes.style; - } else { - style = slots.attributes.style; - } + attributes.set('style', + `--primary-color: ${primary}; --dim-color: ${dim}`); } if (slots.tooltip) { - title = slots.tooltip; + attributes.set('title', slots.tooltip); } const content = @@ -83,11 +70,10 @@ export default { disallowedTags: new Set(['a']), })); - return html.tag('a', { - ...slots.attributes ?? {}, - href, - style, - title, - }, content); + return ( + html.tag('a', + attributes, + slots.attributes, + content)); }, } -- cgit 1.3.0-6-gf8a5