« get me outta code hell

content: generateNewsEntryPage - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-01 11:08:53 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-01 11:09:24 -0300
commite03756a5113f9b9b37588dfa7ddfa96137c685fe (patch)
tree1ed79db32e9e4a3a558048618d76bbb3406dc713 /src/content
parentef873ddd0296b45a3a330c1ba447d0b3ba417ca0 (diff)
content: generateNewsEntryPage
Diffstat (limited to 'src/content')
-rw-r--r--src/content/dependencies/generateNewsEntryPage.js123
-rw-r--r--src/content/dependencies/generateNewsIndexPage.js3
2 files changed, 126 insertions, 0 deletions
diff --git a/src/content/dependencies/generateNewsEntryPage.js b/src/content/dependencies/generateNewsEntryPage.js
new file mode 100644
index 00000000..e3071a57
--- /dev/null
+++ b/src/content/dependencies/generateNewsEntryPage.js
@@ -0,0 +1,123 @@
+import {sortChronologically} from '../../util/wiki-data.js';
+
+export default {
+  contentDependencies: [
+    'generatePageLayout',
+    'generatePreviousNextLinks',
+    'linkNewsEntry',
+    'linkNewsIndex',
+    'transformContent',
+  ],
+
+  extraDependencies: ['html', 'language', 'wikiData'],
+
+  sprawl({newsData}) {
+    return {newsData};
+  },
+
+  query({newsData}, newsEntry) {
+    const entries = sortChronologically(newsData.slice());
+
+    const index = entries.indexOf(newsEntry);
+
+    const previousEntry =
+      (index > 0
+        ? entries[index - 1]
+        : null);
+
+    const nextEntry =
+      (index < entries.length - 1
+        ? entries[index + 1]
+        : null);
+
+    return {previousEntry, nextEntry};
+  },
+
+  relations(relation, query, sprawl, newsEntry) {
+    const relations = {};
+
+    relations.layout =
+      relation('generatePageLayout');
+
+    relations.content =
+      relation('transformContent', newsEntry.content);
+
+    relations.newsIndexLink =
+      relation('linkNewsIndex');
+
+    relations.currentEntryLink =
+      relation('linkNewsEntry', newsEntry);
+
+    if (query.previousEntry || query.nextEntry) {
+      relations.previousNextLinks =
+        relation('generatePreviousNextLinks');
+
+      if (query.previousEntry) {
+        relations.previousEntryLink =
+          relation('linkNewsEntry', query.previousEntry);
+      }
+
+      if (query.nextEntry) {
+        relations.nextEntryLink =
+          relation('linkNewsEntry', query.nextEntry);
+      }
+    }
+
+    return relations;
+  },
+
+  data(query, sprawl, newsEntry) {
+    return {
+      name: newsEntry.name,
+      date: newsEntry.date,
+    };
+  },
+
+  generate(data, relations, {html, language}) {
+    return relations.layout.slots({
+      title:
+        language.$('newsEntryPage.title', {
+          entry: data.name,
+        }),
+
+      headingMode: 'sticky',
+
+      mainClasses: ['long-content'],
+      mainContent: [
+        html.tag('p',
+          language.$('newsEntryPage.published', {
+            date: language.formatDate(data.date),
+          })),
+
+        relations.content,
+      ],
+
+      navLinkStyle: 'hierarchical',
+      navLinks: [
+        {auto: 'home'},
+        {
+          html:
+            relations.newsIndexLink
+              .slot('content', language.$('newsEntryPage.nav.news')),
+        },
+        {
+          html:
+            language.$('newsEntryPage.nav.entry', {
+              date: language.formatDate(data.date),
+              entry:
+                relations.currentEntryLink
+                  .slot('attributes', {class: 'current'}),
+            }),
+
+          accent:
+            (relations.previousNextLinks
+              ? `(${language.formatUnitList(relations.previousNextLinks.slots({
+                  previousLink: relations.previousEntryLink ?? null,
+                  nextLink: relations.nextEntryLink ?? null,
+                }).content)})`
+              : null),
+        },
+      ],
+    });
+  },
+};
diff --git a/src/content/dependencies/generateNewsIndexPage.js b/src/content/dependencies/generateNewsIndexPage.js
new file mode 100644
index 00000000..938d8be7
--- /dev/null
+++ b/src/content/dependencies/generateNewsIndexPage.js
@@ -0,0 +1,3 @@
+export default {
+  generate() {},
+};