« get me outta code hell

Merge branch 'url-special-chars' into data-steps - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-07-14 12:45:07 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-14 12:45:07 -0300
commitb34828921179b53434db4fa93a72dd52e5f72fa5 (patch)
tree94ee7fb4e49b06c683506c1566f1c4720a3cfbe5 /src
parent6f1d669e88cf0d92d73267291e2f70138e965c1f (diff)
parentd3315efaf0cfb481fa32a8ea1739431f32aa1a98 (diff)
Merge branch 'url-special-chars' into data-steps
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generatePageLayout.js6
-rw-r--r--src/content/dependencies/linkExternalAsIcon.js2
-rw-r--r--src/url-spec.js4
-rw-r--r--src/util/html.js8
-rw-r--r--src/util/urls.js19
5 files changed, 21 insertions, 18 deletions
diff --git a/src/content/dependencies/generatePageLayout.js b/src/content/dependencies/generatePageLayout.js
index d297a5f2..794b430b 100644
--- a/src/content/dependencies/generatePageLayout.js
+++ b/src/content/dependencies/generatePageLayout.js
@@ -509,7 +509,7 @@ export default {
 
             html.tag('link', {
               rel: 'stylesheet',
-              href: to('shared.staticFile', `site4.css?${cachebust}`),
+              href: to('shared.staticFile', 'site4.css', cachebust),
             }),
 
             html.tag('style', [
@@ -520,7 +520,7 @@ export default {
             ]),
 
             html.tag('script', {
-              src: to('shared.staticFile', `lazy-loading.js?${cachebust}`),
+              src: to('shared.staticFile', 'lazy-loading.js', cachebust),
             }),
           ]),
 
@@ -537,7 +537,7 @@ export default {
 
               html.tag('script', {
                 type: 'module',
-                src: to('shared.staticFile', `client.js?${cachebust}`),
+                src: to('shared.staticFile', 'client.js', cachebust),
               }),
             ]),
         ])
diff --git a/src/content/dependencies/linkExternalAsIcon.js b/src/content/dependencies/linkExternalAsIcon.js
index 6496d026..cd168992 100644
--- a/src/content/dependencies/linkExternalAsIcon.js
+++ b/src/content/dependencies/linkExternalAsIcon.js
@@ -39,7 +39,7 @@ export default {
       html.tag('svg', [
         html.tag('title', msg),
         html.tag('use', {
-          href: to('shared.staticFile', `icons.svg#icon-${id}`),
+          href: to('shared.staticIcon', id),
         }),
       ]));
   },
diff --git a/src/url-spec.js b/src/url-spec.js
index 0af613cc..d1e347e5 100644
--- a/src/url-spec.js
+++ b/src/url-spec.js
@@ -60,7 +60,9 @@ const urlSpec = {
       staticRoot: 'static',
 
       utilityFile: 'util/<>',
-      staticFile: 'static/<>',
+      staticFile: 'static/<>?<>',
+
+      staticIcon: 'static/icons.svg#icon-<>',
     },
   },
 
diff --git a/src/util/html.js b/src/util/html.js
index f2456565..2468b8db 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -475,14 +475,6 @@ export class Attributes {
           throw new Error(`Attribute value for ${key} should be primitive or array, got ${typeof val}`);
       })
       .filter(([_key, _val, keep]) => keep)
-      .map(([key, val]) => {
-        switch (key) {
-          case 'href':
-            return [key, encodeURI(val)];
-          default:
-            return [key, val];
-        }
-      })
       .map(([key, val]) =>
         typeof val === 'boolean'
           ? `${key}`
diff --git a/src/util/urls.js b/src/util/urls.js
index c2119b8d..4d099acd 100644
--- a/src/util/urls.js
+++ b/src/util/urls.js
@@ -79,16 +79,25 @@ export function generateURLs(urlSpec) {
     );
 
     const toHelper =
-      (delimiterMode) =>
+      ({device}) =>
       (key, ...args) => {
         const {
-          value: {[delimiterMode]: template},
+          value: {
+            [device ? 'device' : 'posix']: template,
+          },
         } = getValueForFullKey(relative, key);
 
         let missing = 0;
         let result = template.replaceAll(/<([0-9]+)>/g, (match, n) => {
           if (n < args.length) {
-            return args[n];
+            const value = args[n];
+            if (device) {
+              return value;
+            } else {
+              let encoded = encodeURIComponent(value);
+              encoded = encoded.replaceAll('%2F', '/');
+              return encoded;
+            }
           } else {
             missing++;
           }
@@ -106,8 +115,8 @@ export function generateURLs(urlSpec) {
       };
 
     return {
-      to: toHelper('posix'),
-      toDevice: toHelper('device'),
+      to: toHelper({device: false}),
+      toDevice: toHelper({device: true}),
     };
   };