« get me outta code hell

data steps: content function evaluation essentials - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/linkThing.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-03-23 15:00:59 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-03-23 15:01:16 -0300
commit8ab00d99fa2f14ac983f0693552b26e4050a939c (patch)
tree1d75c569eec9472c95b24f5072d8d145bf709ee3 /src/content/dependencies/linkThing.js
parent95465bae3aaa92cb617c873bcbbfe8906bea7506 (diff)
data steps: content function evaluation essentials
Also some more actual content in generateAlbumInfoPageContent,
which is in fact fully working as-is(!!).
Diffstat (limited to 'src/content/dependencies/linkThing.js')
-rw-r--r--src/content/dependencies/linkThing.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/content/dependencies/linkThing.js b/src/content/dependencies/linkThing.js
new file mode 100644
index 00000000..ebff6761
--- /dev/null
+++ b/src/content/dependencies/linkThing.js
@@ -0,0 +1,51 @@
+import {empty} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: [
+    'linkTemplate',
+  ],
+
+  extraDependencies: [
+    'html',
+  ],
+
+  relations(relation) {
+    return {
+      linkTemplate: relation('linkTemplate'),
+    };
+  },
+
+  data(pathKey, thing) {
+    return {
+      pathKey,
+
+      color: thing.color,
+      directory: thing.directory,
+
+      name: thing.name,
+      nameShort: thing.nameShort,
+    };
+  },
+
+  generate(data, relations, {html}) {
+    const path = [data.pathKey, data.directory];
+
+    return html.template(slot =>
+      slot('content', ([...content]) =>
+      slot('preferShortName', ([preferShortName]) => {
+        if (empty(content)) {
+          content =
+            (preferShortName
+              ? data.nameShort ?? data.name
+              : data.name);
+        }
+
+        return relations.linkTemplate
+          .slot('path', path)
+          .slot('color', slot('color', data.color))
+          .slot('attributes', slot('attributes', {}))
+          .slot('hash', slot('hash'))
+          .slot('content', content);
+      })));
+  },
+}