From 98133431c801a823f3430b0e178c56350e12622c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 21 Aug 2023 22:14:34 -0300 Subject: write: static-build: gently log failed content functions & continue --- src/write/build-modes/static-build.js | 38 +++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'src/write') diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 2210dfe7..192b7966 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -17,6 +17,7 @@ import {serializeThings} from '#serialize'; import {empty, queue, withEntries} from '#sugar'; import { + fileIssue, logError, logInfo, logWarn, @@ -98,6 +99,7 @@ export async function go({ developersComment, getSizeOfAdditionalFile, getSizeOfImageFile, + niceShowAggregate, }) { const outputPath = cliOptions['out-path'] || process.env.HSMUSIC_OUT; const appendIndexHTML = cliOptions['append-index-html'] ?? false; @@ -253,6 +255,8 @@ export async function go({ )); */ + let errored = false; + const contentDependencies = await quickLoadContentDependencies(); const perLanguageFn = async (language, i, entries) => { @@ -303,14 +307,22 @@ export async function go({ wikiData, }); - const topLevelResult = - quickEvaluate({ - contentDependencies, - extraDependencies: {...bound, appendIndexHTML}, - - name: page.contentFunction.name, - args: page.contentFunction.args ?? [], - }); + let topLevelResult; + try { + topLevelResult = + quickEvaluate({ + contentDependencies, + extraDependencies: {...bound, appendIndexHTML}, + + name: page.contentFunction.name, + args: page.contentFunction.args ?? [], + }); + } catch (error) { + logError`\rError generating page: ${pathname}`; + niceShowAggregate(error); + errored = true; + return; + } const {pageHTML, oEmbedJSON} = html.resolve(topLevelResult); @@ -358,6 +370,16 @@ export async function go({ // The single most important step. logInfo`Written!`; + + if (errored) { + logWarn`The code generating content for some pages ended up erroring.`; + logWarn`These pages were skipped, so if you ran a build previously and`; + logWarn`they didn't error that time, then the old version is still`; + logWarn`available - albeit possibly outdated! Please scroll up and send`; + logWarn`the HSMusic developers a copy of the errors:`; + fileIssue({topMessage: null}); + } + return true; } -- cgit 1.3.0-6-gf8a5 From 5c2aca67db34301e4fb11c28b1b737e9e47c88ab Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 23 Aug 2023 18:35:33 -0300 Subject: write: live-dev-server: fix bad error response for data.json --- src/write/build-modes/live-dev-server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/write') diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index 2767a02f..28cf7a48 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -163,7 +163,7 @@ export async function go({ if (!quietResponses) console.log(`${requestHead} [200] /data.json`); } catch (error) { response.writeHead(500, contentTypeJSON); - response.end({error: `Internal error serializing wiki JSON`}); + response.end(`Internal error serializing wiki JSON`); console.error(`${requestHead} [500] /data.json`); showError(error); } -- cgit 1.3.0-6-gf8a5 From 029210cc329a015a939472a688209d3f3423242b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 30 May 2023 09:51:26 -0300 Subject: thumbs, content: integrate cached thumb sizes into content --- src/write/bind-utilities.js | 20 ++++++++++++++++++-- src/write/build-modes/live-dev-server.js | 10 ++++++---- src/write/build-modes/static-build.js | 6 ++++-- 3 files changed, 28 insertions(+), 8 deletions(-) (limited to 'src/write') diff --git a/src/write/bind-utilities.js b/src/write/bind-utilities.js index 8e2adea7..c32035f1 100644 --- a/src/write/bind-utilities.js +++ b/src/write/bind-utilities.js @@ -10,15 +10,22 @@ import * as html from '#html'; import {bindOpts} from '#sugar'; import {thumb} from '#urls'; +import { + getDimensionsOfImagePath, + getThumbnailEqualOrSmaller, + getThumbnailsAvailableForDimensions, +} from '#thumbs'; + export function bindUtilities({ absoluteTo, cachebust, defaultLanguage, getSizeOfAdditionalFile, - getSizeOfImageFile, + getSizeOfImagePath, language, languages, pagePath, + thumbsCache, to, urls, wikiData, @@ -30,7 +37,8 @@ export function bindUtilities({ cachebust, defaultLanguage, getSizeOfAdditionalFile, - getSizeOfImageFile, + getSizeOfImagePath, + getThumbnailsAvailableForDimensions, html, language, languages, @@ -46,5 +54,13 @@ export function bindUtilities({ bound.find = bindFind(wikiData, {mode: 'warn'}); + bound.getDimensionsOfImagePath = + (imagePath) => + getDimensionsOfImagePath(imagePath, thumbsCache); + + bound.getThumbnailEqualOrSmaller = + (preferred, imagePath) => + getThumbnailEqualOrSmaller(preferred, imagePath, thumbsCache); + return bound; } diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index 28cf7a48..9889b3f0 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -59,13 +59,14 @@ export async function go({ defaultLanguage, languages, srcRootPath, + thumbsCache, urls, wikiData, cachebust, developersComment, getSizeOfAdditionalFile, - getSizeOfImageFile, + getSizeOfImagePath, niceShowAggregate, }) { const showError = (error) => { @@ -343,10 +344,11 @@ export async function go({ cachebust, defaultLanguage, getSizeOfAdditionalFile, - getSizeOfImageFile, + getSizeOfImagePath, language, languages, pagePath: servePath, + thumbsCache, to, urls, wikiData, @@ -367,10 +369,10 @@ export async function go({ response.writeHead(200, contentTypeHTML); response.end(pageHTML); } catch (error) { - response.writeHead(500, contentTypePlain); - response.end(`Error generating page, view server log for details\n`); console.error(`${requestHead} [500] ${pathname}`); showError(error); + response.writeHead(500, contentTypePlain); + response.end(`Error generating page, view server log for details\n`); } }); diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 192b7966..82a947c7 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -91,6 +91,7 @@ export async function go({ defaultLanguage, languages, srcRootPath, + thumbsCache, urls, urlSpec, wikiData, @@ -98,7 +99,7 @@ export async function go({ cachebust, developersComment, getSizeOfAdditionalFile, - getSizeOfImageFile, + getSizeOfImagePath, niceShowAggregate, }) { const outputPath = cliOptions['out-path'] || process.env.HSMUSIC_OUT; @@ -298,10 +299,11 @@ export async function go({ cachebust, defaultLanguage, getSizeOfAdditionalFile, - getSizeOfImageFile, + getSizeOfImagePath, language, languages, pagePath, + thumbsCache, to, urls, wikiData, -- cgit 1.3.0-6-gf8a5 From 7069268db096ab0aa7a8839a3594efb2d1be8f86 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 4 Sep 2023 20:46:58 -0300 Subject: thumbs: new check-has-thumbs util, others throw for missing info --- src/write/bind-utilities.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/write') diff --git a/src/write/bind-utilities.js b/src/write/bind-utilities.js index c32035f1..942cce89 100644 --- a/src/write/bind-utilities.js +++ b/src/write/bind-utilities.js @@ -11,6 +11,7 @@ import {bindOpts} from '#sugar'; import {thumb} from '#urls'; import { + checkIfImagePathHasCachedThumbnails, getDimensionsOfImagePath, getThumbnailEqualOrSmaller, getThumbnailsAvailableForDimensions, @@ -54,6 +55,10 @@ export function bindUtilities({ bound.find = bindFind(wikiData, {mode: 'warn'}); + bound.checkIfImagePathHasCachedThumbnails = + (imagePath) => + checkIfImagePathHasCachedThumbnails(imagePath, thumbsCache); + bound.getDimensionsOfImagePath = (imagePath) => getDimensionsOfImagePath(imagePath, thumbsCache); -- cgit 1.3.0-6-gf8a5 From 745322c71c2443a631533ad7ef651ea30ad87a7c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 8 Sep 2023 08:45:30 -0300 Subject: util: remove unused getPagePathnameAcrossLanguages util --- src/write/build-modes/live-dev-server.js | 8 -------- src/write/build-modes/static-build.js | 9 --------- 2 files changed, 17 deletions(-) (limited to 'src/write') diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index 9889b3f0..94f0962c 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -14,7 +14,6 @@ import {empty} from '#sugar'; import { getPagePathname, - getPagePathnameAcrossLanguages, getURLsFrom, getURLsFromRoot, } from '#urls'; @@ -332,13 +331,6 @@ export async function go({ return; } - const localizedPathnames = getPagePathnameAcrossLanguages({ - defaultLanguage, - languages, - pagePath: servePath, - urls, - }); - const bound = bindUtilities({ absoluteTo, cachebust, diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 82a947c7..c10342e9 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -21,13 +21,11 @@ import { logError, logInfo, logWarn, - progressCallAll, progressPromiseAll, } from '#cli'; import { getPagePathname, - getPagePathnameAcrossLanguages, getURLsFrom, getURLsFromRoot, } from '#urls'; @@ -270,13 +268,6 @@ export async function go({ ...pageWrites.map(page => () => { const pagePath = page.path; - const localizedPathnames = getPagePathnameAcrossLanguages({ - defaultLanguage, - languages, - pagePath, - urls, - }); - const pathname = getPagePathname({ baseDirectory, pagePath, -- cgit 1.3.0-6-gf8a5 From 21a270ca6efa561cad3e87048cf8deb8a166d55f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 8 Sep 2023 08:51:20 -0300 Subject: fix miscellaneous eslint errors --- src/write/build-modes/live-dev-server.js | 1 - src/write/build-modes/static-build.js | 6 ------ 2 files changed, 7 deletions(-) (limited to 'src/write') diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index 94f0962c..644efdbc 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -10,7 +10,6 @@ import {quickEvaluate} from '#content-function'; import * as html from '#html'; import * as pageSpecs from '#page-specs'; import {serializeThings} from '#serialize'; -import {empty} from '#sugar'; import { getPagePathname, diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index c10342e9..6ef69759 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -91,7 +91,6 @@ export async function go({ srcRootPath, thumbsCache, urls, - urlSpec, wikiData, cachebust, @@ -469,14 +468,9 @@ async function writeFavicon({ } async function writeSharedFilesAndPages({ - language, outputPath, - urls, - wikiData, wikiDataJSON, }) { - const {groupData, wikiInfo} = wikiData; - return progressPromiseAll(`Writing files & pages shared across languages.`, [ wikiDataJSON && writeFile( -- cgit 1.3.0-6-gf8a5 From b19e165dc8ba13cd0e2d1862e645d34d86142566 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 11 Sep 2023 15:09:19 -0300 Subject: thumbs, infra: expose list of missing image paths --- src/write/bind-utilities.js | 2 ++ src/write/build-modes/live-dev-server.js | 2 ++ src/write/build-modes/static-build.js | 2 ++ 3 files changed, 6 insertions(+) (limited to 'src/write') diff --git a/src/write/bind-utilities.js b/src/write/bind-utilities.js index 942cce89..3d4ecc7a 100644 --- a/src/write/bind-utilities.js +++ b/src/write/bind-utilities.js @@ -25,6 +25,7 @@ export function bindUtilities({ getSizeOfImagePath, language, languages, + missingImagePaths, pagePath, thumbsCache, to, @@ -43,6 +44,7 @@ export function bindUtilities({ html, language, languages, + missingImagePaths, pagePath, thumb, to, diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index 9889b3f0..730686db 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -58,6 +58,7 @@ export async function go({ defaultLanguage, languages, + missingImagePaths, srcRootPath, thumbsCache, urls, @@ -347,6 +348,7 @@ export async function go({ getSizeOfImagePath, language, languages, + missingImagePaths, pagePath: servePath, thumbsCache, to, diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 82a947c7..79c8defd 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -90,6 +90,7 @@ export async function go({ defaultLanguage, languages, + missingImagePaths, srcRootPath, thumbsCache, urls, @@ -302,6 +303,7 @@ export async function go({ getSizeOfImagePath, language, languages, + missingImagePaths, pagePath, thumbsCache, to, -- cgit 1.3.0-6-gf8a5 From 97d9a13846654b8fa5b7520254f0f5ebc575305b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 2 Oct 2023 17:09:26 -0300 Subject: write: live-dev-server: default to quiet responses --- src/write/build-modes/live-dev-server.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/write') diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index 3986de32..d4efd177 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -42,8 +42,8 @@ export function getCLIOptions() { }, }, - 'quiet-responses': { - help: `Disables outputting [200] and [404] responses in the server log`, + 'loud-responses': { + help: `Enables outputting [200] and [404] responses in the server log, which are suppressed by default`, type: 'flag', }, }; @@ -78,7 +78,7 @@ export async function go({ const host = cliOptions['host'] ?? defaultHost; const port = parseInt(cliOptions['port'] ?? defaultPort); - const quietResponses = cliOptions['quiet-responses'] ?? false; + const loudResponses = cliOptions['loud-responses'] ?? false; const contentDependenciesWatcher = await watchContentDependencies(); const {contentDependencies} = contentDependenciesWatcher; @@ -160,7 +160,7 @@ export async function go({ }); response.writeHead(200, contentTypeJSON); response.end(json); - if (!quietResponses) console.log(`${requestHead} [200] /data.json`); + if (loudResponses) console.log(`${requestHead} [200] /data.json`); } catch (error) { response.writeHead(500, contentTypeJSON); response.end(`Internal error serializing wiki JSON`); @@ -256,7 +256,7 @@ export async function go({ await pipeline( createReadStream(filePath), response); - if (!quietResponses) console.log(`${requestHead} [200] ${pathname}`); + if (loudResponses) console.log(`${requestHead} [200] ${pathname}`); } catch (error) { response.writeHead(500, contentTypePlain); response.end(`Failed during file-to-response pipeline`); @@ -274,7 +274,7 @@ export async function go({ if (!Object.hasOwn(urlToPageMap, pathnameKey)) { response.writeHead(404, contentTypePlain); response.end(`No page found for: ${pathnameKey}\n`); - if (!quietResponses) console.log(`${requestHead} [404] ${pathname}`); + if (loudResponses) console.log(`${requestHead} [404] ${pathname}`); return; } @@ -358,7 +358,7 @@ export async function go({ const {pageHTML} = html.resolve(topLevelResult); - if (!quietResponses) console.log(`${requestHead} [200] ${pathname}`); + if (loudResponses) console.log(`${requestHead} [200] ${pathname}`); response.writeHead(200, contentTypeHTML); response.end(pageHTML); } catch (error) { @@ -388,8 +388,11 @@ export async function go({ server.on('listening', () => { logInfo`${'All done!'} Listening at: ${address}`; logInfo`Press ^C here (control+C) to stop the server and exit.`; - if (quietResponses) { - logInfo`Suppressing [200] and [404] response logging.`; + if (loudResponses) { + logInfo`Printing [200] and [404] responses.` + } else { + logInfo`Suppressing [200] and [404] response logging.` + logInfo`(Pass --loud-responses to show these.)`; } }); -- cgit 1.3.0-6-gf8a5 From 86068ab18e4a82754dbd055ebf21e3a1ec5ead07 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 11 Oct 2023 09:47:00 -0300 Subject: write: live-dev-server: end file responses less enthusiastically This seems to be a bit more reliable, although it'll probably take a little more memory while serving larger files. --- src/write/build-modes/live-dev-server.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/write') diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index d4efd177..1339c322 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -1,8 +1,6 @@ import * as http from 'node:http'; -import {createReadStream} from 'node:fs'; -import {stat} from 'node:fs/promises'; +import {readFile, stat} from 'node:fs/promises'; import * as path from 'node:path'; -import {pipeline} from 'node:stream/promises' import {logInfo, logWarn, progressCallAll} from '#cli'; import {watchContentDependencies} from '#content-dependencies'; @@ -224,7 +222,7 @@ export async function go({ 'gif': 'image/gif', 'ico': 'image/vnd.microsoft.icon', 'jpg': 'image/jpeg', - 'jpeg:': 'image/jpeg', + 'jpeg': 'image/jpeg', 'js': 'text/javascript', 'mjs': 'text/javascript', 'mp3': 'audio/mpeg', @@ -249,13 +247,12 @@ export async function go({ try { const {size} = await stat(filePath); + const buffer = await readFile(filePath) response.writeHead(200, contentType ? { 'Content-Type': contentType, 'Content-Length': size, } : {}); - await pipeline( - createReadStream(filePath), - response); + response.end(buffer); if (loudResponses) console.log(`${requestHead} [200] ${pathname}`); } catch (error) { response.writeHead(500, contentTypePlain); -- cgit 1.3.0-6-gf8a5