« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateListingsIndexPage.js89
-rw-r--r--src/page/listing.js265
2 files changed, 95 insertions, 259 deletions
diff --git a/src/content/dependencies/generateListingsIndexPage.js b/src/content/dependencies/generateListingsIndexPage.js
new file mode 100644
index 00000000..6887c6c2
--- /dev/null
+++ b/src/content/dependencies/generateListingsIndexPage.js
@@ -0,0 +1,89 @@
+import {getTotalDuration} from '../../util/wiki-data.js';
+
+export default {
+  contentDependencies: [
+    'generateListingIndexList',
+    'generateListingSidebar',
+    'generatePageLayout',
+  ],
+
+  extraDependencies: ['html', 'language', 'wikiData'],
+
+  sprawl({albumData, trackData, wikiInfo}) {
+    return {
+      wikiName: wikiInfo.name,
+      numTracks: trackData.length,
+      numAlbums: albumData.length,
+      totalDuration: getTotalDuration(trackData),
+    };
+  },
+
+  relations(relation) {
+    const relations = {};
+
+    relations.layout =
+      relation('generatePageLayout');
+
+    relations.sidebar =
+      relation('generateListingSidebar', null);
+
+    relations.list =
+      relation('generateListingIndexList', null);
+
+    return relations;
+  },
+
+  data(sprawl) {
+    return {
+      wikiName: sprawl.wikiName,
+      numTracks: sprawl.numTracks,
+      numAlbums: sprawl.numAlbums,
+      totalDuration: sprawl.totalDuration,
+    };
+  },
+
+  generate(data, relations, {html, language}) {
+    return relations.layout.slots({
+      title: language.$('listingIndex.title'),
+
+      headingMode: 'static',
+
+      mainContent: [
+        html.tag('p',
+          language.$('listingIndex.infoLine', {
+            wiki: data.wikiName,
+
+            tracks:
+              html.tag('b',
+                language.countTracks(data.numTracks, {unit: true})),
+
+            albums:
+              html.tag('b',
+                language.countAlbums(data.numAlbums, {unit: true})),
+
+            duration:
+              html.tag('b',
+                language.formatDuration(data.totalDuration, {
+                  approximate: true,
+                  unit: true,
+                })),
+          })),
+
+        html.tag('hr'),
+
+        html.tag('p',
+          language.$('listingIndex.exploreList')),
+
+        relations.list.slot('mode', 'content'),
+      ],
+
+      navLinkStyle: 'hierarchical',
+      navLinks: [
+        {auto: 'home'},
+        {auto: 'current'},
+      ],
+
+      ...relations.sidebar,
+    });
+  },
+};
diff --git a/src/page/listing.js b/src/page/listing.js
index 1db7aa7b..64db413d 100644
--- a/src/page/listing.js
+++ b/src/page/listing.js
@@ -36,265 +36,12 @@ export function pathsForTarget(listing) {
   ];
 }
 
