« 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
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateWikiHomeNewsBox.js76
-rw-r--r--src/content/dependencies/generateWikiHomePage.js91
-rw-r--r--src/content/dependencies/linkCommentaryIndex.js12
-rw-r--r--src/content/dependencies/linkFlashIndex.js12
-rw-r--r--src/content/dependencies/linkNewsIndex.js12
-rw-r--r--src/content/dependencies/linkWikiHome.js20
6 files changed, 223 insertions, 0 deletions
diff --git a/src/content/dependencies/generateWikiHomeNewsBox.js b/src/content/dependencies/generateWikiHomeNewsBox.js
new file mode 100644
index 00000000..a1efb810
--- /dev/null
+++ b/src/content/dependencies/generateWikiHomeNewsBox.js
@@ -0,0 +1,76 @@
+import {empty, stitchArrays} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: ['linkNewsEntry', 'transformContent'],
+  extraDependencies: ['html', 'language', 'wikiData'],
+
+  sprawl({newsData}) {
+    return {
+      entries: newsData.slice(0, 3),
+    };
+  },
+
+  relations(relation, sprawl) {
+    return {
+      entryContents:
+        sprawl.entries
+          .map(entry => relation('transformContent', entry.contentShort)),
+
+      entryMainLinks:
+        sprawl.entries
+          .map(entry => relation('linkNewsEntry', entry)),
+
+      entryReadMoreLinks:
+        sprawl.entries
+          .map(entry =>
+            entry.contentShort !== entry.content &&
+              relation('linkNewsEntry', entry)),
+    };
+  },
+
+  data(sprawl) {
+    return {
+      entryDates:
+        sprawl.entries
+          .map(entry => entry.date),
+    }
+  },
+
+  generate(data, relations, {html, language}) {
+    if (empty(relations.entryContents)) {
+      return html.blank();
+    }
+
+    return {
+      content: [
+        html.tag('h1', language.$('homepage.news.title')),
+
+        stitchArrays({
+          date: data.entryDates,
+          content: relations.entryContents,
+          mainLink: relations.entryMainLinks,
+          readMoreLink: relations.entryReadMoreLinks,
+        }).map(({
+            date,
+            content,
+            mainLink,
+            readMoreLink,
+          }, index) =>
+          html.tag('article',
+            {class: ['news-entry', index === 0 && 'first-news-entry']},
+            [
+              html.tag('h2', [
+                html.tag('time', language.formatDate(date)),
+                mainLink,
+              ]),
+
+              content.slot('thumb', 'medium'),
+
+              readMoreLink?.slots({
+                content: language.$('homepage.news.entry.viewRest'),
+              }),
+            ])),
+      ],
+    };
+  },
+};
diff --git a/src/content/dependencies/generateWikiHomePage.js b/src/content/dependencies/generateWikiHomePage.js
new file mode 100644
index 00000000..666c3f26
--- /dev/null
+++ b/src/content/dependencies/generateWikiHomePage.js
@@ -0,0 +1,91 @@
+export default {
+  contentDependencies: [
+    'generatePageLayout',
+    'generateWikiHomeNewsBox',
+    'transformContent',
+  ],
+
+  extraDependencies: ['wikiData'],
+
+  sprawl({wikiInfo}) {
+    return {
+      wikiName: wikiInfo.name,
+
+      enableNews: wikiInfo.enableNews,
+    };
+  },
+
+  relations(relation, sprawl, homepageLayout) {
+    const relations = {};
+
+    relations.layout =
+      relation('generatePageLayout');
+
+    if (homepageLayout.sidebarContent) {
+      relations.customSidebarContent =
+        relation('transformContent', homepageLayout.sidebarContent);
+    }
+
+    if (sprawl.enableNews) {
+      relations.newsSidebarBox =
+        relation('generateWikiHomeNewsBox');
+    }
+
+    if (homepageLayout.navbarLinks) {
+      relations.customNavLinkContents =
+        homepageLayout.navbarLinks
+          .map(content => relation('transformContent', content));
+    }
+
+    return relations;
+  },
+
+  data(sprawl) {
+    return {
+      wikiName: sprawl.wikiName,
+    };
+  },
+
+  generate(data, relations) {
+    return relations.layout.slots({
+      title: data.wikiName,
+      showWikiNameInTitle: false,
+
+      mainClasses: ['top-index'],
+      headingMode: 'static',
+
+      mainContent: [],
+
+      leftSidebarCollapse: false,
+      leftSidebarWide: true,
+
+      leftSidebarMultiple: [
+        (relations.customSidebarContent
+          ? {
+              content:
+                relations.customSidebarContent
+                  .slot('mode', 'multiline'),
+            }
+          : null),
+
+        relations.newsSidebarBox ?? null,
+      ],
+
+      navLinkStyle: 'index',
+      navLinks: [
+        {auto: 'home', current: true},
+
+        ...(
+          relations.customNavLinkContents
+            ?.map(content => ({
+              html:
+                content.slots({
+                  mode: 'inline',
+                  preferShortLinkNames: true,
+                }),
+            }))
+          ?? []),
+      ],
+    });
+  },
+};
diff --git a/src/content/dependencies/linkCommentaryIndex.js b/src/content/dependencies/linkCommentaryIndex.js
new file mode 100644
index 00000000..5568ff84
--- /dev/null
+++ b/src/content/dependencies/linkCommentaryIndex.js
@@ -0,0 +1,12 @@
+export default {
+  contentDependencies: ['linkStationaryIndex'],
+
+  relations: (relation) =>
+    ({link:
+        relation(
+          'linkStationaryIndex',
+          'localized.commentaryIndex',
+          'commentaryIndex.title')}),
+
+  generate: (relations) => relations.link,
+};
diff --git a/src/content/dependencies/linkFlashIndex.js b/src/content/dependencies/linkFlashIndex.js
new file mode 100644
index 00000000..6dd0710e
--- /dev/null
+++ b/src/content/dependencies/linkFlashIndex.js
@@ -0,0 +1,12 @@
+export default {
+  contentDependencies: ['linkStationaryIndex'],
+
+  relations: (relation) =>
+    ({link:
+        relation(
+          'linkStationaryIndex',
+          'localized.flashIndex',
+          'flashIndex.title')}),
+
+  generate: (relations) => relations.link,
+};
diff --git a/src/content/dependencies/linkNewsIndex.js b/src/content/dependencies/linkNewsIndex.js
new file mode 100644
index 00000000..e911a384
--- /dev/null
+++ b/src/content/dependencies/linkNewsIndex.js
@@ -0,0 +1,12 @@
+export default {
+  contentDependencies: ['linkStationaryIndex'],
+
+  relations: (relation) =>
+    ({link:
+        relation(
+          'linkStationaryIndex',
+          'localized.newsIndex',
+          'newsIndex.title')}),
+
+  generate: (relations) => relations.link,
+};
diff --git a/src/content/dependencies/linkWikiHome.js b/src/content/dependencies/linkWikiHome.js
new file mode 100644
index 00000000..06ec6438
--- /dev/null
+++ b/src/content/dependencies/linkWikiHome.js
@@ -0,0 +1,20 @@
+export default {
+  contentDependencies: ['linkStationaryIndex'],
+  extraDependencies: ['wikiData'],
+
+  sprawl({wikiInfo}) {
+    return {wikiShortName: wikiInfo.nameShort};
+  },
+
+  relations: (relation) =>
+    ({link: relation('linkTemplate')}),
+
+  data: (sprawl) =>
+    ({wikiShortName: sprawl.wikiShortName}),
+
+  generate: (data, relations) =>
+    relations.link.slots({
+      path: ['home'],
+      content: data.wikiShortName,
+    }),
+};