« get me outta code hell

extract absoluteTo - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-01-10 16:55:04 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-01-10 16:55:04 -0400
commitd442546057f8280a141d4aa54f633a09c429e2d3 (patch)
treefa4ee7eb5716a06387aaf8734a2722646adcc54e /src/util
parent091d5221948ca4a6decd091bc3a5e0063adf1443 (diff)
extract absoluteTo
Diffstat (limited to 'src/util')
-rw-r--r--src/util/urls.js26
1 files changed, 26 insertions, 0 deletions
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,