« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateStaticPage.js11
-rw-r--r--src/content/dependencies/transformContent.js11
-rw-r--r--src/data/composite/things/album/withTrackSections.js4
-rw-r--r--src/data/composite/things/album/withTracks.js4
-rw-r--r--src/data/things/album.js5
-rw-r--r--src/data/things/static-page.js1
-rw-r--r--src/data/things/track.js13
-rw-r--r--src/data/yaml.js12
-rw-r--r--src/static/client3.js92
-rw-r--r--src/util/sugar.js35
10 files changed, 71 insertions, 117 deletions
diff --git a/src/content/dependencies/generateStaticPage.js b/src/content/dependencies/generateStaticPage.js
index 3e27fd43..226152c7 100644
--- a/src/content/dependencies/generateStaticPage.js
+++ b/src/content/dependencies/generateStaticPage.js
@@ -1,5 +1,6 @@
 export default {
   contentDependencies: ['generatePageLayout', 'transformContent'],
+  extraDependencies: ['html'],
 
   relations(relation, staticPage) {
     return {
@@ -12,10 +13,11 @@ export default {
     return {
       name: staticPage.name,
       stylesheet: staticPage.stylesheet,
+      script: staticPage.script,
     };
   },
 
-  generate(data, relations) {
+  generate(data, relations, {html}) {
     return relations.layout
       .slots({
         title: data.name,
@@ -27,7 +29,12 @@ export default {
             : []),
 
         mainClasses: ['long-content'],
-        mainContent: relations.content,
+        mainContent: [
+          relations.content,
+
+          data.script &&
+            html.tag('script', data.script),
+        ],
 
         navLinkStyle: 'hierarchical',
         navLinks: [
diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js
index b0a7796c..2002ebee 100644
--- a/src/content/dependencies/transformContent.js
+++ b/src/content/dependencies/transformContent.js
@@ -562,11 +562,14 @@ export default {
     const transformMultiline = () => {
       const markedInput =
         extractNonTextNodes()
-          // Compress multiple line breaks into single line breaks.
-          .replace(/\n{2,}/g, '\n')
+          // Compress multiple line breaks into single line breaks,
+          // except when they're preceding or following indented
+          // text (by at least two spaces).
+          .replace(/(?<!  .*)\n{2,}(?!^  )/gm, '\n') /* eslint-disable-line no-regex-spaces */
           // Expand line breaks which don't follow a list, quote,
-          // or <br> / "  ".
-          .replace(/(?<!^ *-.*|^>.*|  $|<br>$)\n+/gm, '\n\n') /* eslint-disable-line no-regex-spaces */
+          // or <br> / "  ", and which don't precede or follow
+          // indented text (by at least two spaces).
+          .replace(/(?<!^ *-.*|^>.*|^  .*\n*|  $|<br>$)\n+(?!  |\n)/gm, '\n\n') /* eslint-disable-line no-regex-spaces */
           // Expand line breaks which are at the end of a list.
           .replace(/(?<=^ *-.*)\n+(?!^ *-)/gm, '\n\n')
           // Expand line breaks which are at the end of a quote.
diff --git a/src/data/composite/things/album/withTrackSections.js b/src/data/composite/things/album/withTrackSections.js
index baa3cb4a..679a09fd 100644
--- a/src/data/composite/things/album/withTrackSections.js
+++ b/src/data/composite/things/album/withTrackSections.js
@@ -22,7 +22,7 @@ export default templateCompositeFrom({
 
   steps: () => [
     exitWithoutDependency({
-      dependency: 'trackData',
+      dependency: 'ownTrackData',
       value: input.value([]),
     }),
 
@@ -75,7 +75,7 @@ export default templateCompositeFrom({
 
     withResolvedReferenceList({
       list: '#trackRefs',
-      data: 'trackData',
+      data: 'ownTrackData',
       notFoundMode: input.value('null'),
       find: input.value(find.track),
     }).outputs({
diff --git a/src/data/composite/things/album/withTracks.js b/src/data/composite/things/album/withTracks.js
index dcea6593..fff3d5ae 100644
--- a/src/data/composite/things/album/withTracks.js
+++ b/src/data/composite/things/album/withTracks.js
@@ -12,7 +12,7 @@ export default templateCompositeFrom({
 
   steps: () => [
     exitWithoutDependency({
-      dependency: 'trackData',
+      dependency: 'ownTrackData',
       value: input.value([]),
     }),
 
@@ -35,7 +35,7 @@ export default templateCompositeFrom({
 
     withResolvedReferenceList({
       list: '#trackRefs',
-      data: 'trackData',
+      data: 'ownTrackData',
       find: input.value(find.track),
     }),
 
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 63ec1140..a95ba354 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -133,7 +133,10 @@ export class Album extends Thing {
       class: input.value(Group),
     }),
 
-    trackData: wikiData({
+    // Only the tracks which belong to this album.
+    // Necessary for computing the track list, so provide this statically
+    // or keep it updated.
+    ownTrackData: wikiData({
       class: input.value(Track),
     }),
 
diff --git a/src/data/things/static-page.js b/src/data/things/static-page.js
index ab9c5f98..8a3fd10e 100644
--- a/src/data/things/static-page.js
+++ b/src/data/things/static-page.js
@@ -30,5 +30,6 @@ export class StaticPage extends Thing {
     directory: directory(),
     content: simpleString(),
     stylesheet: simpleString(),
+    script: simpleString(),
   });
 }
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 08891719..e3fe0804 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -336,12 +336,21 @@ export class Track extends Thing {
     }
 
     let album;
-    if (depth >= 0 && (album = this.album ?? this.dataSourceAlbum)) {
+
+    if (depth >= 0) {
+      try {
+        album = this.album;
+      } catch (_error) {}
+
+      album ??= this.dataSourceAlbum;
+    }
+
+    if (album) {
       const albumName = album.name;
       const albumIndex = album.tracks.indexOf(this);
       const trackNum =
         (albumIndex === -1
-          ? '#?'
+          ? 'indeterminate position'
           : `#${albumIndex + 1}`);
       parts.push(` (${colors.yellow(trackNum)} in ${colors.green(albumName)})`);
     }
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 2c600341..82b7faf2 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -646,6 +646,7 @@ export const processStaticPageDocument = makeProcessDocument(T.StaticPage, {
     directory: 'Directory',
 
     stylesheet: 'Style',
+    script: 'Script',
     content: 'Content',
   },
 });
@@ -935,6 +936,7 @@ export const dataSteps = [
         // an individual section before applying it, since those are just
         // generic objects; they aren't Things in and of themselves.)
         const trackSections = [];
+        const ownTrackData = [];
 
         let currentTrackSection = {
           name: `Default Track Section`,
@@ -969,13 +971,16 @@ export const dataSteps = [
 
           entry.dataSourceAlbum = albumRef;
 
+          ownTrackData.push(entry);
           currentTrackSection.tracks.push(Thing.getReference(entry));
         }
 
         closeCurrentTrackSection();
 
-        album.trackSections = trackSections;
         albumData.push(album);
+
+        album.trackSections = trackSections;
+        album.ownTrackData = ownTrackData;
       }
 
       return {albumData, trackData};
@@ -1550,7 +1555,7 @@ export function linkWikiDataArrays(wikiData, {
 
   assignWikiData([WD.wikiInfo], 'groupData');
 
-  assignWikiData(WD.albumData, 'artistData', 'artTagData', 'groupData', 'trackData');
+  assignWikiData(WD.albumData, 'artistData', 'artTagData', 'groupData');
   assignWikiData(WD.trackData, 'albumData', 'artistData', 'artTagData', 'flashData', 'trackData');
   assignWikiData(WD.artistData, 'albumData', 'artistData', 'flashData', 'trackData');
   assignWikiData(WD.groupData, 'albumData', 'groupCategoryData');
@@ -1624,8 +1629,7 @@ export function filterDuplicateDirectories(wikiData) {
         call(() => {
           throw new Error(
             `Duplicate directory ${colors.green(directory)}:\n` +
-              places.map((thing) => ` - ` + inspect(thing)).join('\n')
-          );
+            places.map(thing => ` - ` + inspect(thing)).join('\n'));
         });
       }
 
diff --git a/src/static/client3.js b/src/static/client3.js
index 86b5f985..1e64ebe1 100644
--- a/src/static/client3.js
+++ b/src/static/client3.js
@@ -2015,98 +2015,6 @@ function addExternalIconTooltipPageListeners() {
 clientSteps.getPageReferences.push(getExternalIconTooltipReferences);
 clientSteps.addPageListeners.push(addExternalIconTooltipPageListeners);
 
-/*
-const linkIconTooltipInfo =
-  Array.from(document.querySelectorAll('span.contribution.has-tooltip'))
-    .map(span => ({
-      mainLink: span.querySelector('a'),
-      iconsContainer: span.querySelector('span.icons-tooltip'),
-      iconLinks: span.querySelectorAll('span.icons-tooltip a'),
-    }));
-
-for (const info of linkIconTooltipInfo) {
-  const focusElements =
-    [info.mainLink, ...info.iconLinks];
-
-  const hoverElements =
-    [info.mainLink, info.iconsContainer];
-
-  let hidden = true;
-
-  const show = () => {
-    info.iconsContainer.classList.add('visible');
-    info.iconsContainer.inert = false;
-    hidden = false;
-  };
-
-  const hide = () => {
-    info.iconsContainer.classList.remove('visible');
-    info.iconsContainer.inert = true;
-    hidden = true;
-  };
-
-  const considerHiding = () => {
-    if (hoverElements.some(el => el.matches(':hover'))) {
-      return;
-    }
-
-    if (<document.activeElement is inside tooltip>) {
-      return;
-    }
-
-    if (justTouched) {
-      return;
-    }
-
-    hide();
-  };
-
-  // Hover (pointer)
-
-  let hoverTimeout;
-
-  info.mainLink.addEventListener('mouseenter', () => {
-    if (hidden) {
-      hoverTimeout = setTimeout(show, 250);
-    }
-  });
-
-  info.mainLink.addEventListener('mouseout', () => {
-    if (hidden) {
-      clearTimeout(hoverTimeout);
-    } else {
-      considerHiding();
-    }
-  });
-
-  info.iconsContainer.addEventListener('mouseout', () => {
-    if (!hidden) {
-      considerHiding();
-    }
-  });
-
-  // Focus (keyboard)
-
-  let focusTimeout;
-
-  info.mainLink.addEventListener('focus', () => {
-    focusTimeout = setTimeout(show, 750);
-  });
-
-  info.mainLink.addEventListener('blur', () => {
-    clearTimeout(focusTimeout);
-  });
-
-  info.iconsContainer.addEventListener('focusout', () => {
-    requestAnimationFrame(considerHiding);
-  });
-
-  info.mainLink.addEventListener('blur', () => {
-    requestAnimationFrame(considerHiding);
-  });
-}
-*/
-
 // Sticky commentary sidebar ------------------------------
 
 const albumCommentarySidebarInfo = clientInfo.albumCommentarySidebarInfo = {
diff --git a/src/util/sugar.js b/src/util/sugar.js
index eab44b75..cee3df12 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -589,6 +589,32 @@ export function _withAggregate(mode, aggregateOpts, fn) {
   }
 }
 
+export const unhelpfulStackLines = [
+  /sugar/,
+  /node:/,
+  /<anonymous>/,
+];
+
+export function getUsefulStackLine(stack) {
+  if (!stack) return '';
+
+  function isUseful(stackLine) {
+    const trimmed = stackLine.trim();
+
+    if (!trimmed.startsWith('at'))
+      return false;
+
+    if (unhelpfulStackLines.some(regex => regex.test(trimmed)))
+      return false;
+
+    return true;
+  }
+
+  const stackLines = stack.split('\n');
+  const usefulStackLine = stackLines.find(isUseful);
+  return usefulStackLine ?? '';
+}
+
 export function showAggregate(topError, {
   pathToFileURL = f => f,
   showTraces = true,
@@ -670,15 +696,8 @@ export function showAggregate(topError, {
         : messagePart);
 
     if (showTraces) {
-      const stackLines =
-        stack?.split('\n');
-
       const stackLine =
-        stackLines?.find(line =>
-          line.trim().startsWith('at') &&
-          !line.includes('sugar') &&
-          !line.includes('node:') &&
-          !line.includes('<anonymous>'));
+        getUsefulStackLine(stack);
 
       const tracePart =
         (stackLine