« get me outta code hell

content: generateCommentaryEntry -> generateContentEntry - 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:
author(quasar) nebula <qznebula@protonmail.com>2026-01-31 17:17:56 -0400
committer(quasar) nebula <qznebula@protonmail.com>2026-01-31 17:17:56 -0400
commit5d1bbf4f3932be0d45acfece1c9bd468e86af14f (patch)
treef6782e4ee4c2d0aae5bd039e2879c60255ea4fb7 /src/content/dependencies/generateContentEntry.js
parent3205d96a9095e2419ded46a30ed26b714ad0395f (diff)
content: generateCommentaryEntry -> generateContentEntry
Diffstat (limited to 'src/content/dependencies/generateContentEntry.js')
-rw-r--r--src/content/dependencies/generateContentEntry.js111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/content/dependencies/generateContentEntry.js b/src/content/dependencies/generateContentEntry.js
new file mode 100644
index 00000000..bebd690d
--- /dev/null
+++ b/src/content/dependencies/generateContentEntry.js
@@ -0,0 +1,111 @@
+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:
+      (entry.body
+        ? relation('transformContent', entry.body)
+        : null),
+
+    colorStyle:
+      relation('generateColorStyleAttribute'),
+
+    date:
+      relation('generateContentEntryDate', entry),
+  }),
+
+  data: (entry) => ({
+    isWikiEditorCommentary:
+      entry.isWikiEditorCommentary,
+  }),
+
+  slots: {
+    color: {validate: v => v.isColor},
+  },
+
+  generate: (data, relations, slots, {html, language}) =>
+    language.encapsulate('misc.artistCommentary.entry', entryCapsule =>
+      html.tags([
+        html.tag('p', {class: 'commentary-entry-heading'},
+          slots.color &&
+            relations.colorStyle.clone()
+              .slot('color', slots.color),
+
+          !html.isBlank(relations.date) &&
+            {class: 'dated'},
+
+          language.encapsulate(entryCapsule, 'title', titleCapsule => [
+            html.tag('span', {class: 'commentary-entry-heading-text'},
+              language.encapsulate(titleCapsule, workingCapsule => {
+                const workingOptions = {};
+
+                workingOptions.artists =
+                  html.tag('span', {class: 'commentary-entry-artists'},
+                    (relations.artistsContent
+                      ? relations.artistsContent.slot('mode', 'inline')
+                   : relations.artistLinks
+                      ? language.formatConjunctionList(relations.artistLinks)
+                      : language.$(titleCapsule, 'noArtists')));
+
+                const accent =
+                  html.tag('span', {class: 'commentary-entry-accent'},
+                    {[html.onlyIfContent]: true},
+
+                    language.encapsulate(titleCapsule, 'accent', accentCapsule =>
+                      language.encapsulate(accentCapsule, workingCapsule => {
+                        const workingOptions = {};
+
+                        if (relations.annotationContent) {
+                          workingCapsule += '.withAnnotation';
+                          workingOptions.annotation =
+                            relations.annotationContent.slots({
+                              mode: 'inline',
+                              absorbPunctuationFollowingExternalLinks: false,
+                            });
+                        }
+
+                        if (workingCapsule === accentCapsule) {
+                          return html.blank();
+                        } else {
+                          return language.$(workingCapsule, workingOptions);
+                        }
+                      })));
+
+                if (!html.isBlank(accent)) {
+                  workingCapsule += '.withAccent';
+                  workingOptions.accent = accent;
+                }
+
+                return language.$(workingCapsule, workingOptions);
+              })),
+
+            relations.date,
+          ])),
+
+        html.tag('blockquote', {class: 'commentary-entry-body'},
+          slots.color &&
+            relations.colorStyle.clone()
+              .slot('color', slots.color),
+
+          data.isWikiEditorCommentary &&
+            {class: 'wiki-commentary'},
+
+          relations.bodyContent.slot('mode', 'multiline')),
+      ])),
+};