« 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/generateLyricsEntry.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateLyricsEntry.js')
-rw-r--r--src/content/dependencies/generateLyricsEntry.js47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/content/dependencies/generateLyricsEntry.js b/src/content/dependencies/generateLyricsEntry.js
index 02fd3634..15f84b27 100644
--- a/src/content/dependencies/generateLyricsEntry.js
+++ b/src/content/dependencies/generateLyricsEntry.js
@@ -1,7 +1,4 @@
 export default {
-  contentDependencies: ['linkArtist', 'linkExternal', 'transformContent'],
-  extraDependencies: ['html', 'language'],
-
   relations: (relation, entry) => ({
     content:
       relation('transformContent', entry.body),
@@ -17,6 +14,9 @@ export default {
     sourceLinks:
       entry.sourceURLs
         .map(url => relation('linkExternal', url)),
+
+    originDetails:
+      relation('transformContent', entry.originDetails),
   }),
 
   data: (entry) => ({
@@ -25,6 +25,30 @@ export default {
 
     hasSquareBracketAnnotations:
       entry.hasSquareBracketAnnotations,
+
+    numStanzas:
+      1 +
+
+      (Array.from(
+        entry.body
+          .matchAll(/\n\n|<br><br>/g))
+
+        .length) +
+
+      (entry.body.includes('<br')
+        ? entry.body.split('\n').length
+        : 0),
+
+    numLines:
+      1 +
+
+      (Array.from(
+        entry.body
+          .replaceAll(/(<br>){1,}/g, '\n')
+          .replaceAll(/\n{2,}/g, '\n')
+          .matchAll(/\n/g))
+
+        .length),
   }),
 
   slots: {
@@ -36,9 +60,16 @@ export default {
 
   generate: (data, relations, slots, {html, language}) =>
     language.encapsulate('misc.lyrics', capsule =>
-      html.tag('div', {class: 'lyrics-entry'},
+      html.tag('blockquote', {class: 'lyrics-entry'},
         slots.attributes,
 
+        {'data-stanzas': data.numStanzas},
+        {'data-lines': data.numLines},
+
+        (data.numStanzas > 1 ||
+         data.numLines > 8) &&
+          {class: 'long-lyrics'},
+
         [
           html.tag('p', {class: 'lyrics-details'},
             {[html.onlyIfContent]: true},
@@ -75,6 +106,14 @@ export default {
                 language.$(capsule, 'squareBracketAnnotations'),
             ]),
 
+          html.tag('p', {class: 'origin-details'},
+            {[html.onlyIfContent]: true},
+
+            relations.originDetails.slots({
+              mode: 'inline',
+              absorbPunctuationFollowingExternalLinks: false,
+            })),
+
           relations.content.slot('mode', 'lyrics'),
         ])),
 };