From 1ced8788ca64ed430fac003dc9281f7194193956 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 7 Jan 2023 20:31:16 -0400 Subject: extract getPagePaths, getURLsFrom functions towards basic dynamics pt. 1 (#124) --- src/util/urls.js | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'src/util/urls.js') diff --git a/src/util/urls.js b/src/util/urls.js index 1f9cd9c0..f05f134b 100644 --- a/src/util/urls.js +++ b/src/util/urls.js @@ -136,3 +136,94 @@ export const thumb = { medium: thumbnailHelper('.medium'), small: thumbnailHelper('.small'), }; + +export function getURLsFrom({ + urls, + + baseDirectory, + pageSubKey, + paths, +}) { + return (targetFullKey, ...args) => { + const [groupKey, subKey] = targetFullKey.split('.'); + let path = paths.subdirectoryPrefix; + + let from; + let 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. + if ( + groupKey !== 'localized' && + groupKey !== 'localizedDefaultLanguage' && + baseDirectory + ) { + from = 'localizedWithBaseDirectory.' + pageSubKey; + to = targetFullKey; + } else if (groupKey === 'localizedDefaultLanguage' && baseDirectory) { + // Special case for specifically linking *from* a page with base + // directory *to* a page without! Used for the language switcher and + // hopefully nothing else oh god. + from = 'localizedWithBaseDirectory.' + pageSubKey; + to = 'localized.' + subKey; + } else if (groupKey === 'localizedDefaultLanguage') { + // Linking to the default, except surprise, we're already IN the default + // (no baseDirectory set). + from = 'localized.' + pageSubKey; + to = 'localized.' + subKey; + } else { + // If we're linking inside the localized area (or there just is no + // 8ase directory), the 8ase directory doesn't matter. + from = 'localized.' + pageSubKey; + to = targetFullKey; + } + + path += urls.from(from).to(to, ...args); + + return path; + }; +} + +export function getPagePaths({ + outputPath, + urls, + + baseDirectory, + fullKey, + urlArgs, +}) { + 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 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, + subdirectoryPrefix, + }; +} -- cgit 1.3.0-6-gf8a5 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/urls.js') 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 From 091d5221948ca4a6decd091bc3a5e0063adf1443 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 9 Jan 2023 21:58:20 -0400 Subject: hopefully fix normal pages on windows --- src/util/urls.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/util/urls.js') diff --git a/src/util/urls.js b/src/util/urls.js index 69ff1d7e..78bcd200 100644 --- a/src/util/urls.js +++ b/src/util/urls.js @@ -186,22 +186,25 @@ export function getURLsFrom({ export function getPagePathname({ baseDirectory, + device = false, fullKey, urlArgs, urls, }) { const [groupKey, subKey] = fullKey.split('.'); + const toKey = device ? 'toDevice' : 'to'; + return (groupKey === 'localized' && baseDirectory ? urls - .from('shared.root') - .toDevice( + .from('shared.root')[toKey]( 'localizedWithBaseDirectory.' + subKey, baseDirectory, ...urlArgs) : urls - .from('shared.root') - .toDevice(fullKey, ...urlArgs)); + .from('shared.root')[toKey]( + fullKey, + ...urlArgs)); } // Needed for the rare path arguments which themselves contains one or more @@ -221,6 +224,7 @@ export function getPagePaths({ const pathname = getPagePathname({ baseDirectory, + device: true, fullKey, urlArgs, urls, -- cgit 1.3.0-6-gf8a5 From d442546057f8280a141d4aa54f633a09c429e2d3 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 16:55:04 -0400 Subject: extract absoluteTo --- src/util/urls.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/util/urls.js') diff --git a/src/util/urls.js b/src/util/urls.js index 78bcd200..4672c6a2 100644 --- a/src/util/urls.js +++ b/src/util/urls.js @@ -137,6 +137,8 @@ export const thumb = { small: thumbnailHelper('.small'), }; +// 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, @@ -184,6 +186,30 @@ export function getURLsFrom({ }; } +// Makes the generally-used and wiki-specialized "absoluteTo" page utility. +// "absoluteTo" returns an absolute path, starting at site root (/) leading +// to the target. +export function getURLsFromRoot({ + baseDirectory, + urls, +}) { + const from = urls.from('shared.root'); + + return (targetFullKey, ...args) => { + const [groupKey, subKey] = targetFullKey.split('.'); + return ( + '/' + + (groupKey === 'localized' && baseDirectory + ? from.to( + 'localizedWithBaseDirectory.' + subKey, + baseDirectory, + ...args + ) + : from.to(targetFullKey, ...args)) + ); + }; +} + export function getPagePathname({ baseDirectory, device = false, -- cgit 1.3.0-6-gf8a5