From 234747721fec14e69fc75d6c0134ad4a5ae7736e Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 1 Jun 2021 15:32:03 -0300 Subject: basic module-ify album pages Other pages are commented out for now. Also, this doesn't include the source .txt processing functions yet, 8ut that'll pro8a8ly end up in the page/ files too. --- src/page/album.js | 381 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/page/index.js | 5 + 2 files changed, 386 insertions(+) create mode 100644 src/page/album.js create mode 100644 src/page/index.js (limited to 'src/page') diff --git a/src/page/album.js b/src/page/album.js new file mode 100644 index 00000000..f8597790 --- /dev/null +++ b/src/page/album.js @@ -0,0 +1,381 @@ +// Album page specification. +// +// Also exports utility functions: +// - generateAlbumSidebar +// - generateAlbumNavLinks +// - generateAlbumChronologyLinks + +import fixWS from 'fix-whitespace'; + +import { + getAlbumCover, + getAlbumListTag, + getTotalDuration +} from '../util/wiki-data.js'; + +import { + getLinkThemeString, + getThemeString +} from '../util/colors.js'; + +import * as html from '../util/html.js'; + +export function targets({wikiData}) { + return wikiData.albumData; +} + +export function write(album, {wikiData}) { + const { wikiInfo } = wikiData; + + const trackToListItem = (track, {getArtistString, link, strings}) => { + const itemOpts = { + duration: strings.count.duration(track.duration), + track: link.track(track) + }; + return `
  • ${ + (track.artists === album.artists + ? strings('trackList.item.withDuration', itemOpts) + : strings('trackList.item.withDuration.withArtists', { + ...itemOpts, + by: `${ + strings('trackList.item.withArtists.by', { + artists: getArtistString(track.artists) + }) + }` + })) + }
  • `; + }; + + const commentaryEntries = [album, ...album.tracks].filter(x => x.commentary).length; + const albumDuration = getTotalDuration(album.tracks); + + const listTag = getAlbumListTag(album); + + const data = { + type: 'data', + path: ['album', album.directory], + data: ({ + serializeContribs, + serializeCover, + serializeGroupsForAlbum, + serializeLink + }) => ({ + name: album.name, + directory: album.directory, + dates: { + released: album.date, + trackArtAdded: album.trackArtDate, + coverArtAdded: album.coverArtDate, + addedToWiki: album.dateAdded + }, + duration: albumDuration, + color: album.color, + cover: serializeCover(album, getAlbumCover), + artists: serializeContribs(album.artists || []), + coverArtists: serializeContribs(album.coverArtists || []), + wallpaperArtists: serializeContribs(album.wallpaperArtists || []), + bannerArtists: serializeContribs(album.bannerArtists || []), + groups: serializeGroupsForAlbum(album), + trackGroups: album.trackGroups?.map(trackGroup => ({ + name: trackGroup.name, + color: trackGroup.color, + tracks: trackGroup.tracks.map(track => track.directory) + })), + tracks: album.tracks.map(track => ({ + link: serializeLink(track), + duration: track.duration + })) + }) + }; + + const page = { + type: 'page', + path: ['album', album.directory], + page: ({ + chronologyLinks, + fancifyURL, + generateCoverLink, + getAlbumStylesheet, + getArtistString, + link, + strings, + transformMultiline + }) => ({ + title: strings('albumPage.title', {album: album.name}), + stylesheet: getAlbumStylesheet(album), + theme: getThemeString(album.color, [ + `--album-directory: ${album.directory}` + ]), + + 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}) + }) + ].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) + }) + ].filter(Boolean).join('
    \n')} +

    + ${album.commentary && fixWS` +

    ${strings('releaseInfo.artistCommentary')}

    +
    + ${transformMultiline(album.commentary)} +
    + `} + ` + }, + + sidebarLeft: generateAlbumSidebar(album, null, { + fancifyURL, + 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, {link, strings}) + } + ], + content: html.tag('div', generateAlbumChronologyLinks(album, null, {chronologyLinks})) + } + }) + }; + + return [page, data]; +} + +export function generateAlbumSidebar(album, currentTrack, { + fancifyURL, + link, + strings, + transformMultiline, + wikiData +}) { + const listTag = getAlbumListTag(album); + + const trackGroups = album.trackGroups || [{ + name: strings('albumSidebar.trackList.fallbackGroupName'), + color: album.color, + startIndex: 0, + tracks: album.tracks + }]; + + const trackToListItem = track => html.tag('li', + {class: track === currentTrack && 'current'}, + strings('albumSidebar.trackList.item', { + track: link.track(track) + })); + + const trackListPart = fixWS` +

    ${link.album(album)}

    + ${trackGroups.map(({ name, color, startIndex, tracks }) => + html.tag('details', { + // Leave side8ar track groups collapsed on al8um homepage, + // since there's already a view of all the groups expanded + // in the main content area. + open: currentTrack && tracks.includes(currentTrack), + class: tracks.includes(currentTrack) && 'current' + }, [ + html.tag('summary', + {style: getLinkThemeString(color)}, + (listTag === 'ol' + ? strings('albumSidebar.trackList.group.withRange', { + group: `${name}`, + range: `${startIndex + 1}–${startIndex + tracks.length}` + }) + : strings('albumSidebar.trackList.group', { + group: `${name}` + })) + ), + fixWS` + <${listTag === 'ol' ? `ol start="${startIndex + 1}"` : listTag}> + ${tracks.map(trackToListItem).join('\n')} + + ` + ])).join('\n')} + `; + + const { groups } = album; + + const groupParts = groups.map(group => { + const index = group.albums.indexOf(album); + const next = group.albums[index + 1]; + const previous = group.albums[index - 1]; + return {group, next, previous}; + }).map(({group, next, previous}) => fixWS` +

    ${ + strings('albumSidebar.groupBox.title', { + group: link.groupInfo(group) + }) + }

    + ${!currentTrack && transformMultiline(group.descriptionShort)} + ${group.urls.length && `

    ${ + strings('releaseInfo.visitOn', { + links: strings.list.or(group.urls.map(url => fancifyURL(url))) + }) + }

    `} + ${!currentTrack && fixWS` + ${next && ``} + ${previous && ``} + `} + `); + + if (groupParts.length) { + if (currentTrack) { + const combinedGroupPart = groupParts.join('\n
    \n'); + return { + multiple: [ + trackListPart, + combinedGroupPart + ] + }; + } else { + return { + multiple: [ + ...groupParts, + trackListPart + ] + }; + } + } else { + return { + content: trackListPart + }; + } +} + +export function generateAlbumNavLinks(album, currentTrack, {link, strings}) { + if (album.tracks.length <= 1) { + return ''; + } + + const previousNextLinks = currentTrack && generatePreviousNextLinks(currentTrack, { + link, strings, + data: album.tracks, + linkKey: 'track' + }); + const randomLink = `${ + (currentTrack + ? strings('trackPage.nav.random') + : strings('albumPage.nav.randomTrack')) + }`; + + return (previousNextLinks + ? `(${previousNextLinks}, ${randomLink})` + : `(${randomLink})`); +} + +export function generateAlbumChronologyLinks(album, currentTrack, {chronologyLinks}) { + return [ + currentTrack && chronologyLinks(currentTrack, { + contribKey: 'artists', + getThings: artist => [...artist.tracks.asArtist, ...artist.tracks.asContributor], + headingString: 'misc.chronology.heading.track' + }), + chronologyLinks(currentTrack || album, { + contribKey: 'coverArtists', + getThings: artist => [...artist.albums.asCoverArtist, ...artist.tracks.asCoverArtist], + headingString: 'misc.chronology.heading.coverArt' + }) + ].filter(Boolean).join('\n'); +} diff --git a/src/page/index.js b/src/page/index.js new file mode 100644 index 00000000..ca782389 --- /dev/null +++ b/src/page/index.js @@ -0,0 +1,5 @@ +// NB: This is the index for the page/ directory and contains exports for all +// other modules here! It's not the page spec for the homepage - see +// homepage.js for that. + +export * as album from './album.js'; -- cgit 1.3.0-6-gf8a5