« get me outta code hell

content: listGroupsByName, listing feature flags - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-07-07 12:28:40 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-07 12:39:14 -0300
commitfbbafa606f12b0ecf3ac89918b424f0ec4a8de4e (patch)
tree58b1b4c4adc9ac5e9bbe7d2b85becd61c5dd4d41
parent556eda40caf7f3921507d90afc81073bb74fbd43 (diff)
content: listGroupsByName, listing feature flags
-rw-r--r--src/content/dependencies/generateListingIndexList.js7
-rw-r--r--src/content/dependencies/listGroupsByName.js49
-rw-r--r--src/listing-spec.js52
-rw-r--r--src/page/listing.js5
4 files changed, 68 insertions, 45 deletions
diff --git a/src/content/dependencies/generateListingIndexList.js b/src/content/dependencies/generateListingIndexList.js
index 32125955..e4a2f5c7 100644
--- a/src/content/dependencies/generateListingIndexList.js
+++ b/src/content/dependencies/generateListingIndexList.js
@@ -14,9 +14,10 @@ export default {
     const targetListings =
       sprawl.listingTargetSpec
         .map(({listings}) =>
-          listings.filter(({condition: c}) =>
-            !c ||
-            c({wikiData: {wikiInfo: sprawl.wikiInfo}})));
+          listings
+            .filter(listing =>
+              !listing.featureFlag ||
+              sprawl.wikiInfo[listing.featureFlag]));
 
     query.wikiColor = sprawl.wikiInfo.color;
 
