« get me outta code hell

content: linkThing: use generateColorStyleAttribute - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-12-31 22:45:51 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-13 19:03:27 -0400
commit5c66e7be6dcbfd7ecbb31b29c8c220d2ed5e0182 (patch)
treef357a46b4ffa79b45e6889140c69efad13eb989b /src/content
parent7ee58f434a5c34c73b60926595f99b83ed869ebf (diff)
content: linkThing: use generateColorStyleAttribute
Diffstat (limited to 'src/content')
-rw-r--r--src/content/dependencies/linkThing.js55
1 files changed, 13 insertions, 42 deletions
diff --git a/src/content/dependencies/linkThing.js b/src/content/dependencies/linkThing.js
index 59780560..2c3b0369 100644
--- a/src/content/dependencies/linkThing.js
+++ b/src/content/dependencies/linkThing.js
@@ -1,18 +1,19 @@
 export default {
-  contentDependencies: ['linkTemplate'],
-  extraDependencies: ['getColors', 'html', 'language'],
+  contentDependencies: ['generateColorStyleAttribute', 'linkTemplate'],
+  extraDependencies: ['html', 'language'],
 
-  relations: (relation) => ({
+  relations: (relation, _pathKey, thing) => ({
     linkTemplate:
       relation('linkTemplate'),
+
+    colorStyle:
+      relation('generateColorStyleAttribute', thing.color ?? null),
   }),
 
   data: (pathKey, thing) => ({
     name: thing.name,
     nameShort: thing.nameShort ?? thing.shortName,
 
-    color: thing.color,
-
     path:
       (pathKey
         ? [pathKey, thing.directory]
@@ -62,7 +63,7 @@ export default {
     hash: {type: 'string'},
   },
 
-  generate(data, relations, slots, {getColors, html, language}) {
+  generate(data, relations, slots, {html, language}) {
     const {attributes} = slots;
 
     const path =
@@ -78,46 +79,16 @@ export default {
         ? language.sanitize(name)
         : slots.content);
 
-    if (slots.color !== false) addColor: {
-      const color =
-        (typeof slots.color === 'string'
-          ? slots.color
-          : data.color);
-
-      if (!color) {
-        break addColor;
-      }
-
-      let selectColors;
-
-      switch (slots.colorContext) {
-        case 'image-box':
-          selectColors = {
-            '--primary-color': 'primary',
-            '--dim-color': 'dim',
-            '--deep-color': 'deep',
-            '--bg-black-color': 'bgBlack',
-          };
-          break;
-
-        case 'primary-only':
-          selectColors = {
-            '--primary-color': 'primary',
-          };
-          break;
-
-        default:
-          break addColor;
-      }
+    if (slots.color !== false) {
+      const {colorStyle} = relations;
 
-      const colors = getColors(color);
-      const selectedColors = [];
+      colorStyle.setSlot('context', slots.colorContext);
 
-      for (const [variable, key] of Object.entries(selectColors)) {
-        selectedColors.push(`${variable}: ${colors[key]}`);
+      if (typeof slots.color === 'string') {
+        colorStyle.setSlot('color', slots.color);
       }
 
-      attributes.add('style', selectedColors);
+      attributes.add(colorStyle);
     }
 
     let tooltip = null;