« 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/linkTemplate.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/linkTemplate.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/linkTemplate.js')
-rw-r--r--src/content/dependencies/linkTemplate.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/content/dependencies/linkTemplate.js b/src/content/dependencies/linkTemplate.js
new file mode 100644
index 0000000..94b9065
--- /dev/null
+++ b/src/content/dependencies/linkTemplate.js
@@ -0,0 +1,53 @@
+import {empty} from '../../util/sugar.js';
+
+export default {
+  extraDependencies: [
+    'appendIndexHTML',
+    'getColors',
+    'html',
+    'to',
+  ],
+
+  generate({
+    appendIndexHTML,
+    getColors,
+    html,
+    to,
+  }) {
+    return html.template(slot =>
+      slot('color', ([color]) =>
+      slot('hash', ([hash]) =>
+      slot('href', ([href]) =>
+      slot('path', ([...path]) => {
+        let style;
+
+        if (!href && !empty(path)) {
+          href = to(...path);
+        }
+
+        if (appendIndexHTML) {
+          if (/^(?!https?:\/\/).+\/$/.test(href)) {
+            href += 'index.html';
+          }
+        }
+
+        if (hash) {
+          href += (hash.startsWith('#') ? '' : '#') + hash;
+        }
+
+        if (color) {
+          const {primary, dim} = getColors(color);
+          style = `--primary-color: ${primary}; --dim-color: ${dim}`;
+        }
+
+        return slot('attributes', ([attributes]) =>
+          html.tag('a',
+            {
+              ...attributes ?? {},
+              href,
+              style,
+            },
+            slot('content')));
+      })))));
+  },
+}