« get me outta code hell

content: various higher-level attribute processing cleanup - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/linkTemplate.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-12-30 10:14:17 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-12-30 16:26:36 -0400
commit51b04c86147f1405c33829cc339b8c045dcafc4f (patch)
tree961c2f22c13065e910441e7d87b95d1d6d0c68b5 /src/content/dependencies/linkTemplate.js
parent3fb01a3022a3f47c0e1e6e76771a35fce23a128b (diff)
content: various higher-level attribute processing cleanup
Diffstat (limited to 'src/content/dependencies/linkTemplate.js')
-rw-r--r--src/content/dependencies/linkTemplate.js52
1 files changed, 19 insertions, 33 deletions
diff --git a/src/content/dependencies/linkTemplate.js b/src/content/dependencies/linkTemplate.js
index a361a4e..f3744bd 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));
   },
 }