« get me outta code hell

remove a bunch of dead util files - 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-08-19 12:35:02 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-19 12:36:14 -0300
commit37ef3f288fce9bd65a2cd86107239e22f977e78d (patch)
tree74935fc783e0cfc6d3afecae76a59ffec8527206 /src
parent4e3dfc18f982b5723fbe086e325788d5c9edbf63 (diff)
remove a bunch of dead util files
Diffstat (limited to 'src')
-rw-r--r--src/listing-spec.js2
-rw-r--r--src/misc-templates.js122
-rwxr-xr-xsrc/upd8.js1
-rw-r--r--src/util/link.js253
-rw-r--r--src/util/magic-constants.js9
-rw-r--r--src/util/urls.js4
6 files changed, 0 insertions, 391 deletions
diff --git a/src/listing-spec.js b/src/listing-spec.js
index 402cb6fd..1e21baa1 100644
--- a/src/listing-spec.js
+++ b/src/listing-spec.js
@@ -1,5 +1,3 @@
-import {OFFICIAL_GROUP_DIRECTORY} from './util/magic-constants.js';
-
 import {
   accumulateSum,
   empty,
diff --git a/src/misc-templates.js b/src/misc-templates.js
deleted file mode 100644
index ba1a60f1..00000000
--- a/src/misc-templates.js
+++ /dev/null
@@ -1,122 +0,0 @@
-// Miscellaneous utility functions which are useful across page specifications.
-// These are made available right on a page spec's ({wikiData, language, ...})
-// args object!
-
-import T from './data/things/index.js';
-
-import {
-  empty,
-  repeat,
-  unique,
-} from './util/sugar.js';
-
-import {thumb} from './util/urls.js';
-
-import {
-  getTotalDuration,
-  sortAlbumsTracksChronologically,
-  sortChronologically,
-} from './util/wiki-data.js';
-
-// Grids
-
-function unbound_getGridHTML({
-  img,
-  html,
-  language,
-
-  getRevealStringFromArtTags,
-
-  entries,
-  srcFn,
-  linkFn,
-  noSrcTextFn = () => '',
-  altFn = () => '',
-  detailsFn = null,
-  lazy = true,
-}) {
-  return entries
-    .map(({large, item}, i) =>
-      linkFn(item, {
-        class: ['grid-item', 'box', large && 'large-grid-item'],
-        text: html.fragment([
-          img({
-            src: srcFn(item),
-            alt: altFn(item),
-            thumb: 'medium',
-            lazy: typeof lazy === 'number' ? i >= lazy : lazy,
-            square: true,
-            reveal: getRevealStringFromArtTags(item.artTags, {language}),
-            noSrcText: noSrcTextFn(item),
-          }),
-          html.tag('span', item.name),
-          detailsFn &&
-            html.tag('span', detailsFn(item)),
-        ]),
-      }))
-    .join('\n');
-}
-
-function unbound_getAlbumGridHTML({
-  getAlbumCover,
-  getGridHTML,
-  link,
-  language,
-  details = false,
-  ...props
-}) {
-  return getGridHTML({
-    srcFn: getAlbumCover,
-    linkFn: link.album,
-    detailsFn:
-      details &&
-      ((album) =>
-        language.$('misc.albumGrid.details', {
-          tracks: language.countTracks(album.tracks.length, {unit: true}),
-          time: language.formatDuration(getTotalDuration(album.tracks)),
-        })),
-    noSrcTextFn: (album) =>
-      language.$('misc.albumGrid.noCoverArt', {
-        album: album.name,
-      }),
-    ...props,
-  });
-}
-
-function unbound_getFlashGridHTML({
-  link,
-
-  getFlashCover,
-  getGridHTML,
-  ...props
-}) {
-  return getGridHTML({
-    srcFn: getFlashCover,
-    linkFn: link.flash,
-    ...props,
-  });
-}
-
-// Carousel reels
-
-function unbound_getCarouselHTML({
-  html,
-  img,
-
-  items,
-  lazy = false,
-
-  altFn = () => '',
-  linkFn = (x, {text}) => text,
-  srcFn,
-}) {
-}
-
-// Exports
-
-export {
-  unbound_getGridHTML as getGridHTML,
-  unbound_getAlbumGridHTML as getAlbumGridHTML,
-  unbound_getFlashGridHTML as getFlashGridHTML,
-  unbound_getCarouselHTML as getCarouselHTML,
-}
diff --git a/src/upd8.js b/src/upd8.js
index 1e52c555..f5781272 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -60,7 +60,6 @@ import {
   WIKI_INFO_FILE,
 } from './data/yaml.js';
 
-import link from './util/link.js';
 import {isMain, traverse} from './util/node-utils.js';
 import {empty, showAggregate, withEntries} from './util/sugar.js';
 import {generateURLs} from './util/urls.js';
diff --git a/src/util/link.js b/src/util/link.js
deleted file mode 100644
index a9f79c8b..00000000
--- a/src/util/link.js
+++ /dev/null
@@ -1,253 +0,0 @@
-// 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")
-// and return actual <a href> HTML link tags.
-//
-// The functions we're cre8ting here (all factory-style) take a "to" argument,
-// which is roughly a function which takes a urlSpec key and spits out a path
-// to 8e stuck in an href or src or suchever. There are also a few other
-// 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 T from '../data/things/index.js';
-
-export function unbound_getLinkThemeString(color, {
-  getColors,
-}) {
-  if (!color) return '';
-
-  const {primary, dim} = getColors(color);
-  return `--primary-color: ${primary}; --dim-color: ${dim}`;
-}
-
-const appendIndexHTMLRegex = /^(?!https?:\/\/).+\/$/;
-
-function linkHelper({
-  path: pathOption,
-
-  expectThing = true,
-  color: colorOption = true,
-
-  attr: attrOption = null,
-  data: dataOption = null,
-  text: textOption = null,
-}) {
-  const generateLink = (data, {
-    getLinkThemeString,
-    to,
-
-    text = '',
-    attributes = null,
-    class: className = '',
-    color = true,
-    hash = '',
-    preferShortName = false,
-  }) => {
-    const path = (expectThing ? pathOption(data) : pathOption());
-    let href = to(...path);
-
-    if (link.globalOptions.appendIndexHTML) {
-      if (appendIndexHTMLRegex.test(href)) {
-        href += 'index.html';
-      }
-    }
-
-    if (hash) {
-      href += (hash.startsWith('#') ? '' : '#') + hash;
-    }
-
-    return html.tag('a',
-      {
-        ...(attrOption ? attrOption(data) : {}),
-        ...(attributes ? attributes : {}),
-        href,
-        style:
-          typeof color === 'string'
-            ? getLinkThemeString(color)
-            : color && colorOption
-            ? getLinkThemeString(data.color)
-            : '',
-        class: className,
-      },
-
-      (text ||
-        (textOption
-          ? textOption(data)
-          : (preferShortName
-              ? data.nameShort ?? data.name
-              : data.name))));
-  };
-
-  generateLink.data = thing => {
-    if (!expectThing) {
-      throw new Error(`This kind of link doesn't need any data serialized`);
-    }
-
-    const data = (dataOption ? dataOption(thing) : {});
-
-    if (colorOption) {
-      data.color = thing.color;
-    }
-
-    if (!textOption) {
-      data.name = thing.name;
-      data.nameShort = thing.nameShort ?? thing.name;
-    }
-
-    return data;
-  };
-
-  return generateLink;
-}
-
-function linkDirectory(key, {
-  exposeDirectory = null,
-  prependLocalized = true,
-
-  data = null,
-  attr = null,
-  ...conf
-} = {}) {
-  return linkHelper({
-    data: thing => ({
-      ...(data ? data(thing) : {}),
-      directory: thing.directory,
-    }),
-
-    path: data =>
-      (prependLocalized
-        ? ['localized.' + key, data.directory]
-        : [key, data.directory]),
-
-    attr: (data) => ({
-      ...(attr ? attr(data) : {}),
-      ...(exposeDirectory ? {[exposeDirectory]: data.directory} : {}),
-    }),
-
-    ...conf,
-  });
-}
-
-function linkIndex(key, conf) {
-  return linkHelper({
-    path: () => [key],
-
-    expectThing: false,
-    ...conf,
-  });
-}
-
-function linkAdditionalFile(key, conf) {
-  return linkHelper({
-    data: ({file, album}) => ({
-      directory: album.directory,
-      file,
-    }),
-
-    path: data => ['media.albumAdditionalFile', data.directory, data.file],
-
-    color: false,
-    ...conf,
-  });
-}
-
-// Mapping of Thing constructor classes to the key for a link.x() function.
-// These represent a sensible "default" link, i.e. to the primary page for
-// the given thing based on what it's an instance of. This is used for the
-// link.anything() function.
-const linkAnythingMapping = [
-  [T.Album, 'album'],
-  [T.Artist, 'artist'],
-  [T.ArtTag, 'tag'],
-  [T.Flash, 'flash'],
-  [T.Group, 'groupInfo'],
-  [T.NewsEntry, 'newsEntry'],
-  [T.StaticPage, 'staticPage'],
-  [T.Track, 'track'],
-];
-
-const link = {
-  globalOptions: {
-    // This should usually only 8e used during development! It'll take any
-    // href that ends with `/` and append `index.html` to the returned
-    // value (for to.thing() functions). This is handy when developing
-    // without a local server (i.e. using file:// protocol URLs in your
-    // we8 8rowser), 8ut isn't guaranteed to 8e 100% 8ug-free.
-    appendIndexHTML: false,
-  },
-
-  album: linkDirectory('album'),
-  albumAdditionalFile: linkAdditionalFile('albumAdditionalFile'),
-  albumGallery: linkDirectory('albumGallery'),
-  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', {exposeDirectory: 'data-track'}),
-
-  media: linkDirectory('media.path', {
-    prependLocalized: false,
-    color: false,
-  }),
-
-  root: linkDirectory('shared.path', {
-    prependLocalized: false,
-    color: false,
-  }),
-  data: linkDirectory('data.path', {
-    prependLocalized: false,
-    color: false,
-  }),
-
-  site: linkDirectory('localized.path', {
-    prependLocalized: false,
-    color: false,
-  }),
-
-  // This is NOT an arrow functions because it should be callable for other
-  // "this" objects - i.e, if we bind arguments in other functions on the same
-  // link object, link.anything() should use those bound functions, not the
-  // original ones we're exporting here.
-  //
-  // This function has been through a lot of names:
-  //   - getHrefOfAnythingMan (2020-05-25)
-  //   - toAnythingMan (2021-03-02)
-  //   - linkAnythingMan (2021-05-14)
-  //   - link.anything (2022-09-15)
-  // ...And it'll probably end up being renamed yet again one day!
-  //
-  anything(...args) {
-    if (!this) {
-      throw new Error(`Missing value for \`this\` - investigate JS call stack`);
-    }
-
-    const [thing] = args;
-
-    for (const [constructor, fnKey] of linkAnythingMapping) {
-      if (thing instanceof constructor) {
-        return Reflect.apply(this[fnKey], this, args);
-      }
-    }
-
-    throw new Error(`Unrecognized type of thing for linking: ${thing}`);
-  },
-};
-
-export {
-  unbound_getLinkThemeString as getLinkThemeString,
-};
-
-export default link;
diff --git a/src/util/magic-constants.js b/src/util/magic-constants.js
deleted file mode 100644
index 83dd7db5..00000000
--- a/src/util/magic-constants.js
+++ /dev/null
@@ -1,9 +0,0 @@
-// Magic constants only! These are hard-coded, and any use of them should be
-// considered a flaw in the codebase - areas where we use hard-coded behavior
-// to support one use of the wiki software (i.e. HSMusic, usually), rather than
-// implementing the feature more generally/customizably.
-//
-// All such uses should eventually be replaced with better code in due time
-// (TM).
-
-export const OFFICIAL_GROUP_DIRECTORY = 'official';
diff --git a/src/util/urls.js b/src/util/urls.js
index bd3a349a..02961743 100644
--- a/src/util/urls.js
+++ b/src/util/urls.js
@@ -3,10 +3,6 @@
 // is in charge of pre-gener8ting a complete network of template strings
 // which can really quickly take su8stitute parameters to link from any one
 // place to another; 8ut there are also a few other utilities, too.
-//
-// Nota8ly, everything here is string-8ased, for gener8ting and transforming
-// actual path strings. More a8stract operations using wiki data o8jects is
-// the domain of link.js.
 
 import * as path from 'path';