diff --git a/src/content/dependencies/listGroupsByName.js b/src/content/dependencies/listGroupsByName.js
new file mode 100644
index 00000000..df35937b
--- /dev/null
+++ b/src/content/dependencies/listGroupsByName.js
@@ -0,0 +1,49 @@
+import {stitchArrays} from '../../util/sugar.js';
+import {sortAlphabetically} from '../../util/wiki-data.js';
+
+export default {
+  contentDependencies: ['generateListingPage', 'linkGroup', 'linkGroupGallery'],
+  extraDependencies: ['language', 'wikiData'],
+
+  sprawl({groupData}) {
+    return {groupData};
+  },
+
+  query({groupData}, spec) {
+    return {
+      spec,
+
+      groups: sortAlphabetically(groupData.slice()),
+    };
+  },
+
+  relations(relation, query) {
+    return {
+      page: relation('generateListingPage', query.spec),
+
+      infoLinks:
+        query.groups
+          .map(group => relation('linkGroup', group)),
+
+      galleryLinks:
+        query.groups
+          .map(group => relation('linkGroupGallery', group)),
+    };
+  },
+
+  generate(relations, {language}) {
+    return relations.page.slots({
+      type: 'rows',
+      rows:
+        stitchArrays({
+          infoLink: relations.infoLinks,
+          galleryLink: relations.galleryLinks,
+        }).map(({infoLink, galleryLink}) => ({
+            group: infoLink,
+            gallery:
+              galleryLink
+                .slot('content', language.$('listingPage.listGroups.byName.item.gallery')),
+          })),
+    });
+  },
+};
diff --git a/src/listing-spec.js b/src/listing-spec.js
index 17cde53f..88b0d9b4 100644
--- a/src/listing-spec.js
+++ b/src/listing-spec.js
@@ -89,28 +89,14 @@ listingSpec.push({
 listingSpec.push({
   directory: 'groups/by-name',
   stringsKey: 'listGroups.byName',
-
-  condition: ({wikiData: {wikiInfo}}) =>
-    wikiInfo.enableGroupUI,
-
-  data: ({wikiData: {groupData}}) =>
-    sortAlphabetically(groupData.slice()),
-
-  row: (group, {language, link}) =>
-    language.$('listingPage.listGroups.byCategory.group', {
-      group: link.groupInfo(group),
-      gallery: link.groupGallery(group, {
-        text: language.$('listingPage.listGroups.byCategory.group.gallery'),
-      }),
-    }),
+  contentFunction: 'listGroupsByName',
+  featureFlag: 'enableGroupUI',
 });
 
 listingSpec.push({
   directory: 'groups/by-category',
   stringsKey: 'listGroups.byCategory',
-
-  condition: ({wikiData: {wikiInfo}}) =>
-    wikiInfo.enableGroupUI,
+  featureFlag: 'enableGroupUI',
 
   data: ({wikiData: {groupCategoryData}}) =>
     groupCategoryData
@@ -150,9 +136,7 @@ listingSpec.push({
 listingSpec.push({
   directory: 'groups/by-albums',
   stringsKey: 'listGroups.byAlbums',
-
-  condition: ({wikiData: {wikiInfo}}) =>
-    wikiInfo.enableGroupUI,
+  featureFlag: 'enableGroupUI',
 
   data: ({wikiData: {groupData}}) =>
     groupData
@@ -172,9 +156,7 @@ listingSpec.push({
 listingSpec.push({
   directory: 'groups/by-tracks',
   stringsKey: 'listGroups.byTracks',
-
-  condition: ({wikiData: {wikiInfo}}) =>
-    wikiInfo.enableGroupUI,
+  featureFlag: 'enableGroupUI',
 
   data: ({wikiData: {groupData}}) =>
     groupData
@@ -196,9 +178,7 @@ listingSpec.push({
 listingSpec.push({
   directory: 'groups/by-duration',
   stringsKey: 'listGroups.byDuration',
-
-  condition: ({wikiData: {wikiInfo}}) =>
-    wikiInfo.enableGroupUI,
+  featureFlag: 'enableGroupUI',
 
   data: ({wikiData: {groupData}}) =>
     groupData
@@ -221,9 +201,7 @@ listingSpec.push({
 listingSpec.push({
   directory: 'groups/by-latest-album',
   stringsKey: 'listGroups.byLatest',
-
-  condition: ({wikiData: {wikiInfo}}) =>
-    wikiInfo.enableGroupUI,
+  featureFlag: 'enableGroupUI',
 
   data: ({wikiData: {groupData}}) =>
     sortChronologically(
@@ -403,9 +381,7 @@ listingSpec.push({
 listingSpec.push({
   directory: 'tracks/in-flashes/by-album',
   stringsKey: 'listTracks.inFlashes.byAlbum',
-
-  condition: ({wikiData: {wikiInfo}}) =>
-    wikiInfo.enableFlashesAndGames,
+  featureFlag: 'enableFlashesAndGames',
 
   data: ({wikiData: {trackData}}) =>
     chunkByProperties(
@@ -437,9 +413,7 @@ listingSpec.push({
 listingSpec.push({
   directory: 'tracks/in-flashes/by-flash',
   stringsKey: 'listTracks.inFlashes.byFlash',
-
-  condition: ({wikiData: {wikiInfo}}) =>
-    wikiInfo.enableFlashesAndGames,
+  featureFlag: 'enableFlashesAndGames',
 
   data: ({wikiData: {flashData}}) =>
     sortFlashesChronologically(flashData.slice())
@@ -538,9 +512,7 @@ listingSpec.push(listTracksWithProperty('midiProjectFiles', {
 listingSpec.push({
   directory: 'tags/by-name',
   stringsKey: 'listTags.byName',
-
-  condition: ({wikiData: {wikiInfo}}) =>
-    wikiInfo.enableArtTagUI,
+  featureFlag: 'enableArtTagUI',
 
   data: ({wikiData: {artTagData}}) =>
     sortAlphabetically(
@@ -565,9 +537,7 @@ listingSpec.push({
 listingSpec.push({
   directory: 'tags/by-uses',
   stringsKey: 'listTags.byUses',
-
-  condition: ({wikiData: {wikiInfo}}) =>
-    wikiInfo.enableArtTagUI,
+  featureFlag: 'enableArtTagUI',
 
   data: ({wikiData: {artTagData}}) =>
     artTagData
diff --git a/src/page/listing.js b/src/page/listing.js
index c770f825..1db7aa7b 100644
--- a/src/page/listing.js
+++ b/src/page/listing.js
@@ -17,7 +17,10 @@ export const description = `wiki-wide listing pages & index`;
 export function targets({wikiData}) {
   return (
     wikiData.listingSpec
-      .filter(listing => listing.contentFunction));
+      .filter(listing => listing.contentFunction)
+      .filter(listing =>
+        !listing.featureFlag ||
+        wikiData.wikiInfo[listing.featureFlag]));
 }
 
 export function pathsForTarget(listing) {