« get me outta code hell

pre-writes: art tags, artists & aliases - 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>2022-02-16 23:04:08 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-02-16 23:04:08 -0400
commitf8557485ac06a7b2527c50dcf638497212678a16 (patch)
treed869354ea475d517f1ef0ac699107f94355187b9
parenta447a03576ec5e346b0381f0845ecdc302d7e11f (diff)
pre-writes: art tags, artists & aliases
-rw-r--r--src/data/things.js36
-rw-r--r--src/listing-spec.js4
-rw-r--r--src/page/artist-alias.js4
-rw-r--r--src/page/artist.js43
-rw-r--r--src/page/tag.js4
-rwxr-xr-xsrc/upd8.js42
6 files changed, 98 insertions, 35 deletions
diff --git a/src/data/things.js b/src/data/things.js
index 7151c507..92763c14 100644
--- a/src/data/things.js
+++ b/src/data/things.js
@@ -546,7 +546,7 @@ Track.propertyDescriptors = {
             compute: ({ artTagsByRef, artTagData }) => (
                 (artTagsByRef && artTagData
                     ? (artTagsByRef
-                        .map(ref => find.tag(ref, {wikiData: {tagData: artTagData}}))
+                        .map(ref => find.tag(ref, {wikiData: {artTagData}}))
                         .filter(Boolean))
                     : [])
             )
@@ -570,6 +570,40 @@ Artist.propertyDescriptors = {
             validate: validateArrayItems(isName)
         }
     },
+
+    isAlias: Thing.common.flag(),
+    aliasedArtistRef: Thing.common.singleReference(Artist),
+
+    // Update only
+
+    artistData: Thing.common.wikiData(Artist),
+
+    // Expose only
+
+    aliasedArtist: {
+        flags: {expose: true},
+
+        expose: {
+            dependencies: ['artistData', 'aliasedArtistRef'],
+            compute: ({ artistData, aliasedArtistRef }) => (
+                (aliasedArtistRef && artistData
+                    ? find.artist(aliasedArtistRef, {wikiData: {artistData}}, {quiet: true})
+                    : null)
+            )
+        }
+    },
+
+    // albumsAsCoverArtist
+    // albumsAsWallpaperArtist
+    // albumsAsBannerArtist
+    // albumsAsCommentator
+
+    // tracksAsArtist
+    // tracksAsContributor
+    // tracksAsCoverArtist
+    // tracksAsCommentator
+
+    // flashesAsContributor
 };
 
 // -> Group
