From 10e9059c502db6586826f7c29c2d483b553d24c6 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 4 Mar 2021 20:32:59 -0400 Subject: thumbnail support! contains a new gen-thumbs.js file, which can be run on its own and is automatically called from the main hsmusic cli tool as well; see this file for details! --- upd8.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'upd8.js') diff --git a/upd8.js b/upd8.js index 07aaa13..21f1605 100755 --- a/upd8.js +++ b/upd8.js @@ -115,6 +115,7 @@ const { joinNoOxford, mapInPlace, logWarn, + logInfo, logError, parseOptions, progressPromiseAll, @@ -126,6 +127,8 @@ const { unique } = require('./upd8-util'); +const genThumbs = require('./gen-thumbs'); + const C = require('./common/common'); const CACHEBUST = 3; @@ -263,6 +266,14 @@ const link = { site: linkPathname('site', {color: false}) }; +const thumbnailHelper = name => file => + file.replace(/\.(jpg|png)$/, name + '.jpg'); + +const thumb = { + medium: thumbnailHelper('.medium'), + small: thumbnailHelper('.small') +}; + function generateURLs(fromPath) { const helper = toPath => { let argIndex = 0; @@ -958,6 +969,7 @@ function transformMultiline(text, {strings, to}) { line = line.replace(//g, (match, attributes) => img({ lazy: true, link: true, + thumb: 'medium', ...parseAttributes(attributes, {to}) })); @@ -1878,6 +1890,7 @@ function attributes(attribs) { function img({ src = '', alt = '', + thumb: thumbKey = '', reveal = '', id = '', width = '', @@ -1889,6 +1902,9 @@ function img({ const willSquare = square; const willLink = typeof link === 'string' || link; + const originalSrc = src; + const thumbSrc = thumbKey ? thumb[thumbKey](src) : src; + const imgAttributes = attributes({ id: link ? '' : id, alt, @@ -1896,8 +1912,8 @@ function img({ height }); - const nonlazyHTML = wrap(``); - const lazyHTML = lazy && wrap(``, true); + const nonlazyHTML = wrap(``); + const lazyHTML = lazy && wrap(``, true); if (lazy) { return fixWS` @@ -1933,7 +1949,7 @@ function img({ if (willLink) { html = `${html}`; } @@ -2202,6 +2218,7 @@ function getGridHTML({ ${img({ src: srcFn(item), alt: altFn(item), + thumb: 'small', lazy: (typeof lazy === 'number' ? i >= lazy : lazy), square: true, reveal: getRevealString(item.artTags, {strings}) @@ -2534,6 +2551,7 @@ function generateCoverLink({ ${img({ src, alt, + thumb: 'medium', id: 'cover-art', link: true, square: true, @@ -5174,6 +5192,13 @@ async function main() { } } + logInfo`Begin thumbnail generation... -----+`; + const result = await genThumbs(mediaPath, {queueSize, quiet: true}); + logInfo`Done thumbnail generation! --------+`; + if (!result) { + return; + } + const defaultStrings = await processLanguageFile(path.join(__dirname, DEFAULT_STRINGS_FILE)); if (defaultStrings.error) { logError`Error loading default strings: ${defaultStrings.error}`; -- cgit 1.3.0-6-gf8a5