« get me outta code hell

real pragma, and some eslint fixes - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/link.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-06-26 18:02:27 -0300
committer(quasar) nebula <qznebula@protonmail.com>2022-06-26 18:02:27 -0300
commitc75b029160248b6935e5c0f5156cc7a870311e82 (patch)
tree693c5cca195e50b048b0086e768aa06a7c1986ee /src/util/link.js
parentf65e712fe8b8b1a196da2db286ebc6a5c9bf7433 (diff)
real pragma, and some eslint fixes
Diffstat (limited to 'src/util/link.js')
-rw-r--r--src/util/link.js94
1 files changed, 47 insertions, 47 deletions
diff --git a/src/util/link.js b/src/util/link.js
index 4095b17d..ee3579d5 100644
--- a/src/util/link.js
+++ b/src/util/link.js
@@ -1,5 +1,5 @@
-// @format
-//
+/** @format */
+
 // This file is essentially one level of a8straction a8ove urls.js (and the
 // urlSpec it gets its paths from). It's a 8unch of utility functions which
 // take certain types of wiki data o8jects (colloquially known as "things")
@@ -11,74 +11,74 @@
 // options availa8le in all the functions, making a common interface for
 // gener8ting just a8out any link on the site.
 
-import * as html from "./html.js";
-import { getColors } from "./colors.js";
+import * as html from './html.js';
+import {getColors} from './colors.js';
 
 export function getLinkThemeString(color) {
-  if (!color) return "";
+  if (!color) return '';
 
-  const { primary, dim } = getColors(color);
+  const {primary, dim} = getColors(color);
   return `--primary-color: ${primary}; --dim-color: ${dim}`;
 }
 
 const appendIndexHTMLRegex = /^(?!https?:\/\/).+\/$/;
 
 const linkHelper =
-  (hrefFn, { color = true, attr = null } = {}) =>
+  (hrefFn, {color = true, attr = null} = {}) =>
   (
     thing,
     {
       to,
-      text = "",
+      text = '',
       attributes = null,
-      class: className = "",
+      class: className = '',
       color: color2 = true,
-      hash = "",
+      hash = '',
     }
   ) => {
-    let href = hrefFn(thing, { to });
+    let href = hrefFn(thing, {to});
 
     if (link.globalOptions.appendIndexHTML) {
       if (appendIndexHTMLRegex.test(href)) {
-        href += "index.html";
+        href += 'index.html';
       }
     }
 
     if (hash) {
-      href += (hash.startsWith("#") ? "" : "#") + hash;
+      href += (hash.startsWith('#') ? '' : '#') + hash;
     }
 
     return html.tag(
-      "a",
+      'a',
       {
         ...(attr ? attr(thing) : {}),
         ...(attributes ? attributes : {}),
         href,
         style:
-          typeof color2 === "string"
+          typeof color2 === 'string'
             ? getLinkThemeString(color2)
             : color2 && color
             ? getLinkThemeString(thing.color)
-            : "",
+            : '',
         class: className,
       },
       text || thing.name
     );
   };
 
-const linkDirectory = (key, { expose = null, attr = null, ...conf } = {}) =>
-  linkHelper((thing, { to }) => to("localized." + key, thing.directory), {
+const linkDirectory = (key, {expose = null, attr = null, ...conf} = {}) =>
+  linkHelper((thing, {to}) => to('localized.' + key, thing.directory), {
     attr: (thing) => ({
       ...(attr ? attr(thing) : {}),
-      ...(expose ? { [expose]: thing.directory } : {}),
+      ...(expose ? {[expose]: thing.directory} : {}),
     }),
     ...conf,
   });
 
 const linkPathname = (key, conf) =>
-  linkHelper(({ directory: pathname }, { to }) => to(key, pathname), conf);
+  linkHelper(({directory: pathname}, {to}) => to(key, pathname), conf);
 const linkIndex = (key, conf) =>
-  linkHelper((_, { to }) => to("localized." + key), conf);
+  linkHelper((_, {to}) => to('localized.' + key), conf);
 
 const link = {
   globalOptions: {
@@ -90,50 +90,50 @@ const link = {
     appendIndexHTML: false,
   },
 
-  album: linkDirectory("album"),
-  albumCommentary: linkDirectory("albumCommentary"),
-  artist: linkDirectory("artist", { color: false }),
-  artistGallery: linkDirectory("artistGallery", { color: false }),
-  commentaryIndex: linkIndex("commentaryIndex", { color: false }),
-  flashIndex: linkIndex("flashIndex", { color: false }),
-  flash: linkDirectory("flash"),
-  groupInfo: linkDirectory("groupInfo"),
-  groupGallery: linkDirectory("groupGallery"),
-  home: linkIndex("home", { color: false }),
-  listingIndex: linkIndex("listingIndex"),
-  listing: linkDirectory("listing"),
-  newsIndex: linkIndex("newsIndex", { color: false }),
-  newsEntry: linkDirectory("newsEntry", { color: false }),
-  staticPage: linkDirectory("staticPage", { color: false }),
-  tag: linkDirectory("tag"),
-  track: linkDirectory("track", { expose: "data-track" }),
+  album: linkDirectory('album'),
+  albumCommentary: linkDirectory('albumCommentary'),
+  artist: linkDirectory('artist', {color: false}),
+  artistGallery: linkDirectory('artistGallery', {color: false}),
+  commentaryIndex: linkIndex('commentaryIndex', {color: false}),
+  flashIndex: linkIndex('flashIndex', {color: false}),
+  flash: linkDirectory('flash'),
+  groupInfo: linkDirectory('groupInfo'),
+  groupGallery: linkDirectory('groupGallery'),
+  home: linkIndex('home', {color: false}),
+  listingIndex: linkIndex('listingIndex'),
+  listing: linkDirectory('listing'),
+  newsIndex: linkIndex('newsIndex', {color: false}),
+  newsEntry: linkDirectory('newsEntry', {color: false}),
+  staticPage: linkDirectory('staticPage', {color: false}),
+  tag: linkDirectory('tag'),
+  track: linkDirectory('track', {expose: 'data-track'}),
 
   // TODO: This is a bit hacky. Files are just strings (not objects), so we
   // have to manually provide the album alongside the file. They also don't
   // follow the usual {name: whatever} type shape, so we have to provide that
   // ourselves.
   _albumAdditionalFileHelper: linkHelper(
-    (fakeFileObject, { to }) =>
+    (fakeFileObject, {to}) =>
       to(
-        "media.albumAdditionalFile",
+        'media.albumAdditionalFile',
         fakeFileObject.album.directory,
         fakeFileObject.name
       ),
-    { color: false }
+    {color: false}
   ),
-  albumAdditionalFile: ({ file, album }, { to }) =>
+  albumAdditionalFile: ({file, album}, {to}) =>
     link._albumAdditionalFileHelper(
       {
         name: file,
         album,
       },
-      { to }
+      {to}
     ),
 
-  media: linkPathname("media.path", { color: false }),
-  root: linkPathname("shared.path", { color: false }),
-  data: linkPathname("data.path", { color: false }),
-  site: linkPathname("localized.path", { color: false }),
+  media: linkPathname('media.path', {color: false}),
+  root: linkPathname('shared.path', {color: false}),
+  data: linkPathname('data.path', {color: false}),
+  site: linkPathname('localized.path', {color: false}),
 };
 
 export default link;