From f5ec083cdcedd8aa50ba5e065805a709f59178b9 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 31 Mar 2021 11:13:25 -0300 Subject: expose link track directory via data attribute --- upd8.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/upd8.js b/upd8.js index 56fae24..a52542a 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 = '' - }) => `${text || thing.name}`; + }) => ( + `${text || thing.name}` + ); + +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}), -- cgit 1.3.0-6-gf8a5