« get me outta code hell

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:
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}),