« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-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 0000000..a1efb81
--- /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 0000000..666c3f2
--- /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 0000000..5568ff8
--- /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 0000000..6dd0710
--- /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 0000000..e911a38
--- /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 0000000..06ec643
--- /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 d65b2ba..8d06c0b 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 fd55050..408a7e7 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';