From 54ad9946e3fa32ae8388d54ec8b3baad78a29417 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 20:20:18 -0400 Subject: prefer passing around pagePath --- src/util/urls.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'src/util') diff --git a/src/util/urls.js b/src/util/urls.js index 0733ce04..1c7d1c58 100644 --- a/src/util/urls.js +++ b/src/util/urls.js @@ -143,9 +143,11 @@ export function getURLsFrom({ urls, baseDirectory, - pageSubKey, + pagePath, subdirectoryPrefix, }) { + const pageSubKey = pagePath[0]; + return (targetFullKey, ...args) => { const [groupKey, subKey] = targetFullKey.split('.'); let path = subdirectoryPrefix; @@ -193,19 +195,19 @@ export function getURLsFromRoot({ baseDirectory, urls, }) { - const from = urls.from('shared.root'); + const {to} = urls.from('shared.root'); return (targetFullKey, ...args) => { const [groupKey, subKey] = targetFullKey.split('.'); return ( '/' + (groupKey === 'localized' && baseDirectory - ? from.to( + ? to( 'localizedWithBaseDirectory.' + subKey, baseDirectory, ...args ) - : from.to(targetFullKey, ...args)) + : to(targetFullKey, ...args)) ); }; } @@ -213,21 +215,20 @@ export function getURLsFromRoot({ export function getPagePathname({ baseDirectory, device = false, - pageSubKey, - urlArgs, + pagePath, urls, }) { - const to = urls.from('shared.root')[device ? 'toDevice' : 'to']; + const {[device ? 'toDevice' : 'to']: to} = urls.from('shared.root'); + return (baseDirectory - ? to('localizedWithBaseDirectory.' + pageSubKey, baseDirectory, ...urlArgs) - : to('localized.' + pageSubKey, ...urlArgs)); + ? to('localizedWithBaseDirectory.' + pagePath[0], baseDirectory, ...pagePath.slice(1)) + : to('localized.' + pagePath[0], ...pagePath.slice(1))); } export function getPagePathnameAcrossLanguages({ defaultLanguage, languages, - pageSubKey, - urlArgs, + pagePath, urls, }) { return withEntries(languages, entries => entries @@ -239,8 +240,7 @@ export function getPagePathnameAcrossLanguages({ (language === defaultLanguage ? '' : language.code), - pageSubKey, - urlArgs, + pagePath, urls, }), ])); @@ -248,6 +248,13 @@ export function getPagePathnameAcrossLanguages({ // 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 getPageSubdirectoryPrefix({ + pagePath, +}) { + const timesNestedDeeply = (pagePath + .slice(1) // skip URL key, only check arguments + .join('/') + .split('/') + .length - 1); + return '../'.repeat(timesNestedDeeply); } -- cgit 1.3.0-6-gf8a5