From b2469c03bd4bdb29c5e80752f812203a6755c159 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 4 Jun 2021 17:30:16 -0300 Subject: move around a bunch of utility functions --- src/page/album-commentary.js | 7 +- src/page/album.js | 275 +++++++++++++++++++++++-------------------- src/page/flash.js | 7 +- src/page/group.js | 32 +++-- src/page/homepage.js | 5 +- src/page/listing.js | 77 ++++++------ src/page/tag.js | 5 +- src/page/track.js | 7 +- 8 files changed, 218 insertions(+), 197 deletions(-) (limited to 'src/page') diff --git a/src/page/album-commentary.js b/src/page/album-commentary.js index 77ca3ef1..c03ae3db 100644 --- a/src/page/album-commentary.js +++ b/src/page/album-commentary.js @@ -4,11 +4,6 @@ import fixWS from 'fix-whitespace'; -import { - getLinkThemeString, - getThemeString -} from '../util/colors.js'; - import { filterAlbumsByCommentary } from '../util/wiki-data.js'; @@ -34,6 +29,8 @@ export function write(album, {wikiData}) { path: ['albumCommentary', album.directory], page: ({ getAlbumStylesheet, + getLinkThemeString, + getThemeString, link, strings, to, diff --git a/src/page/album.js b/src/page/album.js index 16da6021..adcc0584 100644 --- a/src/page/album.js +++ b/src/page/album.js @@ -4,13 +4,12 @@ import fixWS from 'fix-whitespace'; -import { - getLinkThemeString, - getThemeString -} from '../util/colors.js'; - import * as html from '../util/html.js'; +import { + bindOpts +} from '../util/sugar.js'; + import { getAlbumCover, getAlbumListTag, @@ -26,7 +25,12 @@ export function targets({wikiData}) { export function write(album, {wikiData}) { const { wikiInfo } = wikiData; - const trackToListItem = (track, {getArtistString, link, strings}) => { + const unbound_trackToListItem = (track, { + getArtistString, + getLinkThemeString, + link, + strings + }) => { const itemOpts = { duration: strings.count.duration(track.duration), track: link.track(track) @@ -96,140 +100,152 @@ export function write(album, {wikiData}) { generateCoverLink, getAlbumStylesheet, getArtistString, + getLinkThemeString, + getThemeString, link, strings, transformMultiline - }) => ({ - title: strings('albumPage.title', {album: album.name}), - stylesheet: getAlbumStylesheet(album), - theme: getThemeString(album.color, [ - `--album-directory: ${album.directory}` - ]), + }) => { + const trackToListItem = bindOpts(unbound_trackToListItem, { + getArtistString, + getLinkThemeString, + link, + strings + }); - banner: album.bannerArtists && { - dimensions: album.bannerDimensions, - path: ['media.albumBanner', album.directory], - alt: strings('misc.alt.albumBanner'), - position: 'top' - }, + return { + title: strings('albumPage.title', {album: album.name}), + stylesheet: getAlbumStylesheet(album), + theme: getThemeString(album.color, [ + `--album-directory: ${album.directory}` + ]), - main: { - content: fixWS` - ${generateCoverLink({ - path: ['media.albumCover', album.directory], - alt: strings('misc.alt.albumCover'), - tags: album.artTags - })} -

${strings('albumPage.title', {album: album.name})}

-

- ${[ - album.artists && strings('releaseInfo.by', { - artists: getArtistString(album.artists, { - showContrib: true, - showIcons: true - }) - }), - album.coverArtists && strings('releaseInfo.coverArtBy', { - artists: getArtistString(album.coverArtists, { - showContrib: true, - showIcons: true - }) - }), - album.wallpaperArtists && strings('releaseInfo.wallpaperArtBy', { - artists: getArtistString(album.wallpaperArtists, { - showContrib: true, - showIcons: true + banner: album.bannerArtists && { + dimensions: album.bannerDimensions, + path: ['media.albumBanner', album.directory], + alt: strings('misc.alt.albumBanner'), + position: 'top' + }, + + main: { + content: fixWS` + ${generateCoverLink({ + path: ['media.albumCover', album.directory], + alt: strings('misc.alt.albumCover'), + tags: album.artTags + })} +

${strings('albumPage.title', {album: album.name})}

+

+ ${[ + album.artists && strings('releaseInfo.by', { + artists: getArtistString(album.artists, { + showContrib: true, + showIcons: true + }) + }), + album.coverArtists && strings('releaseInfo.coverArtBy', { + artists: getArtistString(album.coverArtists, { + showContrib: true, + showIcons: true + }) + }), + album.wallpaperArtists && strings('releaseInfo.wallpaperArtBy', { + artists: getArtistString(album.wallpaperArtists, { + showContrib: true, + showIcons: true + }) + }), + album.bannerArtists && strings('releaseInfo.bannerArtBy', { + artists: getArtistString(album.bannerArtists, { + showContrib: true, + showIcons: true + }) + }), + strings('releaseInfo.released', { + date: strings.count.date(album.date) + }), + +album.coverArtDate !== +album.date && strings('releaseInfo.artReleased', { + date: strings.count.date(album.coverArtDate) + }), + strings('releaseInfo.duration', { + duration: strings.count.duration(albumDuration, {approximate: album.tracks.length > 1}) }) - }), - album.bannerArtists && strings('releaseInfo.bannerArtBy', { - artists: getArtistString(album.bannerArtists, { - showContrib: true, - showIcons: true + ].filter(Boolean).join('
\n')} +

+ ${commentaryEntries && `

${ + strings('releaseInfo.viewCommentary', { + link: link.albumCommentary(album, { + text: strings('releaseInfo.viewCommentary.link') }) - }), - strings('releaseInfo.released', { - date: strings.count.date(album.date) - }), - +album.coverArtDate !== +album.date && strings('releaseInfo.artReleased', { - date: strings.count.date(album.coverArtDate) - }), - strings('releaseInfo.duration', { - duration: strings.count.duration(albumDuration, {approximate: album.tracks.length > 1}) - }) - ].filter(Boolean).join('
\n')} -

- ${commentaryEntries && `

${ - strings('releaseInfo.viewCommentary', { - link: link.albumCommentary(album, { - text: strings('releaseInfo.viewCommentary.link') }) - }) - }

`} - ${album.urls.length && `

${ - strings('releaseInfo.listenOn', { - links: strings.list.or(album.urls.map(url => fancifyURL(url, {album: true}))) - }) - }

`} - ${album.trackGroups ? fixWS` -
- ${album.trackGroups.map(({ name, color, startIndex, tracks }) => fixWS` -
${ - strings('trackList.group', { - duration: strings.count.duration(getTotalDuration(tracks), {approximate: tracks.length > 1}), - group: name - }) - }
-
<${listTag === 'ol' ? `ol start="${startIndex + 1}"` : listTag}> - ${tracks.map(t => trackToListItem(t, {getArtistString, link, strings})).join('\n')} -
- `).join('\n')} -
- ` : fixWS` - <${listTag}> - ${album.tracks.map(t => trackToListItem(t, {getArtistString, link, strings})).join('\n')} - - `} -

- ${[ - strings('releaseInfo.addedToWiki', { - date: strings.count.date(album.dateAdded) + }

`} + ${album.urls.length && `

${ + strings('releaseInfo.listenOn', { + links: strings.list.or(album.urls.map(url => fancifyURL(url, {album: true}))) }) - ].filter(Boolean).join('
\n')} -

- ${album.commentary && fixWS` -

${strings('releaseInfo.artistCommentary')}

-
- ${transformMultiline(album.commentary)} -
- `} - ` - }, + }

`} + ${album.trackGroups ? fixWS` +
+ ${album.trackGroups.map(({ name, color, startIndex, tracks }) => fixWS` +
${ + strings('trackList.group', { + duration: strings.count.duration(getTotalDuration(tracks), {approximate: tracks.length > 1}), + group: name + }) + }
+
<${listTag === 'ol' ? `ol start="${startIndex + 1}"` : listTag}> + ${tracks.map(trackToListItem).join('\n')} +
+ `).join('\n')} +
+ ` : fixWS` + <${listTag}> + ${album.tracks.map(trackToListItem).join('\n')} + + `} +

+ ${[ + strings('releaseInfo.addedToWiki', { + date: strings.count.date(album.dateAdded) + }) + ].filter(Boolean).join('
\n')} +

+ ${album.commentary && fixWS` +

${strings('releaseInfo.artistCommentary')}

+
+ ${transformMultiline(album.commentary)} +
+ `} + ` + }, - sidebarLeft: generateAlbumSidebar(album, null, { - fancifyURL, - link, - strings, - transformMultiline, - wikiData - }), + sidebarLeft: generateAlbumSidebar(album, null, { + fancifyURL, + getLinkThemeString, + link, + strings, + transformMultiline, + wikiData + }), - nav: { - links: [ - {toHome: true}, - { - html: strings('albumPage.nav.album', { - album: link.album(album, {class: 'current'}) - }) - }, - album.tracks.length > 1 && - { - divider: false, - html: generateAlbumNavLinks(album, null, {strings}) - } - ], - content: html.tag('div', generateAlbumChronologyLinks(album, null, {generateChronologyLinks})) - } - }) + nav: { + links: [ + {toHome: true}, + { + html: strings('albumPage.nav.album', { + album: link.album(album, {class: 'current'}) + }) + }, + album.tracks.length > 1 && + { + divider: false, + html: generateAlbumNavLinks(album, null, {strings}) + } + ], + content: html.tag('div', generateAlbumChronologyLinks(album, null, {generateChronologyLinks})) + } + }; + } }; return [page, data]; @@ -239,6 +255,7 @@ export function write(album, {wikiData}) { export function generateAlbumSidebar(album, currentTrack, { fancifyURL, + getLinkThemeString, link, strings, transformMultiline, diff --git a/src/page/flash.js b/src/page/flash.js index 4ffaefc6..9c59016d 100644 --- a/src/page/flash.js +++ b/src/page/flash.js @@ -4,11 +4,6 @@ import fixWS from 'fix-whitespace'; -import { - getLinkThemeString, - getThemeString -} from '../util/colors.js'; - import * as html from '../util/html.js'; import { @@ -36,6 +31,7 @@ export function write(flash, {wikiData}) { generatePreviousNextLinks, getArtistString, getFlashCover, + getThemeString, link, strings, transformInline @@ -118,6 +114,7 @@ export function writeTargetless({wikiData}) { path: ['flashIndex'], page: ({ getFlashGridHTML, + getLinkThemeString, link, strings }) => ({ diff --git a/src/page/group.js b/src/page/group.js index 5db5a8ff..698c17ec 100644 --- a/src/page/group.js +++ b/src/page/group.js @@ -8,11 +8,6 @@ import { UNRELEASED_TRACKS_DIRECTORY } from '../util/magic-constants.js'; -import { - getLinkThemeString, - getThemeString -} from '../util/colors.js'; - import * as html from '../util/html.js'; import { @@ -44,6 +39,8 @@ export function write(group, {wikiData}) { page: ({ generateInfoGalleryLinks, generatePreviousNextLinks, + getLinkThemeString, + getThemeString, fancifyURL, link, strings, @@ -92,7 +89,13 @@ export function write(group, {wikiData}) { ` }, - sidebarLeft: generateGroupSidebar(group, false, {link, strings, wikiData}), + sidebarLeft: generateGroupSidebar(group, false, { + getLinkThemeString, + link, + strings, + wikiData + }), + nav: generateGroupNav(group, false, { generateInfoGalleryLinks, generatePreviousNextLinks, @@ -110,6 +113,8 @@ export function write(group, {wikiData}) { generateInfoGalleryLinks, generatePreviousNextLinks, getAlbumGridHTML, + getLinkThemeString, + getThemeString, link, strings }) => ({ @@ -144,7 +149,13 @@ export function write(group, {wikiData}) { ` }, - sidebarLeft: generateGroupSidebar(group, true, {link, strings, wikiData}), + sidebarLeft: generateGroupSidebar(group, true, { + getLinkThemeString, + link, + strings, + wikiData + }), + nav: generateGroupNav(group, true, { generateInfoGalleryLinks, generatePreviousNextLinks, @@ -160,7 +171,12 @@ export function write(group, {wikiData}) { // Utility functions -function generateGroupSidebar(currentGroup, isGallery, {link, strings, wikiData}) { +function generateGroupSidebar(currentGroup, isGallery, { + getLinkThemeString, + link, + strings, + wikiData +}) { const { groupCategoryData, wikiInfo } = wikiData; if (!wikiInfo.features.groupUI) { diff --git a/src/page/homepage.js b/src/page/homepage.js index d1dcc680..37ec4426 100644 --- a/src/page/homepage.js +++ b/src/page/homepage.js @@ -4,10 +4,6 @@ import fixWS from 'fix-whitespace'; -import { - getLinkThemeString -} from '../util/colors.js'; - import find from '../util/find.js'; import * as html from '../util/html.js'; @@ -27,6 +23,7 @@ export function writeTargetless({wikiData}) { path: ['home'], page: ({ getAlbumGridHTML, + getLinkThemeString, link, strings, to, diff --git a/src/page/listing.js b/src/page/listing.js index b0766b28..d4021747 100644 --- a/src/page/listing.js +++ b/src/page/listing.js @@ -46,44 +46,45 @@ export function write(listing, {wikiData}) { const page = { type: 'page', path: ['listing', listing.directory], - page: ({ - link, - strings - }) => ({ - title: listing.title({strings}), - - main: { - content: fixWS` -

${listing.title({strings})}

- ${listing.html && (listing.data - ? listing.html(data, {link, strings}) - : listing.html({link, strings}))} - ${listing.row && fixWS` - - `} - ` - }, - - sidebarLeft: { - content: generateSidebarForListings(listing, {link, strings, wikiData}) - }, - - nav: { - links: [ - {toHome: true}, - { - path: ['localized.listingIndex'], - title: strings('listingIndex.title') - }, - {toCurrentPage: true} - ] - } - }) + page: opts => { + const { link, strings } = opts; + + return { + title: listing.title({strings}), + + main: { + content: fixWS` +

${listing.title({strings})}

+ ${listing.html && (listing.data + ? listing.html(data, opts) + : listing.html(opts))} + ${listing.row && fixWS` + + `} + ` + }, + + sidebarLeft: { + content: generateSidebarForListings(listing, {link, strings, wikiData}) + }, + + nav: { + links: [ + {toHome: true}, + { + path: ['localized.listingIndex'], + title: strings('listingIndex.title') + }, + {toCurrentPage: true} + ] + } + }; + } }; return [page]; diff --git a/src/page/tag.js b/src/page/tag.js index c6f64bfc..610f4665 100644 --- a/src/page/tag.js +++ b/src/page/tag.js @@ -4,10 +4,6 @@ import fixWS from 'fix-whitespace'; -import { - getThemeString -} from '../util/colors.js'; - // Page exports export function condition({wikiData}) { @@ -28,6 +24,7 @@ export function write(tag, {wikiData}) { page: ({ getAlbumCover, getGridHTML, + getThemeString, getTrackCover, link, strings, diff --git a/src/page/track.js b/src/page/track.js index 2dec9bd3..0941ee89 100644 --- a/src/page/track.js +++ b/src/page/track.js @@ -10,10 +10,6 @@ import { generateAlbumSidebar } from './album.js'; -import { - getThemeString -} from '../util/colors.js'; - import * as html from '../util/html.js'; import { @@ -134,6 +130,8 @@ export function write(track, {wikiData}) { generatePreviousNextLinks, getAlbumStylesheet, getArtistString, + getLinkThemeString, + getThemeString, getTrackCover, link, strings, @@ -284,6 +282,7 @@ export function write(track, {wikiData}) { sidebarLeft: generateAlbumSidebar(album, track, { fancifyURL, + getLinkThemeString, link, strings, transformMultiline, -- cgit 1.3.0-6-gf8a5