« 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--strings-default.json3
-rw-r--r--upd8-util.js13
-rwxr-xr-xupd8.js32
3 files changed, 47 insertions, 1 deletions
diff --git a/strings-default.json b/strings-default.json
index 3dc2e4b5..7a948d64 100644
--- a/strings-default.json
+++ b/strings-default.json
@@ -225,6 +225,9 @@
     "listingPage.listAlbums.byDuration.item": "{ALBUM} ({DURATION})",
     "listingPage.listAlbums.byDate.title": "Albums - by Date",
     "listingPage.listAlbums.byDate.item": "{ALBUM} ({DATE})",
+    "listingPage.listAlbums.byDateAdded.title": "Albums - by Date Added to Wiki",
+    "listingPage.listAlbums.byDateAdded.date": "{DATE}",
+    "listingPage.listAlbums.byDateAdded.album": "{ALBUM}",
     "listingPage.listArtists.byName.title": "Artists - by Name",
     "listingPage.listArtists.byName.item": "{ARTIST} ({CONTRIBUTIONS})",
     "listingPage.listArtists.byContribs.title": "Artists - by Contributions",
diff --git a/upd8-util.js b/upd8-util.js
index 6ff34199..abeed6c1 100644
--- a/upd8-util.js
+++ b/upd8-util.js
@@ -370,7 +370,18 @@ module.exports.chunkByConditions = function(array, conditions) {
 };
 
 module.exports.chunkByProperties = function(array, properties) {
-    return module.exports.chunkByConditions(array, properties.map(p => (a, b) => a[p] !== b[p] || a[p] != b[p]))
+    return module.exports.chunkByConditions(array, properties.map(p => (a, b) => {
+        if (a[p] instanceof Date && b[p] instanceof Date)
+            return +a[p] !== +b[p];
+
+        if (a[p] !== b[p]) return true;
+
+        // Not sure if this line is still necessary with the specific check for
+        // d8tes a8ove, 8ut, uh, keeping it anyway, just in case....?
+        if (a[p] != b[p]) return true;
+
+        return false;
+    }))
         .map(chunk => ({
             ...Object.fromEntries(properties.map(p => [p, chunk[0][p]])),
             chunk
diff --git a/upd8.js b/upd8.js
index 732c35a1..66582f17 100755
--- a/upd8.js
+++ b/upd8.js
@@ -4136,6 +4136,38 @@ const listingSpec = [
     },
 
     {
+        directory: 'albusm/by-date-added',
+        title: ({strings}) => strings('listingPage.listAlbums.byDateAdded.title'),
+
+        data() {
+            return chunkByProperties(albumData.slice().sort((a, b) => {
+                if (a.dateAdded < b.dateAdded) return -1;
+                if (a.dateAdded > b.dateAdded) return 1;
+            }), ['dateAdded']);
+        },
+
+        html(chunks, {strings, to}) {
+            return fixWS`
+                <dl>
+                    ${chunks.map(({dateAdded, chunk: albums}) => fixWS`
+                        <dt>${strings('listingPage.listAlbums.byDateAdded.date', {
+                            date: strings.count.date(dateAdded)
+                        })}</dt>
+                        <dd><ul>
+                            ${(albums
+                                .map(album => strings('listingPage.listAlbums.byDateAdded.album', {
+                                    album: strings.link.album(album, {to})
+                                }))
+                                .map(row => `<li>${row}</li>`)
+                                .join('\n'))}
+                        </ul></dd>
+                    `).join('\n')}
+                </dl>
+            `;
+        }
+    },
+
+    {
         directory: 'artists/by-name',
         title: ({strings}) => strings('listingPage.listArtists.byName.title'),