« 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/generateListingPage.js44
-rw-r--r--src/content/dependencies/listAlbumsByName.js46
-rw-r--r--src/page/index.js2
-rw-r--r--src/page/listing.js11
4 files changed, 102 insertions, 1 deletions
diff --git a/src/content/dependencies/generateListingPage.js b/src/content/dependencies/generateListingPage.js
new file mode 100644
index 00000000..ae186d28
--- /dev/null
+++ b/src/content/dependencies/generateListingPage.js
@@ -0,0 +1,44 @@
+export default {
+  contentDependencies: ['generatePageLayout', 'linkListingIndex'],
+  extraDependencies: ['html'],
+
+  relations(relation) {
+    return {
+      layout: relation('generatePageLayout'),
+      listingsIndexLink: relation('linkListingIndex'),
+    };
+  },
+
+  slots: {
+    title: {type: 'string'},
+
+    type: {
+      validate: v => v.is('rows'),
+    },
+
+    rows: {
+      validate: v => v.arrayOf(v.isHTML),
+    },
+  },
+
+  generate(relations, slots, {html}) {
+    return relations.layout.slots({
+      title: slots.title,
+      headingMode: 'sticky',
+
+      mainContent: [
+        slots.type === 'rows' &&
+          html.tag('ul',
+            slots.rows
+              .map(row => html.tag('li', row))),
+      ],
+
+      navLinkStyle: 'hierarchical',
+      navLinks: [
+        {auto: 'home'},
+        {html: relations.listingsIndexLink},
+        {auto: 'current'},
+      ],
+    });
+  },
+};
diff --git a/src/content/dependencies/listAlbumsByName.js b/src/content/dependencies/listAlbumsByName.js
new file mode 100644
index 00000000..2182efa5
--- /dev/null
+++ b/src/content/dependencies/listAlbumsByName.js
@@ -0,0 +1,46 @@
+import {stitchArrays} from '../../util/sugar.js';
+import {sortAlphabetically} from '../../util/wiki-data.js';
+
+export default {
+  contentDependencies: ['generateListingPage', 'linkAlbum'],
+  extraDependencies: ['language', 'wikiData'],
+
+  sprawl({albumData}) {
+    return {albumData};
+  },
+
+  query({albumData}) {
+    return {
+      albums: sortAlphabetically(albumData.slice()),
+    };
+  },
+
+  relations(relation, query) {
+    return {
+      page: relation('generateListingPage'),
+      links: query.albums.map(album => relation('linkAlbum', album)),
+    };
+  },
+
+  data(query) {
+    return {
+      numTracks: query.albums.map(album => album.tracks.length),
+    };
+  },
+
+  generate(data, relations, {language}) {
+    return relations.page.slots({
+      title: language.$('listingPage.listAlbums.byName.title'),
+      type: 'rows',
+      rows:
+        stitchArrays({
+          link: relations.links,
+          numTracks: data.numTracks,
+        }).map(({link, numTracks}) =>
+            language.$('listingPage.listAlbums.byName.item', {
+              album: link,
+              tracks: language.countTracks(numTracks, {unit: true}),
+            })),
+    });
+  },
+};
diff --git a/src/page/index.js b/src/page/index.js
index 5a622132..e07c1355 100644
--- a/src/page/index.js
+++ b/src/page/index.js
@@ -13,7 +13,7 @@ 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 listing from './listing.js';
+export * as listing from './listing.js';
 // export * as news from './news.js';
 export * as static from './static.js';
 // export * as tag from './tag.js';
diff --git a/src/page/listing.js b/src/page/listing.js
index 73c30827..da4c2968 100644
--- a/src/page/listing.js
+++ b/src/page/listing.js
@@ -14,6 +14,16 @@ import {getTotalDuration} from '../util/wiki-data.js';
 
 export const description = `wiki-wide listing pages & index`;
 
+export function pathsTargetless() {
+  return [
+    {
+      type: 'page', path: ['listing', 'albums/by-name'],
+      contentFunction: {name: 'listAlbumsByName'},
+    },
+  ];
+}
+
+/*
 export function condition({wikiData}) {
   return wikiData.wikiInfo.enableListings;
 }
@@ -274,3 +284,4 @@ function generateLinkIndexForListings(currentListing, forSidebar, {
             genUL(listings)),
         ]));
 }
+*/