« 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/generateContentEntry.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateContentEntry.js')
-rw-r--r--src/content/dependencies/generateContentEntry.js123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/content/dependencies/generateContentEntry.js b/src/content/dependencies/generateContentEntry.js
new file mode 100644
index 00000000..c77f744a
--- /dev/null
+++ b/src/content/dependencies/generateContentEntry.js
@@ -0,0 +1,123 @@
+import {empty} from '#sugar';
+
+export default {
+  relations: (relation, entry) => ({
+    artistLinks:
+      (!empty(entry.artists) && !entry.artistText
+        ? entry.artists
+            .map(artist => relation('linkArtist', artist))
+        : null),
+
+    artistsContent:
+      (entry.artistText
+        ? relation('transformContent', entry.artistText)
+        : null),
+
+    annotationContent:
+      (entry.annotation
+        ? relation('transformContent', entry.annotation)
+        : null),
+
+    bodyContent:
+      relation('transformContent', entry.body),
+
+    colorStyle:
+      relation('generateColorStyleAttribute'),
+
+    date:
+      relation('generateContentEntryDate', entry),
+  }),
+
+  data: (entry) => ({
+    isWikiEditorEntry:
+      entry.isWikiEditorCommentary ||
+      entry.isWikiEditorSource,
+  }),
+
+  slots: {
+    color: {validate: v => v.isColor},
+  },
+
+  generate: (data, relations, slots, {html, language}) =>
+    language.encapsulate('misc.artistCommentary.entry', entryCapsule =>
+      html.tags([
+        html.tag('p', {class: 'content-entry-heading'},
+          slots.color &&
+            relations.colorStyle.clone()
+              .slot('color', slots.color),
+
+          !html.isBlank(relations.date) &&
+            {class: 'dated'},
+
+          html.tag('span', {class: 'content-entry-heading-inner-box'},
+            language.encapsulate(entryCapsule, 'title', titleCapsule => [
+              html.tags([
+                html.tag('span', {class: 'float-spacer'},
+                  {[html.onlyIfSiblings]: true}),
+
+                relations.date,
+              ]),
+
+              html.tag('span', {class: 'content-entry-heading-text'},
+                language.encapsulate(titleCapsule, workingCapsule => {
+                  const workingOptions = {};
+
+                  const artists =
+                    html.tag('span', {class: 'content-entry-artists'},
+                      {[html.onlyIfContent]: true},
+
+                      (relations.artistsContent
+                        ? relations.artistsContent.slot('mode', 'inline')
+                     : relations.artistLinks
+                        ? language.formatConjunctionList(relations.artistLinks)
+                        : html.blank()));
+
+                  if (!html.isBlank(artists)) {
+                    workingCapsule += '.withArtists';
+                    workingOptions.artists = artists;
+                  }
+
+                  let annotation = html.blank();
+                  if (relations.annotationContent) {
+                    relations.annotationContent.slots({
+                      mode: 'inline',
+                      absorbPunctuationFollowingExternalLinks: false,
+                    });
+
+                    annotation =
+                      html.tag('span', {class: 'content-entry-annotation'},
+                        html.metatag('chunkwrap', {split: ','},
+                          relations.annotationContent));
+                  }
+
+                  if (!html.isBlank(annotation)) {
+                    if (html.isBlank(artists)) {
+                      workingCapsule += '.withAnnotation';
+                      workingOptions.annotation = annotation;
+                    } else {
+                      workingCapsule += '.withAccent';
+                      workingOptions.accent =
+                        html.tag('span', {class: 'content-entry-accent'},
+                          language.$(titleCapsule, 'accent.withAnnotation', {annotation}));
+
+                      if (data.isWikiEditorEntry) {
+                        workingCapsule += '.wikiEditor';
+                      }
+                    }
+                  }
+
+                  return language.$(workingCapsule, workingOptions);
+                })),
+            ]))),
+
+        html.tag('blockquote', {class: 'content-entry-body'},
+          slots.color &&
+            relations.colorStyle.clone()
+              .slot('color', slots.color),
+
+          data.isWikiEditorEntry &&
+            {class: 'wiki-commentary'},
+
+          relations.bodyContent.slot('mode', 'multiline')),
+      ])),
+};