diff --git a/src/listing-spec.js b/src/listing-spec.js
index 2a1268d5..cf0dc09c 100644
--- a/src/listing-spec.js
+++ b/src/listing-spec.js
@@ -710,7 +710,7 @@ const listingSpec = [
         condition: ({wikiData}) => wikiData.wikiInfo.enableArtTagUI,
 
         data({wikiData}) {
-            return wikiData.tagData
+            return wikiData.artTagData
                 .filter(tag => !tag.isCW)
                 .sort(sortByName)
                 .map(tag => ({tag, timesUsed: tag.things.length}));
@@ -730,7 +730,7 @@ const listingSpec = [
         condition: ({wikiData}) => wikiData.wikiInfo.enableArtTagUI,
 
         data({wikiData}) {
-            return wikiData.tagData
+            return wikiData.artTagData
                 .filter(tag => !tag.isCW)
                 .map(tag => ({tag, timesUsed: tag.things.length}))
                 .sort((a, b) => b.timesUsed - a.timesUsed);
diff --git a/src/page/artist-alias.js b/src/page/artist-alias.js
index d03510a8..c7b0feb6 100644
--- a/src/page/artist-alias.js
+++ b/src/page/artist-alias.js
@@ -8,12 +8,12 @@ export function targets({wikiData}) {
 export function write(aliasArtist, {wikiData}) {
     // This function doesn't actually use wikiData, 8ut, um, consistency?
 
-    const { alias: targetArtist } = aliasArtist;
+    const { aliasedArtist } = aliasArtist;
 
     const redirect = {
         type: 'redirect',
         fromPath: ['artist', aliasArtist.directory],
-        toPath: ['artist', targetArtist.directory],
+        toPath: ['artist', aliasedArtist.directory],
         title: () => aliasArtist.name
     };
 
diff --git a/src/page/artist.js b/src/page/artist.js
index 5cdb97f1..b89107fc 100644
--- a/src/page/artist.js
+++ b/src/page/artist.js
@@ -38,9 +38,22 @@ export function write(artist, {wikiData}) {
         note = ''
     } = artist;
 
-    const artThingsAll = sortByDate(unique([...artist.albums.asCoverArtist, ...artist.albums.asWallpaperArtist, ...artist.albums.asBannerArtist, ...artist.tracks.asCoverArtist]));
-    const artThingsGallery = sortByDate([...artist.albums.asCoverArtist, ...artist.tracks.asCoverArtist]);
-    const commentaryThings = sortByDate([...artist.albums.asCommentator, ...artist.tracks.asCommentator]);
+    const artThingsAll = sortByDate(unique([
+        ...artist.albumsAsCoverArtist ?? [],
+        ...artist.albumsAsWallpaperArtist ?? [],
+        ...artist.albumsAsBannerArtist ?? [],
+        ...artist.tracksAsCoverArtist ?? []
+    ]));
+
+    const artThingsGallery = sortByDate([
+        ...artist.albumsAsCoverArtist ?? [],
+        ...artist.tracksAsCoverArtist ?? []
+    ]);
+
+    const commentaryThings = sortByDate([
+        ...artist.albumsAsCommentator ?? [],
+        ...artist.tracksAsCommentator ?? []
+    ]);
 
     const hasGallery = artThingsGallery.length > 0;
 
@@ -68,7 +81,11 @@ export function write(artist, {wikiData}) {
         track: thing.album ? thing : null
     })), ['album']);
 
-    const allTracks = sortByDate(unique([...artist.tracks.asArtist, ...artist.tracks.asContributor]));
+    const allTracks = sortByDate(unique([
+        ...artist.tracksAsArtist ?? [],
+        ...artist.tracksAsContributor ?? []
+    ]));
+
     const unreleasedTracks = allTracks.filter(track => track.album.directory === UNRELEASED_TRACKS_DIRECTORY);
     const releasedTracks = allTracks.filter(track => track.album.directory !== UNRELEASED_TRACKS_DIRECTORY);
 
@@ -115,7 +132,7 @@ export function write(artist, {wikiData}) {
 
     let flashes, flashListChunks;
     if (wikiInfo.enableFlashesAndGames) {
-        flashes = sortByDate(artist.flashes.asContributor.slice());
+        flashes = sortByDate(artist.flashesAsContributor?.slice() ?? []);
         flashListChunks = (
             chunkByProperties(flashes.map(flash => ({
                 act: flash.act,
@@ -228,21 +245,21 @@ export function write(artist, {wikiData}) {
 
             return {
                 albums: {
-                    asCoverArtist: artist.albums.asCoverArtist.map(serializeArtistsAndContrib('coverArtists')),
-                    asWallpaperArtist: artist.albums.asWallpaperArtist.map(serializeArtistsAndContrib('wallpaperArtists')),
-                    asBannerArtist: artist.albums.asBannerArtist.map(serializeArtistsAndContrib('bannerArtists'))
+                    asCoverArtist: artist.albumsAsCoverArtist?.map(serializeArtistsAndContrib('coverArtists')),
+                    asWallpaperArtist: artist.albumsAsWallpaperArtist?.map(serializeArtistsAndContrib('wallpaperArtists')),
+                    asBannerArtist: artist.albumsAsBannerArtist?.map(serializeArtistsAndContrib('bannerArtists'))
                 },
                 flashes: wikiInfo.enableFlashesAndGames ? {
-                    asContributor: artist.flashes.asContributor
-                        .map(flash => getArtistsAndContrib(flash, 'contributors'))
+                    asContributor: (artist.flashesAsContributor
+                        ?.map(flash => getArtistsAndContrib(flash, 'contributors'))
                         .map(({ contrib, thing: flash }) => ({
                             link: serializeLink(flash),
                             contribution: contrib.what
-                        }))
+                        })))
                 } : null,
                 tracks: {
-                    asArtist: artist.tracks.asArtist.map(serializeArtistsAndContrib('artists')),
-                    asContributor: artist.tracks.asContributor.map(serializeArtistsAndContrib('contributors')),
+                    asArtist: artist.tracksAsArtist.map(serializeArtistsAndContrib('artists')),
+                    asContributor: artist.tracksAsContributor.map(serializeArtistsAndContrib('contributors')),
                     chunked: {
                         released: serializeTrackListChunks(releasedTrackListChunks),
                         unreleased: serializeTrackListChunks(unreleasedTrackListChunks)
diff --git a/src/page/tag.js b/src/page/tag.js
index 60b8d217..6090cb08 100644
--- a/src/page/tag.js
+++ b/src/page/tag.js
@@ -11,7 +11,7 @@ export function condition({wikiData}) {
 }
 
 export function targets({wikiData}) {
-    return wikiData.tagData.filter(tag => !tag.isCW);
+    return wikiData.artTagData.filter(tag => !tag.isCW);
 }
 
 export function write(tag, {wikiData}) {
@@ -82,7 +82,7 @@ function generateTagNav(tag, {
     wikiData
 }) {
     const previousNextLinks = generatePreviousNextLinks(tag, {
-        data: wikiData.tagData.filter(tag => !tag.isCW),
+        data: wikiData.artTagData.filter(tag => !tag.isCW),
         linkKey: 'tag'
     });
 
diff --git a/src/upd8.js b/src/upd8.js
index 024c449c..d7d9e5ce 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -2794,6 +2794,10 @@ async function main() {
         track.artTagData = WD.artTagData;
     }
 
+    for (const artist of WD.artistData) {
+        artist.artistData = WD.artistData;
+    }
+
     // Extra organization stuff needed for listings and the like.
 
     Object.assign(wikiData, {
@@ -2841,20 +2845,22 @@ async function main() {
     WD.justEverythingSortedByArtDateMan = sortByArtDate(WD.justEverythingMan.slice());
     // console.log(JSON.stringify(justEverythingSortedByArtDateMan.map(toAnythingMan), null, 2));
 
+    WD.artistAliasData = wikiData.artistData.flatMap(artist => {
+        const origRef = Thing.getReference(artist);
+        return (artist.aliasNames?.map(name => {
+            const alias = new Artist();
+            alias.name = name;
+            alias.isAlias = true;
+            alias.aliasedArtistRef = origRef;
+            alias.artistData = WD.artistData;
+            return alias;
+        }) ?? []);
+    });
+
     // TODO: this should probably be some kinda generalized function lol
     {
         const aggregate = openAggregate({message: `Errors validating artist references in data`});
 
-        const aliasToOrigMap = new Map();
-        const aliasArtistData = wikiData.artistData.flatMap(artist => {
-            return (artist.aliasNames?.map(ref => {
-                const alias = new Artist();
-                alias.name = ref;
-                aliasToOrigMap.set(alias, artist);
-                return alias;
-            }) ?? []);
-        });
-
         const sources = [
             [WD.albumData, [
                 'artistContribsByRef',
@@ -2888,9 +2894,9 @@ async function main() {
                         thingAgg.nest({message: `Errors for property ${color.green(prop)}`}, propAgg => {
                             for (const { who: ref } of contribs) {
                                 propAgg.call(() => {
-                                    const entryAlias = find.artist(ref, {wikiData: {artistData: aliasArtistData}, quiet: true});
+                                    const entryAlias = find.artist(ref, {wikiData: {artistData: wikiData.artistAliasData}, quiet: true});
                                     if (entryAlias) {
-                                        const orig = aliasToOrigMap.get(entryAlias);
+                                        const orig = find.artist(entryAlias.aliasedArtistRef, {wikiData: {artistData: wikiData.artistData}, quiet: true});
                                         throw new Error(`Reference ${color.red(ref)} is to an alias, reference ${color.green(orig.name)} instead`);
                                     }
                                     const entry = find.artist(ref, {wikiData: {artistData: wikiData.artistData}, quiet: true});
@@ -2995,7 +3001,7 @@ async function main() {
 
     const albumAndTrackDataSortedByArtDateMan = sortByArtDate([...WD.albumData, ...WD.trackData]);
 
-    for (const tag of WD.tagData) {
+    for (const tag of WD.artTagData) {
         tag.things = albumAndTrackDataSortedByArtDateMan.filter(thing => thing.artTags.includes(tag));
     }
 
@@ -3071,8 +3077,6 @@ async function main() {
 
     logInfo`Writing site pages: ${writeAll ? 'all' : Object.keys(writeFlags).join(', ')}`;
 
-    return;
-
     await writeSymlinks();
     await writeSharedFilesAndPages({strings: defaultStrings, wikiData});
 
@@ -3103,6 +3107,12 @@ async function main() {
             }
 
             const targets = pageSpec.targets({wikiData});
+            if (!Array.isArray(targets)) {
+                logError`${flag + '.targets'} was called, but it didn't return an array! (${typeof targets})`;
+                error = true;
+                return null;
+            }
+
             return {flag, pageSpec, targets};
         }).filter(Boolean);
 
@@ -3140,6 +3150,8 @@ async function main() {
             return true;
         };
 
+        return;
+
         writes = buildStepsWithTargets.flatMap(({ flag, pageSpec, targets }) => {
             const writes = targets.flatMap(target =>
                 pageSpec.write(target, {wikiData})?.slice() || []);