diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-01-21 07:10:34 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-01-21 07:11:15 -0400 |
commit | 288715112687d33c3193ebae469aaf7d01a52b6d (patch) | |
tree | ad88c8681143b4a09454a3340a23748ddb73636e /src | |
parent | 0807f466104c11033abe3e79c528cd409329415d (diff) |
upd8, content: preload all file sizes, straight-shot
Diffstat (limited to 'src')
-rw-r--r-- | src/content/dependencies/generateAlbumAdditionalFilesList.js | 6 | ||||
-rw-r--r-- | src/content/dependencies/image.js | 6 | ||||
-rwxr-xr-x | src/upd8.js | 74 | ||||
-rw-r--r-- | src/write/bind-utilities.js | 6 |
4 files changed, 19 insertions, 73 deletions
diff --git a/src/content/dependencies/generateAlbumAdditionalFilesList.js b/src/content/dependencies/generateAlbumAdditionalFilesList.js index 9818a43c..ad17206f 100644 --- a/src/content/dependencies/generateAlbumAdditionalFilesList.js +++ b/src/content/dependencies/generateAlbumAdditionalFilesList.js @@ -9,7 +9,7 @@ export default { 'transformContent', ], - extraDependencies: ['getSizeOfAdditionalFile', 'html', 'urls'], + extraDependencies: ['getSizeOfMediaFile', 'html', 'urls'], relations: (relation, album, additionalFiles) => ({ list: @@ -55,7 +55,7 @@ export default { showFileSizes: {type: 'boolean', default: true}, }, - generate: (data, relations, slots, {getSizeOfAdditionalFile, urls}) => + generate: (data, relations, slots, {getSizeOfMediaFile, urls}) => relations.list.slots({ chunks: stitchArrays({ @@ -86,7 +86,7 @@ export default { fileLink: fileLink, fileSize: (slots.showFileSizes - ? getSizeOfAdditionalFile( + ? getSizeOfMediaFile( urls .from('media.root') .to('media.albumAdditionalFile', data.albumDirectory, location)) diff --git a/src/content/dependencies/image.js b/src/content/dependencies/image.js index b1f02819..6cbcb7dd 100644 --- a/src/content/dependencies/image.js +++ b/src/content/dependencies/image.js @@ -5,7 +5,7 @@ export default { extraDependencies: [ 'checkIfImagePathHasCachedThumbnails', 'getDimensionsOfImagePath', - 'getSizeOfImagePath', + 'getSizeOfMediaFile', 'getThumbnailEqualOrSmaller', 'getThumbnailsAvailableForDimensions', 'html', @@ -83,7 +83,7 @@ export default { generate(data, relations, slots, { checkIfImagePathHasCachedThumbnails, getDimensionsOfImagePath, - getSizeOfImagePath, + getSizeOfMediaFile, getThumbnailEqualOrSmaller, getThumbnailsAvailableForDimensions, html, @@ -228,7 +228,7 @@ export default { const fileSize = (willLink && mediaSrc - ? getSizeOfImagePath(mediaSrc) + ? getSizeOfMediaFile(mediaSrc) : null); imgAttributes.add([ diff --git a/src/upd8.js b/src/upd8.js index 30f1b143..3628bff5 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -2555,12 +2555,10 @@ async function main() { } } - let getSizeOfAdditionalFile; - let getSizeOfImagePath; + let getSizeOfMediaFile; if (stepStatusSummary.preloadFileSizes.status === STATUS_NOT_APPLICABLE) { - getSizeOfAdditionalFile = () => null; - getSizeOfImagePath = () => null; + getSizeOfMediaFile = () => null; } else if (stepStatusSummary.preloadFileSizes.status === STATUS_NOT_STARTED) { Object.assign(stepStatusSummary.preloadFileSizes, { status: STATUS_STARTED_NOT_DONE, @@ -2569,51 +2567,11 @@ async function main() { const fileSizePreloader = new FileSizePreloader(); - // File sizes of additional files need to be precalculated before we can - // actually reference 'em in site building, so get those loading right - // away. We actually need to keep track of two things here - the on-device - // file paths we're actually reading, and the corresponding on-site media - // 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 albumAdditionalFilePaths = - wikiData.albumData.flatMap(album => - ([ - ...album.additionalFiles, - ...album.tracks.flatMap(track => [ - ...track.additionalFiles, - ...track.sheetMusicFiles, - ...track.midiProjectFiles, - ]), - ]).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(...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 = + const mediaFilePaths = await traverse(mediaPath, { pathStyle: 'device', filterDir: dir => dir !== '.git', - filterFile: file => - ['.png', '.gif', '.jpg'].includes(path.extname(file)) && - !isThumb(file), + filterFile: file => !isThumb(file), }).then(files => files .map(file => ({ device: file, @@ -2623,28 +2581,19 @@ async function main() { .to('media.path', path.relative(mediaPath, file).split(path.sep).join('/')), }))); - const getSizeOfMediaFileHelper = paths => (mediaPath) => { - const pair = paths.find(({media}) => media === mediaPath); + getSizeOfMediaFile = mediaPath => { + const pair = mediaFilePaths.find(({media}) => media === mediaPath); if (!pair) return null; return fileSizePreloader.getSizeOfPath(pair.device); }; - getSizeOfAdditionalFile = getSizeOfMediaFileHelper(additionalFilePaths); - getSizeOfImagePath = getSizeOfMediaFileHelper(imageFilePaths); + logInfo`Preloading file sizes for ${mediaFilePaths.length} media files...`; - logInfo`Preloading filesizes for ${additionalFilePaths.length} additional files...`; - - fileSizePreloader.loadPaths(...additionalFilePaths.map((path) => path.device)); - await fileSizePreloader.waitUntilDoneLoading(); - - logInfo`Preloading filesizes for ${imageFilePaths.length} full-resolution images...`; - paragraph = false; - - fileSizePreloader.loadPaths(...imageFilePaths.map((path) => path.device)); + fileSizePreloader.loadPaths(...mediaFilePaths.map(path => path.device)); await fileSizePreloader.waitUntilDoneLoading(); if (fileSizePreloader.hasErrored) { - logWarn`Some media files couldn't be read for preloading filesizes.`; + logWarn`Some media files couldn't be read for preloading file sizes.`; logWarn`This means the wiki won't display file sizes for these files.`; logWarn`Investigate missing or unreadable files to get that fixed!`; @@ -2655,7 +2604,7 @@ async function main() { memory: process.memoryUsage(), }); } else { - logInfo`Done preloading filesizes without any errors - nice!`; + logInfo`Done preloading file sizes without any errors - nice!`; paragraph = false; Object.assign(stepStatusSummary.preloadFileSizes, { @@ -2819,8 +2768,7 @@ async function main() { console.log(''); const universalUtilities = { - getSizeOfAdditionalFile, - getSizeOfImagePath, + getSizeOfMediaFile, defaultLanguage: finalDefaultLanguage, developersComment, diff --git a/src/write/bind-utilities.js b/src/write/bind-utilities.js index be702c8c..d55ab215 100644 --- a/src/write/bind-utilities.js +++ b/src/write/bind-utilities.js @@ -20,8 +20,7 @@ import { export function bindUtilities({ absoluteTo, defaultLanguage, - getSizeOfAdditionalFile, - getSizeOfImagePath, + getSizeOfMediaFile, language, languages, missingImagePaths, @@ -37,8 +36,7 @@ export function bindUtilities({ Object.assign(bound, { absoluteTo, defaultLanguage, - getSizeOfAdditionalFile, - getSizeOfImagePath, + getSizeOfMediaFile, getThumbnailsAvailableForDimensions, html, language, |