« get me outta code hell

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:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/urls.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/util/urls.js b/src/util/urls.js
index f0f9cdb1..5f1d6eb0 100644
--- a/src/util/urls.js
+++ b/src/util/urls.js
@@ -48,8 +48,12 @@ export function generateURLs(urlSpec) {
                 target = rebasePrefix + (toGroup.prefix || '') + target;
             }
 
-            return (path.relative(fromPath, target)
-                + (toPath.endsWith('/') ? '/' : ''));
+            const suffix = (toPath.endsWith('/') ? '/' : '');
+
+            return {
+                posix: path.posix.relative(fromPath, target) + suffix,
+                device: path.relative(fromPath, target) + suffix
+            };
         };
 
         const groupSymbol = Symbol();
@@ -63,8 +67,12 @@ export function generateURLs(urlSpec) {
         const relative = withEntries(urlSpec, entries => entries
             .map(([key, urlGroup]) => [key, groupHelper(urlGroup)]));
 
-        const to = (key, ...args) => {
-            const { value: template, group: {[groupSymbol]: toGroup} } = getValueForFullKey(relative, key)
+        const toHelper = (delimiterMode) => (key, ...args) => {
+            const {
+                value: {[delimiterMode]: template},
+                group: {[groupSymbol]: toGroup}
+            } = getValueForFullKey(relative, key);
+
             let result = template.replaceAll(/<([0-9]+)>/g, (match, n) => args[n]);
 
             // Kinda hacky lol, 8ut it works.
@@ -76,7 +84,10 @@ export function generateURLs(urlSpec) {
             return result;
         };
 
-        return {to, relative};
+        return {
+            to: toHelper('posix'),
+            toDevice: toHelper('device')
+        };
     };
 
     const generateFrom = () => {