« 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/generateReferencingArtworksPage.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateReferencingArtworksPage.js')
-rw-r--r--src/content/dependencies/generateReferencingArtworksPage.js100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/content/dependencies/generateReferencingArtworksPage.js b/src/content/dependencies/generateReferencingArtworksPage.js
new file mode 100644
index 00000000..e97b01f8
--- /dev/null
+++ b/src/content/dependencies/generateReferencingArtworksPage.js
@@ -0,0 +1,100 @@
+export default {
+  contentDependencies: [
+    'generateCoverArtwork',
+    'generateCoverGrid',
+    'generatePageLayout',
+    'image',
+    'linkAnythingMan',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  relations: (relation, artwork) => ({
+    layout:
+      relation('generatePageLayout'),
+
+    cover:
+      relation('generateCoverArtwork', artwork),
+
+    coverGrid:
+      relation('generateCoverGrid'),
+
+    links:
+      artwork.referencedByArtworks.map(({artwork}) =>
+        relation('linkAnythingMan', artwork.thing)),
+
+    images:
+      artwork.referencedByArtworks.map(({artwork}) =>
+        relation('image', artwork)),
+  }),
+
+  data: (artwork) => ({
+    color:
+      artwork.thing.color,
+
+    count:
+      artwork.referencedByArtworks.length,
+
+    names:
+      artwork.referencedByArtworks
+        .map(({artwork}) => artwork.thing.name),
+
+    coverArtistNames:
+      artwork.referencedByArtworks
+        .map(({artwork}) =>
+          artwork.artistContribs
+            .map(contrib => contrib.artist.name)),
+  }),
+
+  slots: {
+    styleTags: {type: 'html', mutable: false},
+
+    title: {type: 'html', mutable: false},
+
+    navLinks: {validate: v => v.isArray},
+    navBottomRowContent: {type: 'html', mutable: false},
+  },
+
+  generate: (data, relations, slots, {html, language}) =>
+    language.encapsulate('referencingArtworksPage', pageCapsule =>
+      relations.layout.slots({
+        title: slots.title,
+        subtitle: language.$(pageCapsule, 'subtitle'),
+
+        color: data.color,
+        styleTags: slots.styleTags,
+
+        artworkColumnContent:
+          relations.cover.slots({
+            showArtistDetails: true,
+          }),
+
+        mainClasses: ['top-index'],
+        mainContent: [
+          html.tag('p', {class: 'quick-info'},
+            language.$(pageCapsule, 'statsLine', {
+              artworks:
+                language.countArtworks(data.count, {
+                  unit: true,
+                }),
+            })),
+
+          relations.coverGrid.slots({
+            links: relations.links,
+            images: relations.images,
+            names: data.names,
+
+            info:
+              data.coverArtistNames.map(names =>
+                language.$('misc.coverGrid.details.coverArtists', {
+                  artists:
+                    language.formatUnitList(names),
+                })),
+          }),
+        ],
+
+        navLinkStyle: 'hierarchical',
+        navLinks: slots.navLinks,
+        navBottomRowContent: slots.navBottomRowContent,
+      })),
+};