From 5b1418b417c2bac641a8671e7da5cf02aefa6245 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 31 Dec 2021 21:16:59 -0400 Subject: refactor/tweak getGridHTML to use link() fns --- src/misc-templates.js | 42 ++++++++++++++++++++---------------------- src/page/artist.js | 6 +++--- src/page/tag.js | 6 +++--- src/upd8.js | 7 +++---- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/misc-templates.js b/src/misc-templates.js index a6b39b9..e787184 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}) - })} - ${item.name} - ${detailsFn && `${detailsFn(item)}`} - `)).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}) + })} + ${item.name} + ${detailsFn && `${detailsFn(item)}`} + ` + })).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 2e87669..e6160be 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)) })} ` diff --git a/src/page/tag.js b/src/page/tag.js index 4253120..791c713 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)) })} ` diff --git a/src/upd8.js b/src/upd8.js index 91cc66d..b31505d 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, { -- cgit 1.3.0-6-gf8a5