diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/data/things.js | 11 | ||||
-rw-r--r-- | src/data/yaml.js | 3 | ||||
-rw-r--r-- | src/misc-templates.js | 46 | ||||
-rw-r--r-- | src/page/album.js | 2 | ||||
-rw-r--r-- | src/page/track.js | 53 | ||||
-rw-r--r-- | src/strings-default.json | 4 | ||||
-rwxr-xr-x | src/upd8.js | 6 |
7 files changed, 88 insertions, 37 deletions
diff --git a/src/data/things.js b/src/data/things.js index 8f460e49..18efac47 100644 --- a/src/data/things.js +++ b/src/data/things.js @@ -1388,13 +1388,22 @@ WikiInfo.propertyDescriptors = { update: {validate: isURL} }, - // Feature toggles + divideTrackListsByGroupsByRef: Thing.common.referenceList(Group), + // Feature toggles enableFlashesAndGames: Thing.common.flag(false), enableListings: Thing.common.flag(false), enableNews: Thing.common.flag(false), enableArtTagUI: Thing.common.flag(false), enableGroupUI: Thing.common.flag(false), + + // Update only + + groupData: Thing.common.wikiData(Group), + + // Expose only + + divideTrackListsByGroups: Thing.common.dynamicThingsFromReferenceList('divideTrackListsByGroupsByRef', 'groupData', find.group), }; // -> Language diff --git a/src/data/yaml.js b/src/data/yaml.js index 072aca67..fa967561 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -402,6 +402,7 @@ export const processWikiInfoDocument = makeProcessDocument(WikiInfo, { footerContent: 'Footer Content', defaultLanguage: 'Default Language', canonicalBase: 'Canonical Base', + divideTrackListsByGroupsByRef: 'Divide Track Lists By Groups', enableFlashesAndGames: 'Enable Flashes & Games', enableListings: 'Enable Listings', enableNews: 'Enable News', @@ -1090,6 +1091,8 @@ export function linkWikiDataArrays(wikiData) { const WD = wikiData; + assignWikiData([WD.wikiInfo], 'groupData'); + assignWikiData(WD.albumData, 'artistData', 'artTagData', 'groupData', 'trackData'); WD.albumData.forEach(album => assignWikiData(album.trackGroups, 'trackData')); diff --git a/src/misc-templates.js b/src/misc-templates.js index 58c45f5c..d3817500 100644 --- a/src/misc-templates.js +++ b/src/misc-templates.js @@ -242,6 +242,52 @@ export function getAlbumStylesheet(album, {to}) { ].filter(Boolean).join('\n'); } +// Divided track lists + +export function generateTrackListDividedByGroups(tracks, { + getTrackItem, + language, + wikiData, +}) { + const { divideTrackListsByGroups: groups } = wikiData.wikiInfo; + + if (!groups?.length) { + return html.tag('ul', tracks.map(t => getTrackItem(t))); + } + + const lists = Object.fromEntries(groups.map(group => [group.directory, {group, tracks: []}])); + const other = []; + + for (const track of tracks) { + const { album } = track; + const group = groups.find(g => g.albums.includes(album)); + if (group) { + lists[group.directory].tracks.push(track); + } else { + other.push(track); + } + } + + const ddul = tracks => fixWS` + <dd><ul> + ${tracks.map(t => getTrackItem(t)).join('\n')} + </ul></dd> + `; + + return html.tag('dl', Object.values(lists) + .filter(({ tracks }) => tracks.length) + .flatMap(({ group, tracks }) => [ + html.tag('dt', language.formatString('trackList.group', {group: group.name})), + ddul(tracks) + ]) + .concat(other.length ? [ + `<dt>${language.formatString('trackList.group', { + group: language.formatString('trackList.group.other') + })}</dt>`, + ddul(other) + ] : [])); +} + // Fancy lookin' links export function fancifyURL(url, {language, album = false} = {}) { diff --git a/src/page/album.js b/src/page/album.js index ec994ebb..70cb5367 100644 --- a/src/page/album.js +++ b/src/page/album.js @@ -205,7 +205,7 @@ export function write(album, {wikiData}) { <dl class="album-group-list"> ${album.trackGroups.map(({ name, color, startIndex, tracks }) => fixWS` <dt>${ - language.$('trackList.group', { + language.$('trackList.section.withDuration', { duration: language.formatDuration(getTotalDuration(tracks), {approximate: tracks.length > 1}), group: name }) diff --git a/src/page/track.js b/src/page/track.js index 3295d48a..22e6c9da 100644 --- a/src/page/track.js +++ b/src/page/track.js @@ -13,10 +13,6 @@ import { import * as html from '../util/html.js'; import { - OFFICIAL_GROUP_DIRECTORY -} from '../util/magic-constants.js'; - -import { bindOpts } from '../util/sugar.js'; @@ -36,12 +32,6 @@ export function write(track, {wikiData}) { const { groupData, wikiInfo } = wikiData; const { album, referencedByTracks, referencedTracks, otherReleases } = track; - const useDividedReferences = groupData.some(group => group.directory === OFFICIAL_GROUP_DIRECTORY); - const rbtFanon = (useDividedReferences && - referencedByTracks.filter(t => t.album.groups.every(group => group.directory !== OFFICIAL_GROUP_DIRECTORY))); - const rbtOfficial = (useDividedReferences && - referencedByTracks.filter(t => t.album.groups.some(group => group.directory === OFFICIAL_GROUP_DIRECTORY))); - const listTag = getAlbumListTag(album); let flashesThatFeature; @@ -50,18 +40,20 @@ export function write(track, {wikiData}) { .flatMap(track => track.featuredInFlashes.map(flash => ({flash, as: track})))); } + const unbound_getTrackItem = (track, {getArtistString, link, language}) => { + const line = language.$('trackList.item.withArtists', { + track: link.track(track), + by: `<span class="by">${language.$('trackList.item.withArtists.by', { + artists: getArtistString(track.artistContribs) + })}</span>` + }); + return (track.aka + ? `<li class="rerelease">${language.$('trackList.item.rerelease', {track: line})}</li>` + : `<li>${line}</li>`); + }; + const unbound_generateTrackList = (tracks, {getArtistString, link, language}) => html.tag('ul', - tracks.map(track => { - const line = language.$('trackList.item.withArtists', { - track: link.track(track), - by: `<span class="by">${language.$('trackList.item.withArtists.by', { - artists: getArtistString(track.artistContribs) - })}</span>` - }); - return (track.aka - ? `<li class="rerelease">${language.$('trackList.item.rerelease', {track: line})}</li>` - : `<li>${line}</li>`); - }) + tracks.map(track => unbound_getTrackItem(track, {getArtistString, link, language})) ); const hasCommentary = track.commentary || otherReleases.some(t => t.commentary); @@ -150,6 +142,7 @@ export function write(track, {wikiData}) { generateChronologyLinks, generateCoverLink, generatePreviousNextLinks, + generateTrackListDividedByGroups, getAlbumStylesheet, getArtistString, getLinkThemeString, @@ -164,6 +157,7 @@ export function write(track, {wikiData}) { urls, }) => { const generateTrackList = bindOpts(unbound_generateTrackList, {getArtistString, link, language}); + const getTrackItem = bindOpts(unbound_getTrackItem, {getArtistString, link, language}); const cover = getTrackCover(track); return { @@ -264,19 +258,10 @@ export function write(track, {wikiData}) { `} ${referencedByTracks.length && fixWS` <p>${language.$('releaseInfo.tracksThatReference', {track: `<i>${track.name}</i>`})}</p> - ${useDividedReferences && fixWS` - <dl> - ${rbtOfficial.length && fixWS` - <dt>${language.$('trackPage.referenceList.official')}</dt> - <dd>${generateTrackList(rbtOfficial)}</dd> - `} - ${rbtFanon.length && fixWS` - <dt>${language.$('trackPage.referenceList.fandom')}</dt> - <dd>${generateTrackList(rbtFanon)}</dd> - `} - </dl> - `} - ${!useDividedReferences && generateTrackList(referencedByTracks)} + ${generateTrackListDividedByGroups(referencedByTracks, { + getTrackItem, + wikiData, + })} `} ${wikiInfo.enableFlashesAndGames && flashesThatFeature.length && fixWS` <p>${language.$('releaseInfo.flashesThatFeature', {track: `<i>${track.name}</i>`})}</p> diff --git a/src/strings-default.json b/src/strings-default.json index 9ece6a8e..b607b06e 100644 --- a/src/strings-default.json +++ b/src/strings-default.json @@ -111,7 +111,9 @@ "releaseInfo.additionalFiles.file": "{FILE}", "releaseInfo.additionalFiles.file.withSize": "{FILE} ({SIZE})", "releaseInfo.note": "Note:", - "trackList.group": "{GROUP} ({DURATION}):", + "trackList.section.withDuration": "{SECTION} ({DURATION}):", + "trackList.group": "{GROUP}:", + "trackList.group.other": "Other", "trackList.item.withDuration": "({DURATION}) {TRACK}", "trackList.item.withDuration.withArtists": "({DURATION}) {TRACK} {BY}", "trackList.item.withArtists": "{TRACK} {BY}", diff --git a/src/upd8.js b/src/upd8.js index 394af80e..3294ba73 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -92,6 +92,7 @@ import { generateCoverLink, generateInfoGalleryLinks, generatePreviousNextLinks, + generateTrackListDividedByGroups, getAlbumGridHTML, getAlbumStylesheet, getArtistString, @@ -2111,6 +2112,11 @@ async function main() { language }); + bound.generateTrackListDividedByGroups = bindOpts(generateTrackListDividedByGroups, { + language, + wikiData, + }); + bound.getGridHTML = bindOpts(getGridHTML, { [bindOpts.bindIndex]: 0, img, |