From cf1653116c881d3ca91ecab4256560435625db31 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 17 Jan 2025 09:14:27 -0400 Subject: upd8: tidy additional file paths logic --- src/upd8.js | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/upd8.js b/src/upd8.js index ab369573..6d6f51c1 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -2407,35 +2407,37 @@ async function main() { // paths that will be exposed in site build code. We'll build a mapping // function between them so that when site code requests a site path, // it'll get the size of the file at the corresponding device path. - const additionalFilePaths = [ - ...wikiData.albumData.flatMap((album) => - [ - ...(album.additionalFiles ?? []), - ...album.tracks.flatMap((track) => [ - ...(track.additionalFiles ?? []), - ...(track.sheetMusicFiles ?? []), - ...(track.midiProjectFiles ?? []), + + const albumAdditionalFilePaths = + wikiData.albumData.flatMap(album => + ([ + ...album.additionalFiles, + ...album.tracks.flatMap(track => [ + ...track.additionalFiles, + ...track.sheetMusicFiles, + ...track.midiProjectFiles, ]), - ] - .flatMap((fileGroup) => fileGroup.files ?? []) - .map((file) => ({ - device: path.join( + ]).flatMap(fileGroup => fileGroup.files ?? []) + .map(file => ['media.albumAdditionalFile', album.directory, file])); + + const additionalFilePaths = + ([ + ...albumAdditionalFilePaths, + ]).map(filePath => ({ + device: + path.join( mediaPath, - urls - .from('media.root') - .toDevice('media.albumAdditionalFile', album.directory, file) - ), - media: urls - .from('media.root') - .to('media.albumAdditionalFile', album.directory, file), - })) - ), - ]; + urls.from('media.root').toDevice(...filePath)), + + media: + urls.from('media.root').to(...filePath), + })); // Same dealio for images. Since just about any image can be embedded and // we can't super easily know which ones are referenced at runtime, just // cheat and get file sizes for all images under media. (This includes // additional files which are images.) + const imageFilePaths = await traverse(mediaPath, { pathStyle: 'device', -- cgit 1.3.0-6-gf8a5