« get me outta code hell

expose link track directory via data attribute - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/upd8.js
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-03-31 11:13:25 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-03-31 11:13:25 -0300
commitf5ec083cdcedd8aa50ba5e065805a709f59178b9 (patch)
tree9b318a4edbfba9a60b2432d3be89253a2d56d8bc /upd8.js
parent50f7934cf32ff09b271b91c98e0439b9eb8a5294 (diff)
expose link track directory via data attribute
Diffstat (limited to 'upd8.js')
-rwxr-xr-xupd8.js25
1 files changed, 18 insertions, 7 deletions
diff --git a/upd8.js b/upd8.js
index 56fae24b..a52542a2 100755
--- a/upd8.js
+++ b/upd8.js
@@ -234,18 +234,29 @@ const urlSpec = {
     }
 };
 
-const linkHelper = (hrefFn, {color = true} = {}) =>
+const linkHelper = (hrefFn, {color = true, attr = null} = {}) =>
     (thing, {
         strings, to,
         text = '',
         class: className = '',
         hash = ''
-    }) => `<a href="${hrefFn(thing, {to}) + (hash ? (hash.startsWith('#') ? '' : '#') + hash : '')}" ${attributes({
-        style: color ? getLinkThemeString(thing) : '',
-        class: className
-    })}>${text || thing.name}</a>`;
+    }) => (
+        `<a href="${hrefFn(thing, {to}) + (hash ? (hash.startsWith('#') ? '' : '#') + hash : '')}" ${attributes({
+            ...attr ? attr(thing) : {},
+            style: color ? getLinkThemeString(thing) : '',
+            class: className
+        })}>${text || thing.name}</a>`
+    );
+
+const linkDirectory = (key, {expose = null, attr = null, ...conf} = {}) =>
+    linkHelper((thing, {to}) => to[key](thing.directory), {
+        attr: thing => ({
+            ...attr ? attr(thing) : {},
+            ...expose ? {[expose]: thing.directory} : {}
+        }),
+        ...conf
+    });
 
-const linkDirectory = (key, conf) => linkHelper(({directory}, {to}) => to[key](directory), conf);
 const linkPathname = (key, conf) => linkHelper((pathname, {to}) => to[key](pathname), conf);
 const linkIndex = (key, conf) => linkHelper((_, {to}) => to[key](''), conf);
 
@@ -266,7 +277,7 @@ const link = {
     newsEntry: linkDirectory('newsEntry', {color: false}),
     staticPage: linkDirectory('staticPage', {color: false}),
     tag: linkDirectory('tag'),
-    track: linkDirectory('track'),
+    track: linkDirectory('track', {expose: 'data-track'}),
 
     media: linkPathname('media', {color: false}),
     root: linkPathname('root', {color: false}),