« get me outta code hell

content: generateNewsIndexPage - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateNewsIndexPage.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-01 11:23:39 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-01 11:27:35 -0300
commit84a4f21fefa1b7127f51463660740895fa7383a4 (patch)
tree400734468fa35a1d3eafe73d4bbc0c18331191d5 /src/content/dependencies/generateNewsIndexPage.js
parentf1b4ff800797dfc14acaeef3c7b2adb3412d738c (diff)
content: generateNewsIndexPage
Diffstat (limited to 'src/content/dependencies/generateNewsIndexPage.js')
-rw-r--r--src/content/dependencies/generateNewsIndexPage.js92
1 files changed, 91 insertions, 1 deletions
diff --git a/src/content/dependencies/generateNewsIndexPage.js b/src/content/dependencies/generateNewsIndexPage.js
index 938d8be7..da497a7d 100644
--- a/src/content/dependencies/generateNewsIndexPage.js
+++ b/src/content/dependencies/generateNewsIndexPage.js
@@ -1,3 +1,93 @@
+import {stitchArrays} from '../../util/sugar.js';
+import {sortChronologically} from '../../util/wiki-data.js';
+
 export default {
-  generate() {},
+  contentDependencies: [
+    'generatePageLayout',
+    'linkNewsEntry',
+    'transformContent',
+  ],
+
+  extraDependencies: ['html', 'language', 'wikiData'],
+
+  sprawl({newsData}) {
+    return {newsData};
+  },
+
+  query({newsData}) {
+    return {
+      entries:
+        sortChronologically(
+          newsData.slice(),
+          {latestFirst: true}),
+    };
+  },
+
+  relations(relation, query) {
+    const relations = {};
+
+    relations.layout =
+      relation('generatePageLayout');
+
+    relations.entryLinks =
+      query.entries
+        .map(entry => relation('linkNewsEntry', entry));
+
+    relations.viewRestLinks =
+      query.entries
+        .map(entry =>
+          (entry.content === entry.contentShort
+            ? null
+            : relation('linkNewsEntry', entry)));
+
+    relations.entryContents =
+      query.entries
+        .map(entry => relation('transformContent', entry.contentShort));
+
+    return relations;
+  },
+
+  data(query) {
+    return {
+      entryDates:
+        query.entries.map(entry => entry.date),
+
+      entryDirectories:
+        query.entries.map(entry => entry.directory),
+    };
+  },
+
+  generate(data, relations, {html, language}) {
+    return relations.layout.slots({
+      title: language.$('newsIndex.title'),
+      headingMode: 'sticky',
+
+      mainClasses: ['long-content', 'news-index'],
+      mainContent:
+        stitchArrays({
+          entryLink: relations.entryLinks,
+          viewRestLink: relations.viewRestLinks,
+          content: relations.entryContents,
+          date: data.entryDates,
+          directory: data.entryDirectories,
+        }).map(({entryLink, viewRestLink, content, date, directory}) =>
+            html.tag('article', {id: directory}, [
+              html.tag('h2', [
+                html.tag('time', language.formatDate(date)),
+                entryLink,
+              ]),
+
+              content,
+
+              viewRestLink
+                ?.slot('content', language.$('newsIndex.entry.viewRest')),
+            ])),
+
+      navLinkStyle: 'hierarchical',
+      navLinks: [
+        {auto: 'home'},
+        {auto: 'current'},
+      ],
+    });
+  },
 };