« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/content/dependencies/linkThing.js124
1 files changed, 61 insertions, 63 deletions
diff --git a/src/content/dependencies/linkThing.js b/src/content/dependencies/linkThing.js
index 4ccdf58d..03aa9836 100644
--- a/src/content/dependencies/linkThing.js
+++ b/src/content/dependencies/linkThing.js
@@ -25,70 +25,68 @@ export default {
     };
   },
 
-  generate(data, relations, {html}) {
+  slots: {
+    // content: relations.linkTemplate.getSlotDescription('content'),
+    content: {type: 'html'},
+
+    preferShortName: {type: 'boolean', default: false},
+
+    tooltip: {
+      validate: v => v.oneOf(v.isBoolean, v.isString),
+      default: false,
+    },
+
+    color: {
+      validate: v => v.oneOf(v.isBoolean, v.isColor),
+      default: true,
+    },
+
+    anchor: {type: 'boolean', default: false},
+
+    // attributes: relations.linkTemplate.getSlotDescription('attributes'),
+    // hash: relations.linkTemplate.getSlotDescription('hash'),
+    attributes: {validate: v => v.isAttributes},
+    hash: {type: 'string'},
+  },
+
+  generate(data, relations, slots, {html}) {
     const path = [data.pathKey, data.directory];
 
-    return html.template({
-      annotation: 'linkThing',
-
-      slots: {
-        content: relations.linkTemplate.getSlotDescription('content'),
-        preferShortName: {type: 'boolean', default: false},
-
-        tooltip: {
-          validate: v => v.oneOf(v.isBoolean, v.isString),
-          default: false,
-        },
-
-        color: {
-          validate: v => v.oneOf(v.isBoolean, v.isColor),
-          default: true,
-        },
-
-        anchor: {type: 'boolean', default: false},
-
-        attributes: relations.linkTemplate.getSlotDescription('attributes'),
-        hash: relations.linkTemplate.getSlotDescription('hash'),
-      },
-
-      content(slots) {
-        let content = slots.content;
-
-        const name =
-          (slots.preferShortName
-            ? data.nameShort ?? data.name
-            : data.name);
-
-        if (html.isBlank(content)) {
-          content = name;
-        }
-
-        let color = null;
-        if (slots.color === true) {
-          color = data.color ?? null;
-        } else if (typeof slots.color === 'string') {
-          color = slots.color;
-        }
-
-        let tooltip = null;
-        if (slots.tooltip === true) {
-          tooltip = name;
-        } else if (typeof slots.tooltip === 'string') {
-          tooltip = slots.tooltip;
-        }
-
-        return relations.linkTemplate
-          .slots({
-            path: slots.anchor ? [] : path,
-            href: slots.anchor ? '' : null,
-            content,
-            color,
-            tooltip,
-
-            attributes: slots.attributes,
-            hash: slots.hash,
-          });
-      },
-    });
+    let content = slots.content;
+
+    const name =
+      (slots.preferShortName
+        ? data.nameShort ?? data.name
+        : data.name);
+
+    if (html.isBlank(content)) {
+      content = name;
+    }
+
+    let color = null;
+    if (slots.color === true) {
+      color = data.color ?? null;
+    } else if (typeof slots.color === 'string') {
+      color = slots.color;
+    }
+
+    let tooltip = null;
+    if (slots.tooltip === true) {
+      tooltip = name;
+    } else if (typeof slots.tooltip === 'string') {
+      tooltip = slots.tooltip;
+    }
+
+    return relations.linkTemplate
+      .slots({
+        path: slots.anchor ? [] : path,
+        href: slots.anchor ? '' : null,
+        content,
+        color,
+        tooltip,
+
+        attributes: slots.attributes,
+        hash: slots.hash,
+      });
   },
 }