-/*
-export function condition({wikiData}) {
-  return wikiData.wikiInfo.enableListings;
-}
-
-export function targets({wikiData}) {
-  return wikiData.listingSpec;
-}
-
-export function write(listing, {wikiData}) {
-  if (listing.condition && !listing.condition({wikiData})) {
-    return null;
-  }
-
-  const {listingSpec, listingTargetSpec} = wikiData;
-
-  const getTitleKey = l => `listingPage.${l.stringsKey}.title`;
-
-  const data = listing.data ? listing.data({wikiData}) : null;
-
-  // TODO: Invalid listing directories filtered here aren't warned about anywhere.
-  const seeAlso =
-    listing.seeAlso
-     ?.map(directory => listingSpec.find(l => l.directory === directory))
-      .filter(Boolean)
-    ?? null;
-
-  const currentTarget = listingTargetSpec.find(({listings}) => listings.includes(listing));
-  const currentListing = listing;
-
-  const page = {
-    type: 'page',
-    path: ['listing', listing.directory],
-    page: (opts) => {
-      const {
-        getLinkThemeString,
-        html,
-        language,
-        link,
-      } = opts;
-
-      return {
-        title: language.$(getTitleKey(listing)),
-
-        main: {
-          headingMode: 'sticky',
-
-          content: [
-            currentTarget.listings.length > 1 &&
-              html.tag('p',
-                language.$('listingPage.listingsFor', {
-                  target: currentTarget.title({language}),
-                  listings:
-                    language.formatUnitList(
-                      currentTarget.listings.map(listing =>
-                        html.tag('span',
-                          {class: listing === currentListing ? 'current' : ''},
-                          link.listing(listing, {
-                            class: 'nowrap',
-                            text: language.$(getTitleKey(listing) + '.short'),
-                          })))),
-                })),
-
-            !empty(seeAlso) &&
-              html.tag('p',
-                language.$('listingPage.seeAlso', {
-                  listings:
-                    language.formatUnitList(
-                      seeAlso.map(listing =>
-                        link.listing(listing, {
-                          text: language.$(getTitleKey(listing)),
-                        }))),
-                })),
-
-            ...html.fragment(
-              listing.html &&
-                (listing.data
-                  ? listing.html(data, opts)
-                  : listing.html(opts))),
-
-            listing.row &&
-              html.tag('ul',
-                data.map((item) =>
-                  html.tag('li',
-                    listing.row(item, opts)))),
-          ],
-        },
-
-        sidebarLeft: {
-          content: generateSidebarForListings(listing, {
-            getLinkThemeString,
-            html,
-            language,
-            link,
-            wikiData,
-          }),
-        },
-
-        nav: {
-          linkContainerClasses: ['nav-links-hierarchy'],
-          links: [
-            {toHome: true},
-            {
-              path: ['localized.listingIndex'],
-              title: language.$('listingIndex.title'),
-            },
-            {toCurrentPage: true},
-          ],
-        },
-      };
-    },
-  };
-
-  return [page];
-}
-
-export function writeTargetless({wikiData}) {
-  const {albumData, trackData, wikiInfo} = wikiData;
-
-  const totalDuration = getTotalDuration(trackData);
-
-  const page = {
-    type: 'page',
-    path: ['listingIndex'],
-    page: ({
-      getLinkThemeString,
-      html,
-      language,
-      link,
-    }) => ({
-      title: language.$('listingIndex.title'),
-
-      main: {
-        headingMode: 'static',
-
-        content: [
-          html.tag('p',
-            language.$('listingIndex.infoLine', {
-              wiki: wikiInfo.name,
-              tracks: html.tag('b',
-                language.countTracks(trackData.length, {
-                  unit: true,
-                })),
-              albums: html.tag('b',
-                language.countAlbums(albumData.length, {
-                  unit: true,
-                })),
-              duration: html.tag('b',
-                language.formatDuration(totalDuration, {
-                  approximate: true,
-                  unit: true,
-                })),
-            })),
-
-          html.tag('hr'),
-
-          html.tag('p',
-            language.$('listingIndex.exploreList')),
-
-          ...html.fragment(
-            generateLinkIndexForListings(null, false, {
-              html,
-              link,
-              language,
-              wikiData,
-            })),
-        ],
-      },
-
-      sidebarLeft: {
-        content: generateSidebarForListings(null, {
-          getLinkThemeString,
-          html,
-          language,
-          link,
-          wikiData,
-        }),
-      },
-
-      nav: {simple: true},
-    }),
-  };
-
-  return [page];
-}
-
-// Utility functions
-
-function generateSidebarForListings(currentListing, {
-  getLinkThemeString,
-  html,
-  language,
-  link,
-  wikiData,
-}) {
+export function pathsTargetless() {
   return [
-    html.tag('h1',
-      link.listingIndex('', {
-        text: language.$('listingIndex.title'),
-      })),
-
-    ...html.fragment(
-      generateLinkIndexForListings(currentListing, true, {
-        getLinkThemeString,
-        html,
-        language,
-        link,
-        wikiData,
-      })),
+    {
+      type: 'page',
+      path: ['listingIndex'],
+      contentFunction: {name: 'generateListingsIndexPage'},
+    },
   ];
 }
-
-function generateLinkIndexForListings(currentListing, forSidebar, {
-  getLinkThemeString,
-  html,
-  language,
-  link,
-  wikiData,
-}) {
-  const {listingTargetSpec, wikiInfo} = wikiData;
-
-  const filteredByCondition = listingTargetSpec
-    .map(({listings, ...rest}) => ({
-      ...rest,
-      listings: listings.filter(({condition: c}) => !c || c({wikiData})),
-    }))
-    .filter(({listings}) => !empty(listings));
-
-  const genUL = (listings) =>
-    html.tag('ul',
-      listings.map((listing) =>
-        html.tag('li',
-          {class: [listing === currentListing && 'current']},
-          link.listing(listing, {
-            text: language.$(`listingPage.${listing.stringsKey}.title.short`),
-          }))));
-
-  return forSidebar
-    ? filteredByCondition.map(({title, listings}) =>
-        html.tag('details',
-          {
-            open: listings.includes(currentListing),
-            class: listings.includes(currentListing) && 'current',
-          },
-          [
-            html.tag('summary',
-              {style: getLinkThemeString(wikiInfo.color)},
-              html.tag('span',
-                {class: 'group-name'},
-                title({language}))),
-            genUL(listings),
-          ]))
-    : html.tag('dl',
-        filteredByCondition.flatMap(({title, listings}) => [
-          html.tag('dt',
-            {class: ['content-heading']},
-            title({language})),
-          html.tag('dd',
-            genUL(listings)),
-        ]));
-}
-*/