« get me outta code hell

refactor/tweak getGridHTML to use link() fns - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2021-12-31 21:16:59 -0400
committer(quasar) nebula <qznebula@protonmail.com>2021-12-31 21:16:59 -0400
commit5b1418b417c2bac641a8671e7da5cf02aefa6245 (patch)
treedba642ee9fbcb6d4e8707c007c0962e8621f946c
parent7710fc578ec94bb9edca551e7d38ab30d8560ecf (diff)
refactor/tweak getGridHTML to use link() fns
-rw-r--r--src/misc-templates.js42
-rw-r--r--src/page/artist.js6
-rw-r--r--src/page/tag.js6
-rwxr-xr-xsrc/upd8.js7
4 files changed, 29 insertions, 32 deletions
diff --git a/src/misc-templates.js b/src/misc-templates.js
index a6b39b99..e787184c 100644
--- a/src/misc-templates.js
+++ b/src/misc-templates.js
@@ -270,45 +270,42 @@ export function iconifyURL(url, {strings, to}) {
 // Grids
 
 export function getGridHTML({
-    getLinkThemeString,
     img,
     strings,
 
     entries,
     srcFn,
-    hrefFn,
+    linkFn,
     altFn = () => '',
     detailsFn = null,
     lazy = true
 }) {
-    return entries.map(({ large, item }, i) => html.tag('a',
+    return entries.map(({ large, item }, i) => linkFn(item,
         {
             class: ['grid-item', 'box', large && 'large-grid-item'],
-            href: hrefFn(item),
-            style: getLinkThemeString(item.color)
-        },
-        fixWS`
-            ${img({
-                src: srcFn(item),
-                alt: altFn(item),
-                thumb: 'small',
-                lazy: (typeof lazy === 'number' ? i >= lazy : lazy),
-                square: true,
-                reveal: getRevealStringFromTags(item.artTags, {strings})
-            })}
-            <span>${item.name}</span>
-            ${detailsFn && `<span>${detailsFn(item)}</span>`}
-        `)).join('\n');
+            text: fixWS`
+                ${img({
+                    src: srcFn(item),
+                    alt: altFn(item),
+                    thumb: 'small',
+                    lazy: (typeof lazy === 'number' ? i >= lazy : lazy),
+                    square: true,
+                    reveal: getRevealStringFromTags(item.artTags, {strings})
+                })}
+                <span>${item.name}</span>
+                ${detailsFn && `<span>${detailsFn(item)}</span>`}
+            `
+        })).join('\n');
 }
 
 export function getAlbumGridHTML({
-    getAlbumCover, getGridHTML, strings, to,
+    getAlbumCover, getGridHTML, link, strings,
     details = false,
     ...props
 }) {
     return getGridHTML({
         srcFn: getAlbumCover,
-        hrefFn: album => to('localized.album', album.directory),
+        linkFn: link.album,
         detailsFn: details && (album => strings('misc.albumGridDetails', {
             tracks: strings.count.tracks(album.tracks.length, {unit: true}),
             time: strings.count.duration(getTotalDuration(album.tracks))
@@ -318,15 +315,16 @@ export function getAlbumGridHTML({
 }
 
 export function getFlashGridHTML({
-    getFlashCover, getGridHTML, to,
+    getFlashCover, getGridHTML, link,
     ...props
 }) {
     return getGridHTML({
         srcFn: getFlashCover,
-        hrefFn: flash => to('localized.flash', flash.directory),
+        linkFn: link.flash,
         ...props
     });
 }
+
 // Nav-bar links
 
 export function generateInfoGalleryLinks(currentThing, isGallery, {
diff --git a/src/page/artist.js b/src/page/artist.js
index 2e87669d..e6160be3 100644
--- a/src/page/artist.js
+++ b/src/page/artist.js
@@ -452,9 +452,9 @@ export function write(artist, {wikiData}) {
                             srcFn: thing => (thing.album
                                 ? getTrackCover(thing)
                                 : getAlbumCover(thing)),
-                            hrefFn: thing => (thing.album
-                                ? to('localized.track', thing.directory)
-                                : to('localized.album', thing.directory))
+                            linkFn: (thing, opts) => (thing.album
+                                ? link.track(thing, opts)
+                                : link.album(thing, opts))
                         })}
                     </div>
                 `
diff --git a/src/page/tag.js b/src/page/tag.js
index 4253120e..791c713d 100644
--- a/src/page/tag.js
+++ b/src/page/tag.js
@@ -53,9 +53,9 @@ export function write(tag, {wikiData}) {
                             srcFn: thing => (thing.album
                                 ? getTrackCover(thing)
                                 : getAlbumCover(thing)),
-                            hrefFn: thing => (thing.album
-                                ? to('localized.track', thing.directory)
-                                : to('localized.album', thing.directory))
+                            linkFn: (thing, opts) => (thing.album
+                                ? link.track(thing, opts)
+                                : link.album(thing, opts))
                         })}
                     </div>
                 `
diff --git a/src/upd8.js b/src/upd8.js
index 91cc66df..b31505d3 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -3059,7 +3059,6 @@ async function main() {
 
                 bound.getGridHTML = bindOpts(getGridHTML, {
                     [bindOpts.bindIndex]: 0,
-                    getLinkThemeString,
                     img,
                     strings
                 });
@@ -3068,15 +3067,15 @@ async function main() {
                     [bindOpts.bindIndex]: 0,
                     getAlbumCover: bound.getAlbumCover,
                     getGridHTML: bound.getGridHTML,
-                    strings,
-                    to
+                    link: bound.link,
+                    strings
                 });
 
                 bound.getFlashGridHTML = bindOpts(getFlashGridHTML, {
                     [bindOpts.bindIndex]: 0,
                     getFlashCover: bound.getFlashCover,
                     getGridHTML: bound.getGridHTML,
-                    to
+                    link: bound.link
                 });
 
                 bound.getRevealStringFromTags = bindOpts(getRevealStringFromTags, {