From 0bb644e2a37ad63d86fe3b313d5f33059b3bdc43 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 1 Jan 2022 23:18:03 -0400 Subject: fix backwards slashes in hrefs on windows... ...while also not breaking the way we use the to() functions for actual output write paths! --- src/util/urls.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/util') diff --git a/src/util/urls.js b/src/util/urls.js index f0f9cdb..5f1d6eb 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 = () => { -- cgit 1.3.0-6-gf8a5