From 592acc152dc68e0f24300c090c9eabb9f21cef6b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 19:32:22 -0400 Subject: remove output-specific getPagePaths util --- src/util/urls.js | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'src/util/urls.js') diff --git a/src/util/urls.js b/src/util/urls.js index 4672c6a2..a74e0dfb 100644 --- a/src/util/urls.js +++ b/src/util/urls.js @@ -238,36 +238,3 @@ export function getPagePathname({ 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 = getPagePathname({ - baseDirectory, - device: true, - fullKey, - urlArgs, - urls, - }); - - const outputDirectory = path.join(outputPath, pathname); - - const output = { - directory: outputDirectory, - documentHTML: path.join(outputDirectory, 'index.html'), - oEmbedJSON: path.join(outputDirectory, 'oembed.json'), - }; - - return { - urlPath: [fullKey, ...urlArgs], - - output, - pathname, - }; -} -- cgit 1.3.0-6-gf8a5 From e06292fe8e7d789d38ac43fd9eee6816e39e18fe Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 19:45:13 -0400 Subject: extract fn for localizedPathnames --- src/util/urls.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/util/urls.js') diff --git a/src/util/urls.js b/src/util/urls.js index a74e0dfb..ead6c769 100644 --- a/src/util/urls.js +++ b/src/util/urls.js @@ -233,6 +233,29 @@ export function getPagePathname({ ...urlArgs)); } +export function getPagePathnameAcrossLanguages({ + defaultLanguage, + languages, + pageSubKey, + urlArgs, + urls, +}) { + return withEntries(languages, entries => entries + .filter(([key, language]) => key !== 'default' && !language.hidden) + .map(([_key, language]) => [ + language.code, + getPagePathname({ + baseDirectory: + (language === defaultLanguage + ? '' + : language.code), + fullKey: 'localized.' + pageSubKey, + urlArgs, + urls, + }), + ])); +} + // 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}) { -- cgit 1.3.0-6-gf8a5 From fd59ddd05bdfebf2f9a55a0fa5915485929e7de6 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 19:54:10 -0400 Subject: don't pass around fullKey where unneeded --- src/util/urls.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/util/urls.js') diff --git a/src/util/urls.js b/src/util/urls.js index ead6c769..0733ce04 100644 --- a/src/util/urls.js +++ b/src/util/urls.js @@ -213,24 +213,14 @@ export function getURLsFromRoot({ export function getPagePathname({ baseDirectory, device = false, - fullKey, + pageSubKey, urlArgs, urls, }) { - const [groupKey, subKey] = fullKey.split('.'); - - const toKey = device ? 'toDevice' : 'to'; - - return (groupKey === 'localized' && baseDirectory - ? urls - .from('shared.root')[toKey]( - 'localizedWithBaseDirectory.' + subKey, - baseDirectory, - ...urlArgs) - : urls - .from('shared.root')[toKey]( - fullKey, - ...urlArgs)); + const to = urls.from('shared.root')[device ? 'toDevice' : 'to']; + return (baseDirectory + ? to('localizedWithBaseDirectory.' + pageSubKey, baseDirectory, ...urlArgs) + : to('localized.' + pageSubKey, ...urlArgs)); } export function getPagePathnameAcrossLanguages({ @@ -249,7 +239,7 @@ export function getPagePathnameAcrossLanguages({ (language === defaultLanguage ? '' : language.code), - fullKey: 'localized.' + pageSubKey, + pageSubKey, urlArgs, urls, }), -- cgit 1.3.0-6-gf8a5 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/urls.js') 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 From ba8a441f95481e294d414a0c89e2513f82f45a7a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 20:28:22 -0400 Subject: compute subdirectoryPrefix internally --- src/util/urls.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/util/urls.js') diff --git a/src/util/urls.js b/src/util/urls.js index 1c7d1c58..c2119b8d 100644 --- a/src/util/urls.js +++ b/src/util/urls.js @@ -140,20 +140,16 @@ export const thumb = { // Makes the generally-used and wiki-specialized "to" page utility. // "to" returns a relative path from the current page to the target. export function getURLsFrom({ - urls, - baseDirectory, pagePath, - subdirectoryPrefix, + urls, }) { const pageSubKey = pagePath[0]; + const subdirectoryPrefix = getPageSubdirectoryPrefix({pagePath}); return (targetFullKey, ...args) => { const [groupKey, subKey] = targetFullKey.split('.'); - let path = subdirectoryPrefix; - - let from; - let to; + let from, to; // When linking to *outside* the localized area of the site, we need to // make sure the result is correctly relative to the 8ase directory. @@ -182,9 +178,9 @@ export function getURLsFrom({ to = targetFullKey; } - path += urls.from(from).to(to, ...args); - - return path; + return ( + subdirectoryPrefix + + urls.from(from).to(to, ...args)); }; } -- cgit 1.3.0-6-gf8a5