From add3806e515d6537e448fbb63ce2e817c1ee118c Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 17 Nov 2019 00:27:49 -0400 Subject: add music commentary from pastebin + tumblrs https://pastebin.com/gqpHsKkE --- upd8.js | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 84 insertions(+), 8 deletions(-) (limited to 'upd8.js') diff --git a/upd8.js b/upd8.js index 7e811cd5..d169d820 100644 --- a/upd8.js +++ b/upd8.js @@ -77,6 +77,7 @@ const access = util.promisify(fs.access); const { joinNoOxford, + progressPromiseAll, splitArray } = require('./upd8-util'); @@ -138,7 +139,7 @@ async function findAlbumDataFiles() { const albums = await readdir(ALBUM_DIRECTORY); - const paths = await Promise.all(albums.map(async album => { + const paths = await progressPromiseAll(`Searching for album files.`, albums.map(async album => { // Argua8ly terri8le/am8iguous varia8le naming. Too 8ad! const albumDirectory = path.join(ALBUM_DIRECTORY, album); const files = await readdir(albumDirectory); @@ -248,6 +249,40 @@ async function processAlbumDataFile(file) { return contributors; }; + const getMultilineField = (lines, name) => { + // All this code is 8asically the same as the getListText - just with a + // different line prefix (four spaces instead of a dash and a space). + let startIndex = lines.findIndex(line => line.startsWith(name + ':')); + if (startIndex === -1) { + return null; + } + startIndex++; + let endIndex = lines.findIndex((line, index) => index >= startIndex && !line.startsWith(' ')); + if (endIndex === -1) { + endIndex = lines.length; + } + // If there aren't any content lines, don't return anything! + if (endIndex === startIndex) { + return null; + } + // We also join the lines instead of returning an array. + const listLines = lines.slice(startIndex, endIndex); + return listLines.map(line => line.slice(4)).join('\n'); + }; + + const getMultilineHTMLField = (lines, name) => { + const text = getMultilineField(lines, name); + if (text) { + const lines = text.split('\n'); + if (!lines[0].startsWith('')) { + return {error: `An entry is missing commentary citation: "${lines[0].slice(0, 40)}..."`}; + } + return lines.map(line => line.startsWith(' `} + ${track.commentary && fixWS` +

Artist commentary:

+
+ ${track.commentary} +
+ `} @@ -614,14 +673,15 @@ async function writeArtistPage(artistName, albumData) { track.artists.includes(artistName) || track.contributors.some(({ who }) => who === artistName) || getTracksReferencedBy(track, allTracks).some(track => track.artists.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); const artistDirectory = path.join(ARTIST_DIRECTORY, kebab); + const index = `${ARTIST_DIRECTORY}/${kebab}/index.html`; await mkdirp(artistDirectory); await writeFile(path.join(artistDirectory, 'index.html'), fixWS` @@ -638,8 +698,13 @@ async function writeArtistPage(artistName, albumData) { `}

${artistName}

+

Jump to: ${[ + tracks.length && `Tracks`, + artThings.length && `Art`, + commentaryThings.length && `Commentary` + ].filter(Boolean).join(', ')}

${tracks.length && fixWS` -

Tracks

+

Tracks

Dim tracks are tracks that this artist contributed only a based-upon song to.

    ${tracks.map(track => { @@ -666,7 +731,7 @@ async function writeArtistPage(artistName, albumData) {
`} ${artThings.length && fixWS` -

Art

+

Art

    ${artThings.map(thing => { const contrib = thing.coverArtists.find(({ who }) => who === artistName); @@ -680,6 +745,17 @@ async function writeArtistPage(artistName, albumData) { }).join('\n')}
`} + ${commentaryThings.length && fixWS` +

Commentary

+ + `} @@ -878,20 +954,20 @@ async function main() { // Technically, we could do the data file reading and output writing at the // same time, 8ut that kinda makes the code messy, so I'm not 8othering // with it. - const albumData = await Promise.all(albumDataFiles.map(processAlbumDataFile)); + const albumData = await progressPromiseAll(`Reading & processing album files.`, albumDataFiles.map(processAlbumDataFile)); sortByDate(albumData); const errors = albumData.filter(obj => obj.error); if (errors.length) { for (const error of errors) { - console.log(error.error); + console.log(`\x1b[31;1m${error.error}\x1b[0m`); } return; } await writeTopIndexPage(albumData); - await Promise.all(albumData.map(album => writeIndexAndTrackPagesForAlbum(album, albumData))); + await progressPromiseAll(`Writing album & track pages.`, albumData.map(album => writeIndexAndTrackPagesForAlbum(album, albumData))); await writeArtistPages(albumData); // await writeGridSite(albumData); -- cgit 1.3.0-6-gf8a5