From 5d7b838a030f8bdab66c5b8a48cc30c9b23b6737 Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 6 Mar 2020 16:59:52 -0400 Subject: a whole heckin lot of stuff but mainly lofam1/2 --- upd8.js | 158 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 79 insertions(+), 79 deletions(-) (limited to 'upd8.js') diff --git a/upd8.js b/upd8.js index c62d4590..4486a86c 100644 --- a/upd8.js +++ b/upd8.js @@ -151,6 +151,17 @@ const ALBUM_DATA_FILE = 'album.txt'; const CSS_FILE = 'site.css'; +// Shared varia8les! These are more efficient to access than a shared varia8le +// (or at least I h8pe so), and are easier to pass across functions than a +// 8unch of specific arguments. +// +// Upd8: Okay yeah these aren't actually any different. Still cleaner than +// passing around a data object containing all this, though. +let albumData; +let allTracks; +let artistNames; +let flashData; + // Note there isn't a 'find track data files' function. I plan on including the // data for all tracks within an al8um collected in the single metadata file // for that al8um. Otherwise there'll just 8e way too many files, and I'd also @@ -278,11 +289,11 @@ function getMultilineField(lines, name) { return listLines.map(line => line.slice(4)).join('\n'); }; -function transformMultiline(text, D) { +function transformMultiline(text) { // Heck yes, HTML magics. text = text.replace(/\[\[(.+?)\]\]/g, (match, ref) => { - const track = getLinkedTrack(ref, D); + const track = getLinkedTrack(ref); if (track) { return fixWS` ${track.name} @@ -600,7 +611,7 @@ async function processFlashDataFile(file) { // compiling a 8unch of songs with radically different & interspersed release // d8s, 8ut still keep the al8um listing in a specific order, since that isn't // sorted 8y date. -function getAllTracks(albumData) { +function getAllTracks() { return sortByDate(albumData.reduce((acc, album) => acc.concat(album.tracks), [])); } @@ -618,7 +629,7 @@ function getDateString({ date }) { return date.toLocaleDateString(); } -function getArtistNames(albumData) { +function getArtistNames() { return Array.from(new Set( albumData.reduce((acc, album) => acc.concat((album.coverArtists || []).map(({ who }) => who), album.tracks.reduce((acc, track) => acc.concat(track.artists, (track.coverArtists || []).map(({ who }) => who)), [])), []) )); @@ -652,8 +663,7 @@ async function writePage(directoryParts, title, body) { `); } -function writeMiscellaneousPages(D) { - const { albumData, flashData } = D; +function writeMiscellaneousPages() { return progressPromiseAll('Writing miscellaneous pages.', [ writePage([], SITE_TITLE, fixWS` @@ -746,14 +756,14 @@ function writeMiscellaneousPages(D) { // This function title is my gr8test work of art. // (The 8ehavior... well, um. Don't tell anyone, 8ut it's even 8etter.) -function writeIndexAndTrackPagesForAlbum(album, D) { +function writeIndexAndTrackPagesForAlbum(album) { return [ - () => writeAlbumPage(album, D), - ...album.tracks.map(track => () => writeTrackPage(track, D)) + () => writeAlbumPage(album), + ...album.tracks.map(track => () => writeTrackPage(track)) ]; } -async function writeAlbumPage(album, D) { +async function writeAlbumPage(album) { await writePage([ALBUM_DIRECTORY, album.directory], album.name, fixWS` @@ -790,13 +800,12 @@ async function writeAlbumPage(album, D) { `); } -async function writeTrackPage(track, D) { - const { artistNames } = D; - const tracksThatReference = getTracksThatReference(track, D); +async function writeTrackPage(track) { + const tracksThatReference = getTracksThatReference(track); const ttrFanon = tracksThatReference.filter(t => t.isFanon); const ttrCanon = tracksThatReference.filter(t => !t.isFanon); - const tracksReferenced = getTracksReferencedBy(track, D); - const flashesThatFeature = getFlashesThatFeature(track, D); + const tracksReferenced = getTracksReferencedBy(track); + const flashesThatFeature = getFlashesThatFeature(track); await writePage([TRACK_DIRECTORY, track.directory], track.name, fixWS` @@ -893,17 +902,17 @@ async function writeTrackPage(track, D) { `); } -async function writeArtistPages(D) { - await progressPromiseAll('Writing artist pages.', queue(D.artistNames.map(artistName => () => writeArtistPage(artistName, D)))); +async function writeArtistPages() { + await progressPromiseAll('Writing artist pages.', queue(artistNames.map(artistName => () => writeArtistPage(artistName)))); } -async function writeArtistPage(artistName, D) { - const tracks = sortByDate(D.allTracks.filter(track => ( +async function writeArtistPage(artistName) { + const tracks = sortByDate(allTracks.filter(track => ( track.artists.includes(artistName) || track.contributors.some(({ who }) => who === artistName) ))); - const artThings = sortByDate(D.albumData.concat(D.allTracks).filter(thing => (thing.coverArtists || []).some(({ who }) => who === artistName))); - const commentaryThings = sortByDate(D.albumData.concat(D.allTracks).filter(thing => thing.commentary && thing.commentary.includes('' + artistName + ':'))); + const artThings = sortByDate(albumData.concat(allTracks).filter(thing => (thing.coverArtists || []).some(({ who }) => who === artistName))); + const commentaryThings = sortByDate(albumData.concat(allTracks).filter(thing => thing.commentary && thing.commentary.includes('' + artistName + ':'))); // Shish! const kebab = getArtistDirectory(artistName); @@ -927,12 +936,12 @@ async function writeArtistPage(artistName, D) { who: artistName, what: track.contributors.filter(({ who }) => who === artistName).map(({ what }) => what).join(', ') }; - const flashes = getFlashesThatFeature(track, D); + const flashes = getFlashesThatFeature(track); return fixWS`
  • ${track.name} - ${track.artists.includes(artistName) && track.artists.length > 1 && `(with ${getArtistString(track.artists.filter(a => a !== artistName), D)})`} - ${contrib.what && `(${getContributionString(contrib, D) || 'contributed'})`} + ${track.artists.includes(artistName) && track.artists.length > 1 && `(with ${getArtistString(track.artists.filter(a => a !== artistName))})`} + ${contrib.what && `(${getContributionString(contrib) || 'contributed'})`} ${flashes.length && `
    (Featured in ${joinNoOxford(flashes.map(getFlashLinkHTML))})
    `}
  • `; @@ -947,7 +956,7 @@ async function writeArtistPage(artistName, D) { ${thing.album ? fixWS` ${thing.name} ` : '(cover art)'} - ${contrib.what && `(${getContributionString(contrib, D)})`} + ${contrib.what && `(${getContributionString(contrib)})`} `; })} @@ -955,7 +964,7 @@ async function writeArtistPage(artistName, D) { ${commentaryThings.length && fixWS`

    Commentary

    ${albumChunkedList(commentaryThings, thing => { - const flashes = getFlashesThatFeature(thing, D); + const flashes = getFlashesThatFeature(thing); return fixWS`
  • ${thing.album ? fixWS` @@ -1000,12 +1009,11 @@ function albumChunkedList(tracks, getLI, showDate = true) { `; } -async function writeFlashPages(D) { - await progressPromiseAll('Writing Flash pages.', D.flashData.map(flash => flash.page && writeFlashPage(flash, D)).filter(Boolean)); +async function writeFlashPages() { + await progressPromiseAll('Writing Flash pages.', queue(flashData.map(flash => () => flash.page && writeFlashPage(flash)).filter(Boolean))); } -async function writeFlashPage(flash, D) { - const {allTracks, flashData} = D; +async function writeFlashPage(flash) { const kebab = getFlashDirectory(flash); const index = `${FLASH_DIRECTORY}/${kebab}/index.html`; const act6 = flashData.findIndex(f => f.act.startsWith('Act 6')) @@ -1045,13 +1053,13 @@ async function writeFlashPage(flash, D) {

    Tracks featured in ${flash.name.replace(/\.$/, '')}: