« 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/dependencies
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateAlbumInfoPage.js47
-rw-r--r--src/content/dependencies/generateAlbumInfoPageContent.js218
-rw-r--r--src/content/dependencies/generateAlbumStyleRules.js (renamed from src/content/dependencies/generateAlbumStylesheet.js)0
-rw-r--r--src/content/dependencies/generateColorStyleRules.js42
-rw-r--r--src/content/dependencies/generateContributionLinks.js6
-rw-r--r--src/content/dependencies/linkArtist.js9
6 files changed, 322 insertions, 0 deletions
diff --git a/src/content/dependencies/generateAlbumInfoPage.js b/src/content/dependencies/generateAlbumInfoPage.js
new file mode 100644
index 00000000..8bbb320f
--- /dev/null
+++ b/src/content/dependencies/generateAlbumInfoPage.js
@@ -0,0 +1,47 @@
+export default {
+  contentDependencies: [
+    'generateAlbumInfoPageContent',
+    'generateAlbumSocialEmbed',
+    'generateAlbumStyleRules',
+    'generateColorStyleRules',
+  ],
+
+  extraDependencies: [
+    'language',
+  ],
+
+  relations(relation, album) {
+    const relations = {};
+
+    relations.socialEmbed = relation('generateAlbumSocialEmbed', album);
+    relations.albumStyleRules = relation('generateAlbumStyleRules', album);
+    relations.colorStyleRules = relation('generateColorStyleRules', album.color);
+
+    return relations;
+  },
+
+  data(album) {
+    const data = {};
+
+    return data;
+  },
+
+  generate(data, relations, {
+    language,
+  }) {
+    const page = {};
+
+    page.title = language.$('albumPage.title', {album: data.name});
+
+    page.themeColor = data.color;
+
+    page.styleRules = [
+      relations.albumStyleRules,
+      relations.colorStyleRules,
+    ];
+
+    page.socialEmbed = relations.socialEmbed;
+
+    return page;
+  },
+};
diff --git a/src/content/dependencies/generateAlbumInfoPageContent.js b/src/content/dependencies/generateAlbumInfoPageContent.js
new file mode 100644
index 00000000..a9e51c02
--- /dev/null
+++ b/src/content/dependencies/generateAlbumInfoPageContent.js
@@ -0,0 +1,218 @@
+import {accumulateSum, empty} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: [
+    'generateContributionLinks',
+  ],
+
+  extraDependencies: [
+    'html',
+    'language',
+  ],
+
+  relations(relation, album) {
+    const relations = {};
+
+    const contributionLinksRelation = contribs =>
+      relation('generateContributionLinks', contribs, {
+        showContrib: true,
+        showIcons: true,
+      })
+
+    relations.artistLinks =
+      contributionLinksRelation(album.artistContribs);
+
+    relations.coverArtistLinks =
+      contributionLinksRelation(album.coverArtistContribs);
+
+    relations.wallpaperArtistLinks =
+      contributionLinksRelation(album.wallpaperArtistContribs);
+
+    relations.bannerArtistLinks =
+      contributionLinksRelation(album.bannerArtistContribs);
+
+    return relations;
+  },
+
+  data(album) {
+    const data = {};
+
+    data.date = album.date;
+    data.duration = accumulateSum(album.tracks, track => track.duration);
+    data.durationApproximate = album.tracks.length > 1;
+
+    if (
+      album.hasCoverArt &&
+      album.coverArtDate &&
+      +album.coverArtDate !== +album.date
+    ) {
+      data.coverArtDate = album.coverArtDate;
+    }
+
+    return data;
+  },
+
+  generate(data, relations, {
+    html,
+    language,
+  }) {
+    const content = {};
+
+    content.main = {
+      headingMode: 'sticky',
+      content: [
+        html.tag('p',
+          {
+            [html.onlyIfContent]: true,
+            [html.joinChildren]: '<br>',
+          },
+          [
+            !empty(relations.artistLinks) &&
+              language.$('releaseInfo.by', {
+                artists: relations.artistLinks,
+              }),
+
+            !empty(relations.coverArtistLinks) &&
+              language.$('releaseInfo.coverArtBy', {
+                artists: relations.coverArtistLinks,
+              }),
+
+            !empty(relations.wallpaperArtistLinks) &&
+              language.$('releaseInfo.wallpaperArtBy', {
+                artists: relations.wallpaperArtistLinks,
+              }),
+
+            !empty(relations.bannerArtistLinks) &&
+              language.$('releaseInfo.bannerArtBy', {
+                artists: relations.bannerArtistLinks,
+              }),
+
+            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,
+                  }),
+              }),
+          ]),
+
+        /*
+        html.tag('p',
+          {
+            [html.onlyIfContent]: true,
+            [html.joinChildren]: '<br>',
+          },
+          [
+            hasAdditionalFiles &&
+              generateAdditionalFilesShortcut(album.additionalFiles),
+
+            checkGalleryPage(album) &&
+              language.$('releaseInfo.viewGallery', {
+                link: link.albumGallery(album, {
+                  text: language.$('releaseInfo.viewGallery.link'),
+                }),
+              }),
+
+            checkCommentaryPage(album) &&
+              language.$('releaseInfo.viewCommentary', {
+                link: link.albumCommentary(album, {
+                  text: language.$('releaseInfo.viewCommentary.link'),
+                }),
+              }),
+          ]),
+
+        !empty(album.urls) &&
+          html.tag('p',
+            language.$('releaseInfo.listenOn', {
+              links: language.formatDisjunctionList(
+                album.urls.map(url => fancifyURL(url, {album: true}))
+              ),
+            })),
+
+        displayTrackSections &&
+        !empty(album.trackSections) &&
+          html.tag('dl',
+            {class: 'album-group-list'},
+            album.trackSections.flatMap(({
+              name,
+              startIndex,
+              tracks,
+            }) => [
+              html.tag('dt',
+                {class: ['content-heading']},
+                language.$('trackList.section.withDuration', {
+                  duration: language.formatDuration(getTotalDuration(tracks), {
+                    approximate: tracks.length > 1,
+                  }),
+                  section: name,
+                })),
+              html.tag('dd',
+                html.tag(listTag,
+                  listTag === 'ol' ? {start: startIndex + 1} : {},
+                  tracks.map(trackToListItem))),
+            ])),
+
+        !displayTrackSections &&
+        !empty(album.tracks) &&
+          html.tag(listTag,
+            album.tracks.map(trackToListItem)),
+
+        html.tag('p',
+          {
+            [html.onlyIfContent]: true,
+            [html.joinChildren]: '<br>',
+          },
+          [
+            album.dateAddedToWiki &&
+              language.$('releaseInfo.addedToWiki', {
+                date: language.formatDate(
+                  album.dateAddedToWiki
+                ),
+              })
+          ]),
+
+        ...html.fragment(
+          hasAdditionalFiles && [
+            generateContentHeading({
+              id: 'additional-files',
+              title: language.$('releaseInfo.additionalFiles.heading', {
+                additionalFiles: language.countAdditionalFiles(numAdditionalFiles, {
+                  unit: true,
+                }),
+              }),
+            }),
+
+            generateAlbumAdditionalFilesList(album, album.additionalFiles, {
+              generateAdditionalFilesList,
+              getSizeOfAdditionalFile,
+              link,
+              urls,
+            }),
+          ]),
+
+        ...html.fragment(
+          album.commentary && [
+            generateContentHeading({
+              id: 'artist-commentary',
+              title: language.$('releaseInfo.artistCommentary'),
+            }),
+
+            html.tag('blockquote', transformMultiline(album.commentary)),
+          ])
+        */
+      ]
+    };
+
+    return content;
+  },
+};
diff --git a/src/content/dependencies/generateAlbumStylesheet.js b/src/content/dependencies/generateAlbumStyleRules.js
index c9547836..c9547836 100644
--- a/src/content/dependencies/generateAlbumStylesheet.js
+++ b/src/content/dependencies/generateAlbumStyleRules.js
diff --git a/src/content/dependencies/generateColorStyleRules.js b/src/content/dependencies/generateColorStyleRules.js
new file mode 100644
index 00000000..02c3380e
--- /dev/null
+++ b/src/content/dependencies/generateColorStyleRules.js
@@ -0,0 +1,42 @@
+export default {
+  extraDependencies: [
+    'getColors',
+  ],
+
+  data(color) {
+    return {color};
+  },
+
+  generate(data, {
+    getColors,
+  }) {
+    if (!color) return '';
+
+    const {
+      primary,
+      dark,
+      dim,
+      dimGhost,
+      bg,
+      bgBlack,
+      shadow,
+    } = getColors(data.color);
+
+    const variables = [
+      `--primary-color: ${primary}`,
+      `--dark-color: ${dark}`,
+      `--dim-color: ${dim}`,
+      `--dim-ghost-color: ${dimGhost}`,
+      `--bg-color: ${bg}`,
+      `--bg-black-color: ${bgBlack}`,
+      `--shadow-color: ${shadow}`,
+      ...additionalVariables,
+    ];
+
+    return [
+      `:root {`,
+      ...variables.map((line) => `    ${line};`),
+      `}`,
+    ].join('\n');
+  },
+};
diff --git a/src/content/dependencies/generateContributionLinks.js b/src/content/dependencies/generateContributionLinks.js
index 74695796..a79c8234 100644
--- a/src/content/dependencies/generateContributionLinks.js
+++ b/src/content/dependencies/generateContributionLinks.js
@@ -5,6 +5,12 @@ export default {
     'linkArtist',
   ],
 
+  extraDependencies: [
+    'html',
+    'iconifyURL',
+    'language',
+  ],
+
   relations(relation, contributions) {
     const relations = {};
 
diff --git a/src/content/dependencies/linkArtist.js b/src/content/dependencies/linkArtist.js
new file mode 100644
index 00000000..396eca41
--- /dev/null
+++ b/src/content/dependencies/linkArtist.js
@@ -0,0 +1,9 @@
+export default {
+  data(artist) {
+    return {directory: artist.directory};
+  },
+
+  generate(data) {
+    return `(stub artist link: "${data.directory}")`;
+  },
+};