« get me outta code hell

content: cut html.template boilerplate - 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-06-12 16:35:38 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-12 16:35:38 -0300
commit535acb34613b5cf7e22654619f4337b94b70644d (patch)
tree5a713eb4f12eae7e1fe1aa60941709708585db32 /src/content/dependencies/linkTemplate.js
parent630af0a345f3be6c3e4aa3300ce138e48ed5ae91 (diff)
content: cut html.template boilerplate
Diffstat (limited to 'src/content/dependencies/linkTemplate.js')
-rw-r--r--src/content/dependencies/linkTemplate.js92
1 files changed, 43 insertions, 49 deletions
diff --git a/src/content/dependencies/linkTemplate.js b/src/content/dependencies/linkTemplate.js
index 9109ab5..98e2c8b 100644
--- a/src/content/dependencies/linkTemplate.js
+++ b/src/content/dependencies/linkTemplate.js
@@ -8,66 +8,60 @@ export default {
     'to',
   ],
 
-  generate({
+  slots: {
+    href: {type: 'string'},
+    path: {validate: v => v.validateArrayItems(v.isString)},
+    hash: {type: 'string'},
+
+    tooltip: {validate: v => v.isString},
+    attributes: {validate: v => v.isAttributes},
+    color: {validate: v => v.isColor},
+    content: {type: 'html'},
+  },
+
+  generate(slots, {
     appendIndexHTML,
     getColors,
     html,
     to,
   }) {
-    return html.template({
-      annotation: 'linkTemplate',
-
-      slots: {
-        href: {type: 'string'},
-        path: {validate: v => v.validateArrayItems(v.isString)},
-        hash: {type: 'string'},
-
-        tooltip: {validate: v => v.isString},
-        attributes: {validate: v => v.isAttributes},
-        color: {validate: v => v.isColor},
-        content: {type: 'html'},
-      },
-
-      content(slots) {
-        let href = slots.href;
-        let style;
-        let title;
+    let href = slots.href;
+    let style;
+    let title;
 
-        if (!href && !empty(slots.path)) {
-          href = to(...slots.path);
-        }
+    if (!href && !empty(slots.path)) {
+      href = to(...slots.path);
+    }
 
-        if (appendIndexHTML) {
-          if (
-            /^(?!https?:\/\/).+\/$/.test(href) &&
-            href.endsWith('/')
-          ) {
-            href += 'index.html';
-          }
-        }
+    if (appendIndexHTML) {
+      if (
+        /^(?!https?:\/\/).+\/$/.test(href) &&
+        href.endsWith('/')
+      ) {
+        href += 'index.html';
+      }
+    }
 
-        if (slots.hash) {
-          href += (slots.hash.startsWith('#') ? '' : '#') + slots.hash;
-        }
+    if (slots.hash) {
+      href += (slots.hash.startsWith('#') ? '' : '#') + slots.hash;
+    }
 
-        if (slots.color) {
-          const {primary, dim} = getColors(slots.color);
-          style = `--primary-color: ${primary}; --dim-color: ${dim}`;
-        }
+    if (slots.color) {
+      const {primary, dim} = getColors(slots.color);
+      style = `--primary-color: ${primary}; --dim-color: ${dim}`;
+    }
 
-        if (slots.tooltip) {
-          title = slots.tooltip;
-        }
+    if (slots.tooltip) {
+      title = slots.tooltip;
+    }
 
-        return html.tag('a',
-          {
-            ...slots.attributes ?? {},
-            href,
-            style,
-            title,
-          },
-          slots.content);
+    return html.tag('a',
+      {
+        ...slots.attributes ?? {},
+        href,
+        style,
+        title,
       },
-    });
+      slots.content);
   },
 }