From 594e8dd46f9e6cc74c680536a1d820eef27133f0 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 9 Jan 2023 21:07:16 -0400 Subject: most essential behavior for live-dev-server --- src/util/urls.js | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'src/util') diff --git a/src/util/urls.js b/src/util/urls.js index f05f134b..69ff1d7e 100644 --- a/src/util/urls.js +++ b/src/util/urls.js @@ -142,11 +142,11 @@ export function getURLsFrom({ baseDirectory, pageSubKey, - paths, + subdirectoryPrefix, }) { return (targetFullKey, ...args) => { const [groupKey, subKey] = targetFullKey.split('.'); - let path = paths.subdirectoryPrefix; + let path = subdirectoryPrefix; let from; let to; @@ -184,32 +184,47 @@ export function getURLsFrom({ }; } -export function getPagePaths({ - outputPath, +export function getPagePathname({ + baseDirectory, + fullKey, + urlArgs, urls, +}) { + const [groupKey, subKey] = fullKey.split('.'); + return (groupKey === 'localized' && baseDirectory + ? urls + .from('shared.root') + .toDevice( + 'localizedWithBaseDirectory.' + subKey, + baseDirectory, + ...urlArgs) + : urls + .from('shared.root') + .toDevice(fullKey, ...urlArgs)); +} + +// Needed for the rare path arguments which themselves contains one or more +// slashes, e.g. for listings, with arguments like 'albums/by-name'. +export function getPageSubdirectoryPrefix({urlArgs}) { + return '../'.repeat(urlArgs.join('/').split('/').length - 1); +} + +export function getPagePaths({ baseDirectory, fullKey, + outputPath, urlArgs, + urls, }) { const [groupKey, subKey] = fullKey.split('.'); - const pathname = - groupKey === 'localized' && baseDirectory - ? urls - .from('shared.root') - .toDevice( - 'localizedWithBaseDirectory.' + subKey, - baseDirectory, - ...urlArgs) - : urls - .from('shared.root') - .toDevice(fullKey, ...urlArgs); - - // Needed for the rare path arguments which themselves contains one or more - // slashes, e.g. for listings, with arguments like 'albums/by-name'. - const subdirectoryPrefix = - '../'.repeat(urlArgs.join('/').split('/').length - 1); + const pathname = getPagePathname({ + baseDirectory, + fullKey, + urlArgs, + urls, + }); const outputDirectory = path.join(outputPath, pathname); @@ -224,6 +239,5 @@ export function getPagePaths({ output, pathname, - subdirectoryPrefix, }; } -- cgit 1.3.0-6-gf8a5