« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content
diff options
context:
space:
mode:
Diffstat (limited to 'src/content')
-rw-r--r--src/content/dependencies/generateAlbumInfoPage.js84
-rw-r--r--src/content/dependencies/generateAlbumReleaseInfo.js101
-rw-r--r--src/content/dependencies/generateTrackInfoPage.js94
-rw-r--r--src/content/dependencies/generateTrackReleaseInfo.js86
4 files changed, 202 insertions, 163 deletions
diff --git a/src/content/dependencies/generateAlbumInfoPage.js b/src/content/dependencies/generateAlbumInfoPage.js
index 3658f028..d1be0f3a 100644
--- a/src/content/dependencies/generateAlbumInfoPage.js
+++ b/src/content/dependencies/generateAlbumInfoPage.js
@@ -1,6 +1,6 @@
 import getChronologyRelations from '../util/getChronologyRelations.js';
 import {sortAlbumsTracksChronologically} from '../../util/wiki-data.js';
-import {accumulateSum, empty} from '../../util/sugar.js';
+import {empty} from '../../util/sugar.js';
 
 export default {
   contentDependencies: [
@@ -8,6 +8,7 @@ export default {
     'generateAlbumAdditionalFilesList',
     'generateAlbumCoverArtwork',
     'generateAlbumNavAccent',
+    'generateAlbumReleaseInfo',
     'generateAlbumSidebar',
     'generateAlbumSocialEmbed',
     'generateAlbumStyleRules',
@@ -16,12 +17,10 @@ export default {
     'generateColorStyleRules',
     'generateContentHeading',
     'generatePageLayout',
-    'generateReleaseInfoContributionsLine',
     'linkAlbum',
     'linkAlbumCommentary',
     'linkAlbumGallery',
     'linkArtist',
-    'linkExternal',
     'linkTrack',
     'transformContent',
   ],
@@ -78,29 +77,8 @@ export default {
 
     // Section: Release info
 
-    const releaseInfo = sections.releaseInfo = {};
-
-    releaseInfo.artistContributionsLine =
-      relation('generateReleaseInfoContributionsLine', album.artistContribs);
-
-    releaseInfo.coverArtistContributionsLine =
-      relation('generateReleaseInfoContributionsLine', album.coverArtistContribs);
-
-    releaseInfo.wallpaperArtistContributionsLine =
-      relation('generateReleaseInfoContributionsLine', album.wallpaperArtistContribs);
-
-    releaseInfo.bannerArtistContributionsLine =
-      relation('generateReleaseInfoContributionsLine', album.bannerArtistContribs);
-
-    // Section: Listen on
-
-    if (!empty(album.urls)) {
-      const listen = sections.listen = {};
-
-      listen.externalLinks =
-        album.urls.map(url =>
-          relation('linkExternal', url));
-    }
+    relations.releaseInfo =
+      relation('generateAlbumReleaseInfo', album);
 
     // Section: Extra links
 
@@ -157,14 +135,6 @@ export default {
     const data = {};
 
     data.name = album.name;
-    data.date = album.date;
-
-    data.duration = accumulateSum(album.tracks, track => track.duration);
-    data.durationApproximate = album.tracks.length > 1;
-
-    if (album.coverArtDate && +album.coverArtDate !== +album.date) {
-      data.coverArtDate = album.coverArtDate;
-    }
 
     if (!empty(album.additionalFiles)) {
       data.numAdditionalFiles = album.additionalFiles.length;
@@ -194,51 +164,7 @@ export default {
             : null),
 
         mainContent: [
-          html.tag('p',
-            {
-              [html.onlyIfContent]: true,
-              [html.joinChildren]: html.tag('br'),
-            },
-            [
-              sec.releaseInfo.artistContributionsLine
-                .slots({stringKey: 'releaseInfo.by'}),
-
-              sec.releaseInfo.coverArtistContributionsLine
-                .slots({stringKey: 'releaseInfo.coverArtBy'}),
-
-              sec.releaseInfo.wallpaperArtistContributionsLine
-                .slots({stringKey: 'releaseInfo.wallpaperArtBy'}),
-
-              sec.releaseInfo.bannerArtistContributionsLine
-                .slots({stringKey: 'releaseInfo.bannerArtBy'}),
-
-              data.date &&
-                language.$('releaseInfo.released', {
-                  date: language.formatDate(data.date),
-                }),
-
-              data.coverArtDate &&
-                language.$('releaseInfo.artReleased', {
-                  date: language.formatDate(data.coverArtDate),
-                }),
-
-              data.duration &&
-                language.$('releaseInfo.duration', {
-                  duration:
-                    language.formatDuration(data.duration, {
-                      approximate: data.durationApproximate,
-                    }),
-                }),
-            ]),
-
-          sec.listen &&
-            html.tag('p',
-              language.$('releaseInfo.listenOn', {
-                links:
-                  language.formatDisjunctionList(
-                    sec.listen.externalLinks
-                      .map(link => link.slot('mode', 'album'))),
-              })),
+          relations.releaseInfo,
 
           html.tag('p',
             {
diff --git a/src/content/dependencies/generateAlbumReleaseInfo.js b/src/content/dependencies/generateAlbumReleaseInfo.js
new file mode 100644
index 00000000..86e6dfe9
--- /dev/null
+++ b/src/content/dependencies/generateAlbumReleaseInfo.js
@@ -0,0 +1,101 @@
+import {accumulateSum, empty} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: [
+    'generateReleaseInfoContributionsLine',
+    'linkExternal',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  relations(relation, album) {
+    const relations = {};
+
+    relations.artistContributionsLine =
+      relation('generateReleaseInfoContributionsLine', album.artistContribs);
+
+    relations.coverArtistContributionsLine =
+      relation('generateReleaseInfoContributionsLine', album.coverArtistContribs);
+
+    relations.wallpaperArtistContributionsLine =
+      relation('generateReleaseInfoContributionsLine', album.wallpaperArtistContribs);
+
+    relations.bannerArtistContributionsLine =
+      relation('generateReleaseInfoContributionsLine', album.bannerArtistContribs);
+
+    if (!empty(album.urls)) {
+      relations.externalLinks =
+        album.urls.map(url =>
+          relation('linkExternal', url));
+    }
+
+    return relations;
+  },
+
+  data(album) {
+    const data = {};
+
+    if (album.date) {
+      data.date = album.date;
+    }
+
+    if (album.coverArtDate && +album.coverArtDate !== +album.date) {
+      data.coverArtDate = album.coverArtDate;
+    }
+
+    data.duration = accumulateSum(album.tracks, track => track.duration);
+    data.durationApproximate = album.tracks.length > 1;
+
+    return data;
+  },
+
+  generate(data, relations, {html, language}) {
+    return html.tags([
+      html.tag('p',
+        {
+          [html.onlyIfContent]: true,
+          [html.joinChildren]: html.tag('br'),
+        },
+        [
+          relations.artistContributionsLine
+            .slots({stringKey: 'releaseInfo.by'}),
+
+          relations.coverArtistContributionsLine
+            .slots({stringKey: 'releaseInfo.coverArtBy'}),
+
+          relations.wallpaperArtistContributionsLine
+            .slots({stringKey: 'releaseInfo.wallpaperArtBy'}),
+
+          relations.bannerArtistContributionsLine
+            .slots({stringKey: 'releaseInfo.bannerArtBy'}),
+
+          data.date &&
+            language.$('releaseInfo.released', {
+              date: language.formatDate(data.date),
+            }),
+
+          data.coverArtDate &&
+            language.$('releaseInfo.artReleased', {
+              date: language.formatDate(data.coverArtDate),
+            }),
+
+          data.duration &&
+            language.$('releaseInfo.duration', {
+              duration:
+                language.formatDuration(data.duration, {
+                  approximate: data.durationApproximate,
+                }),
+            }),
+        ]),
+
+      relations.externalLinks &&
+        html.tag('p',
+          language.$('releaseInfo.listenOn', {
+            links:
+              language.formatDisjunctionList(
+                relations.externalLinks
+                  .map(link => link.slot('mode', 'album'))),
+          })),
+    ]);
+  },
+};
diff --git a/src/content/dependencies/generateTrackInfoPage.js b/src/content/dependencies/generateTrackInfoPage.js
index ed28edec..9ea8efab 100644
--- a/src/content/dependencies/generateTrackInfoPage.js
+++ b/src/content/dependencies/generateTrackInfoPage.js
@@ -18,14 +18,13 @@ export default {
     'generateColorStyleRules',
     'generateContentHeading',
     'generatePageLayout',
-    'generateReleaseInfoContributionsLine',
     'generateTrackCoverArtwork',
     'generateTrackList',
     'generateTrackListDividedByGroups',
+    'generateTrackReleaseInfo',
     'linkAlbum',
     'linkArtist',
     'linkContribution',
-    'linkExternal',
     'linkFlash',
     'linkTrack',
     'transformContent',
@@ -115,25 +114,8 @@ export default {
 
     // Section: Release info
 
-    const releaseInfo = sections.releaseInfo = {};
-
-    releaseInfo.artistContributionLinks =
-      relation('generateReleaseInfoContributionsLine', track.artistContribs);
-
-    if (track.hasUniqueCoverArt) {
-      releaseInfo.coverArtistContributionsLine =
-        relation('generateReleaseInfoContributionsLine', track.coverArtistContribs);
-    }
-
-    // Section: Listen on
-
-    const listen = sections.listen = {};
-
-    if (!empty(track.urls)) {
-      listen.externalLinks =
-        track.urls.map(url =>
-          relation('linkExternal', url));
-    }
+    relations.releaseInfo =
+      relation('generateTrackReleaseInfo', track);
 
     // Section: Extra links
 
@@ -301,37 +283,14 @@ export default {
   },
 
   data(sprawl, track) {
-    const data = {};
-    const {album} = track;
-
-    data.name = track.name;
-    data.date = track.date;
-    data.duration = track.duration;
-
-    data.hasUniqueCoverArt = track.hasUniqueCoverArt;
-    data.hasAlbumCoverArt = album.hasCoverArt;
-
-    if (track.hasUniqueCoverArt) {
-      data.albumCoverArtDirectory = album.directory;
-      data.trackCoverArtDirectory = track.directory;
-      data.coverArtFileExtension = track.coverArtFileExtension;
-
-      if (track.coverArtDate && +track.coverArtDate !== +track.date) {
-        data.coverArtDate = track.coverArtDate;
-      }
-    } else if (track.album.hasCoverArt) {
-      data.albumCoverArtDirectory = album.directory;
-      data.coverArtFileExtension = album.coverArtFileExtension;
-    }
+    return {
+      name: track.name,
 
-    data.hasTrackNumbers = album.hasTrackNumbers;
-    data.trackNumber = album.tracks.indexOf(track) + 1;
+      hasTrackNumbers: track.album.hasTrackNumbers,
+      trackNumber: track.album.tracks.indexOf(track) + 1,
 
-    if (!empty(track.additionalFiles)) {
-      data.numAdditionalFiles = track.additionalFiles.length;
-    }
-
-    return data;
+      numAdditionalFiles: track.additionalFiles.length,
+    };
   },
 
   generate(data, relations, {html, language}) {
@@ -353,40 +312,7 @@ export default {
             : null),
 
         mainContent: [
-          html.tag('p', {
-            [html.onlyIfContent]: true,
-            [html.joinChildren]: html.tag('br'),
-          }, [
-            sec.releaseInfo.artistContributionLinks
-              .slots({stringKey: 'releaseInfo.by'}),
-
-            sec.releaseInfo.coverArtistContributionsLine
-              ?.slots({stringKey: 'releaseInfo.coverArtBy'}),
-
-            data.date &&
-              language.$('releaseInfo.released', {
-                date: language.formatDate(data.date),
-              }),
-
-            data.coverArtDate &&
-              language.$('releaseInfo.artReleased', {
-                date: language.formatDate(data.coverArtDate),
-              }),
-
-            data.duration &&
-              language.$('releaseInfo.duration', {
-                duration: language.formatDuration(data.duration),
-              }),
-          ]),
-
-          html.tag('p',
-            (sec.listen.externalLinks
-              ? language.$('releaseInfo.listenOn', {
-                  links: language.formatDisjunctionList(sec.listen.externalLinks),
-                })
-              : language.$('releaseInfo.listenOn.noLinks', {
-                  name: html.tag('i', data.name),
-                }))),
+          relations.releaseInfo,
 
           html.tag('p',
             {
diff --git a/src/content/dependencies/generateTrackReleaseInfo.js b/src/content/dependencies/generateTrackReleaseInfo.js
new file mode 100644
index 00000000..f47b6356
--- /dev/null
+++ b/src/content/dependencies/generateTrackReleaseInfo.js
@@ -0,0 +1,86 @@
+import {empty} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: [
+    'generateReleaseInfoContributionsLine',
+    'linkExternal',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  relations(relation, track) {
+    const relations = {};
+
+    relations.artistContributionLinks =
+      relation('generateReleaseInfoContributionsLine', track.artistContribs);
+
+    if (track.hasUniqueCoverArt) {
+      relations.coverArtistContributionsLine =
+        relation('generateReleaseInfoContributionsLine', track.coverArtistContribs);
+    }
+
+    if (!empty(track.urls)) {
+      relations.externalLinks =
+        track.urls.map(url =>
+          relation('linkExternal', url));
+    }
+
+    return relations;
+  },
+
+  data(track) {
+    const data = {};
+
+    data.date = track.date;
+    data.duration = track.duration;
+
+    if (
+      track.hasUniqueCoverArt &&
+      track.coverArtDate &&
+      +track.coverArtDate !== +track.date
+    ) {
+      data.coverArtDate = track.coverArtDate;
+    }
+
+    return data;
+  },
+
+  generate(data, relations, {html, language}) {
+    return html.tags([
+      html.tag('p', {
+        [html.onlyIfContent]: true,
+        [html.joinChildren]: html.tag('br'),
+      }, [
+        relations.artistContributionLinks
+          .slots({stringKey: 'releaseInfo.by'}),
+
+        relations.coverArtistContributionsLine
+          ?.slots({stringKey: 'releaseInfo.coverArtBy'}),
+
+        data.date &&
+          language.$('releaseInfo.released', {
+            date: language.formatDate(data.date),
+          }),
+
+        data.coverArtDate &&
+          language.$('releaseInfo.artReleased', {
+            date: language.formatDate(data.coverArtDate),
+          }),
+
+        data.duration &&
+          language.$('releaseInfo.duration', {
+            duration: language.formatDuration(data.duration),
+          }),
+      ]),
+
+      html.tag('p',
+        (relations.externalLinks
+          ? language.$('releaseInfo.listenOn', {
+              links: language.formatDisjunctionList(relations.externalLinks),
+            })
+          : language.$('releaseInfo.listenOn.noLinks', {
+              name: html.tag('i', data.name),
+            }))),
+    ]);
+  },
+};