« get me outta code hell

content: generateWikiHomePage (layout besides content) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-07-26 10:13:46 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-26 10:15:23 -0300
commitbce6a52f44b6be8de1d7ed42150d051c25e63fb7 (patch)
tree3cb4b95fe277c37b3bba540f866ab5a2f02525f1 /src
parent40b607ef6f0500d36d1e7541b4229e45c866d5ae (diff)
content: generateWikiHomePage (layout besides content)
Diffstat (limited to 'src')
-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
-rw-r--r--src/page/homepage.js82
-rw-r--r--src/page/index.js2
8 files changed, 240 insertions, 67 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,
+    }),
+};
diff --git a/src/page/homepage.js b/src/page/homepage.js
index d65b2ba7..8d06c0b6 100644
--- a/src/page/homepage.js
+++ b/src/page/homepage.js
@@ -13,6 +13,21 @@ import {
 
 export const description = `main wiki homepage`;
 
+export function pathsTargetless({wikiData}) {
+  return [
+    {
+      type: 'page',
+      path: ['home'],
+
+      contentFunction: {
+        name: 'generateWikiHomePage',
+        args: [wikiData.homepageLayout],
+      },
+    },
+  ];
+}
+
+/*
 export function writeTargetless({wikiData}) {
   const {newsData, homepageLayout, wikiInfo} = wikiData;
 
@@ -140,74 +155,9 @@ export function writeTargetless({wikiData}) {
                 ]))),
         ],
       },
-
-      sidebarLeft: {
-        collapse: false,
-        wide: true,
-        stickyMode: 'none',
-
-        multiple: [
-          homepageLayout.sidebarContent &&
-            transformMultiline(homepageLayout.sidebarContent, {
-              thumb: 'medium',
-            }),
-
-          wikiInfo.enableNews &&
-            [
-              html.tag('h1',
-                language.$('homepage.news.title')),
-
-              ...newsData
-                .slice(0, 3)
-                .map((entry, i) =>
-                  html.tag('article',
-                    {
-                      class: [
-                        'news-entry',
-                        i === 0 && 'first-news-entry',
-                      ],
-                    },
-                    [
-                      html.tag('h2', [
-                        html.tag('time',
-                          language.formatDate(entry.date)),
-                        link.newsEntry(entry),
-                      ]),
-
-                      transformMultiline(entry.contentShort, {
-                        thumb: 'medium',
-                      }),
-
-                      entry.contentShort !== entry.content &&
-                        link.newsEntry(entry, {
-                          text: language.$('homepage.news.entry.viewRest')
-                        }),
-                    ])),
-            ],
-        ],
-      },
-
-      nav: {
-        linkContainerClasses: ['nav-links-index'],
-        links: [
-          link.home('', {text: wikiInfo.nameShort, class: 'current', to}),
-
-          ...html.fragment(
-            homepageLayout.navbarLinks?.map(text =>
-              transformInline(text, {
-                link:
-                  withEntries(link, entries =>
-                    entries.map(([key, fn]) =>
-                      [key, bindOpts(fn, {
-                        preferShortName: true,
-                      })])),
-              }))),
-        ]
-          .filter(Boolean)
-          .map((html) => ({html})),
-      },
     }),
   };
 
   return [page];
 }
+*/
diff --git a/src/page/index.js b/src/page/index.js
index fd550509..408a7e72 100644
--- a/src/page/index.js
+++ b/src/page/index.js
@@ -12,7 +12,7 @@ export * as artist from './artist.js';
 export * as artistAlias from './artist-alias.js';
 // export * as flash from './flash.js';
 export * as group from './group.js';
-// export * as homepage from './homepage.js';
+export * as homepage from './homepage.js';
 export * as listing from './listing.js';
 // export * as news from './news.js';
 export * as static from './static.js';