diff options
Diffstat (limited to 'src/write')
-rw-r--r-- | src/write/bind-utilities.js | 6 | ||||
-rw-r--r-- | src/write/build-modes/live-dev-server.js | 42 | ||||
-rw-r--r-- | src/write/build-modes/repl.js | 14 | ||||
-rw-r--r-- | src/write/build-modes/static-build.js | 13 |
4 files changed, 62 insertions, 13 deletions
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, diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index f6eec334..dd29c93e 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -5,7 +5,9 @@ import * as path from 'node:path'; import {pipeline} from 'node:stream/promises'; import {inspect as nodeInspect} from 'node:util'; -import {ENABLE_COLOR, colors, logInfo, logWarn, progressCallAll} from '#cli'; +import {openAggregate} from '#aggregate'; +import {ENABLE_COLOR, colors, fileIssue, logInfo, logWarn, progressCallAll} + from '#cli'; import {watchContentDependencies} from '#content-dependencies'; import {quickEvaluate} from '#content-function'; import * as html from '#html'; @@ -165,21 +167,47 @@ export async function go({ const commonUtilities = {...universalUtilities}; + const pathAggregate = openAggregate({message: `Errors computing page paths`}); + let targetSpecPairs = getPageSpecsWithTargets({wikiData}); - const pages = progressCallAll(`Computing page data & paths for ${targetSpecPairs.length} targets.`, + const pages = progressCallAll(`Computing page paths for ${targetSpecPairs.length} targets.`, targetSpecPairs.flatMap(({ pageSpec, target, targetless, }) => () => { - if (targetless) { - const result = pageSpec.pathsTargetless({wikiData}); - return Array.isArray(result) ? result : [result]; - } else { - return pageSpec.pathsForTarget(target); + try { + if (targetless) { + const result = pageSpec.pathsTargetless({wikiData}); + return Array.isArray(result) ? result : [result]; + } else { + return pageSpec.pathsForTarget(target); + } + } catch (caughtError) { + if (targetless) { + pathAggregate.push(new Error( + `Failed to compute targetless paths for ` + + inspect(pageSpec, {compact: true}), + {cause: caughtError})); + } else { + pathAggregate.push(new Error( + `Failed to compute paths for ` + + inspect(target), + {cause: caughtError})); + } + return []; } })).flat(); + try { + pathAggregate.close(); + } catch (error) { + niceShowAggregate(error); + logWarn`Failed to compute page paths for some targets.`; + logWarn`This means some pages that normally exist will be 404s.`; + fileIssue(); + } + logInfo`Will be serving a total of ${pages.length} pages.`; const urlToPageMap = Object.fromEntries(pages diff --git a/src/write/build-modes/repl.js b/src/write/build-modes/repl.js index 957d2c2d..920ad9f7 100644 --- a/src/write/build-modes/repl.js +++ b/src/write/build-modes/repl.js @@ -36,6 +36,7 @@ import * as path from 'node:path'; import * as repl from 'node:repl'; import _find, {bindFind} from '#find'; +import _reverse, {bindReverse} from '#reverse'; import CacheableObject from '#cacheable-object'; import {logWarn} from '#cli'; import {debugComposite} from '#composite'; @@ -66,6 +67,15 @@ export async function getContextAssignments({ logWarn`\`find\` variable will be missing`; } + let reverse; + try { + reverse = bindReverse(wikiData); + } catch (error) { + console.error(error); + logWarn`Failed to prepare wikiData-bound reverse() functions`; + logWarn`\`reverse\` variable will be missing`; + } + const replContext = { universalUtilities, ...universalUtilities, @@ -95,6 +105,10 @@ export async function getContextAssignments({ find, bindFind, + _reverse, + reverse, + bindReverse, + showAggregate, }; diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index d40e1cb7..3d3c779b 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -27,6 +27,7 @@ import { } from '#cli'; import { + getOrigin, getPagePathname, getURLsFrom, getURLsFromRoot, @@ -436,12 +437,18 @@ async function writePage({ ].filter(Boolean)); } +function filterNoOrigin(route) { + return !getOrigin(route.to); +} + function writeWebRouteSymlinks({ outputPath, webRoutes, }) { const symlinkRoutes = - webRoutes.filter(route => route.statically === 'symlink'); + webRoutes + .filter(route => route.statically === 'symlink') + .filter(filterNoOrigin); const promises = symlinkRoutes.map(async route => { @@ -481,7 +488,9 @@ async function writeWebRouteCopies({ webRoutes, }) { const copyRoutes = - webRoutes.filter(route => route.statically === 'copy'); + webRoutes + .filter(route => route.statically === 'copy') + .filter(filterNoOrigin); const promises = copyRoutes.map(async route => { |