Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
towerofnix committed Feb 24, 2024
1 parent 410d11c commit a4ae6e7
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 100 deletions.
49 changes: 15 additions & 34 deletions src/content/dependencies/listAlbumsByDuration.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,25 @@
import {sortAlphabetically, sortByCount} from '#sort';
import {filterByCount, stitchArrays} from '#sugar';
import {getTotalDuration} from '#wiki-data';
import {stitchArrays} from '#sugar';

export default {
contentDependencies: ['generateListingPage', 'linkAlbum'],
extraDependencies: ['language', 'wikiData'],

sprawl({albumData}) {
return {albumData};
},
relations: (relation, listing) => ({
page:
relation('generateListingPage', listing),

query({albumData}, spec) {
const albums = sortAlphabetically(albumData.slice());
const durations = albums.map(album => getTotalDuration(album.tracks));
albumLinks:
listing.data.albums
.map(album => relation('linkAlbum', album)),
}),

filterByCount(albums, durations);
sortByCount(albums, durations, {greatestFirst: true});
data: (listing) => ({
durations:
listing.data.durations,
}),

return {spec, albums, durations};
},

relations(relation, query) {
return {
page: relation('generateListingPage', query.spec),

albumLinks:
query.albums
.map(album => relation('linkAlbum', album)),
};
},

data(query) {
return {
durations: query.durations,
};
},

generate(data, relations, {language}) {
return relations.page.slots({
generate: (data, relations, {language}) =>
relations.page.slots({
type: 'rows',
rows:
stitchArrays({
Expand All @@ -47,6 +29,5 @@ export default {
album: link,
duration: language.formatDuration(duration),
})),
});
},
}),
};
48 changes: 16 additions & 32 deletions src/content/dependencies/listAlbumsByName.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,26 @@
import {sortAlphabetically} from '#sort';
import {stitchArrays} from '#sugar';

export default {
contentDependencies: ['generateListingPage', 'linkAlbum'],
extraDependencies: ['language', 'wikiData'],
extraDependencies: ['language'],

sprawl({albumData}) {
return {albumData};
},
relations: (relation, listing) => ({
page:
relation('generateListingPage', listing),

query({albumData}, spec) {
return {
spec,
albums: sortAlphabetically(albumData.slice()),
};
},
albumLinks:
listing.data
.map(album => relation('linkAlbum', album)),
}),

relations(relation, query) {
return {
page: relation('generateListingPage', query.spec),
data: (listing) => ({
counts:
listing.data
.map(album => album.tracks.length),
}),

albumLinks:
query.albums
.map(album => relation('linkAlbum', album)),
};
},

data(query) {
return {
counts:
query.albums
.map(album => album.tracks.length),
};
},

generate(data, relations, {language}) {
return relations.page.slots({
generate: (data, relations, {language}) =>
relations.page.slots({
type: 'rows',
rows:
stitchArrays({
Expand All @@ -45,6 +30,5 @@ export default {
album: link,
tracks: language.countTracks(count, {unit: true}),
})),
});
},
}),
};
50 changes: 16 additions & 34 deletions src/content/dependencies/listAlbumsByTracks.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
import {sortAlphabetically, sortByCount} from '#sort';
import {filterByCount, stitchArrays} from '#sugar';
import {stitchArrays} from '#sugar';

export default {
contentDependencies: ['generateListingPage', 'linkAlbum'],
extraDependencies: ['language', 'wikiData'],
extraDependencies: ['language'],

sprawl({albumData}) {
return {albumData};
},
relations: (relation, listing) => ({
page:
relation('generateListingPage', listing),

query({albumData}, spec) {
const albums = sortAlphabetically(albumData.slice());
const counts = albums.map(album => album.tracks.length);
albumLinks:
listing.data.albums
.map(album => relation('linkAlbum', album)),
}),

filterByCount(albums, counts);
sortByCount(albums, counts, {greatestFirst: true});
data: (listing) => ({
counts:
listing.data.counts,
}),

return {spec, albums, counts};
},

relations(relation, query) {
return {
page: relation('generateListingPage', query.spec),

albumLinks:
query.albums
.map(album => relation('linkAlbum', album)),
};
},

data(query) {
return {
counts: query.counts,
};
},

generate(data, relations, {language}) {
return relations.page.slots({
generate: (data, relations, {language}) =>
relations.page.slots({
type: 'rows',
rows:
stitchArrays({
Expand All @@ -46,6 +29,5 @@ export default {
album: link,
tracks: language.countTracks(count, {unit: true}),
})),
});
},
}),
};
46 changes: 46 additions & 0 deletions src/listing-spec/wiki/albums/by-duration.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,54 @@
import {input} from '#composite';
import {sortAlphabetically, sortByCount} from '#sort';
import {filterByCount} from '#sugar';
import {getTotalDuration} from '#wiki-data';

import {exitWithoutDependency} from '#composite/control-flow';
import {withMappedList, withPropertyFromList} from '#composite/data';
import {withThingsSortedAlphabetically} from '#composite/wiki-data';

export default {
scope: 'wiki',
directory: 'albums/by-duration',
target: 'album',

stringsKey: 'listAlbums.byDuration',
contentFunction: 'listAlbumsByDuration',

data: () => [
exitWithoutDependency({
dependency: 'albumData',
value: input.value([]),
}),

withThingsSortedAlphabetically({
things: 'albumData',
}).outputs({
'#sortedThings': '#albums',
}),

withPropertyFromList({
list: '#albums',
property: input.value('tracks'),
}),

withMappedList({
list: '#albums.tracks',
map: input.value(getTotalDuration)
}).outputs({
'#mappedList': '#durations',
}),

{
dependencies: ['#albums', '#durations'],
compute: ({
['#albums']: albums,
['#durations']: durations,
}) => {
filterByCount(albums, durations);
sortByCount(albums, durations, {greatestFirst: true});
return {albums, durations};
},
},
],
};
21 changes: 21 additions & 0 deletions src/listing-spec/wiki/albums/by-name.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {input} from '#composite';

import {exitWithoutDependency, exposeDependency}
from '#composite/control-flow';
import {withThingsSortedAlphabetically} from '#composite/wiki-data';

export default {
scope: 'wiki',
directory: 'albums/by-name',
Expand All @@ -9,4 +15,19 @@ export default {
seeAlsoListings: [
'tracks/by-album',
],

data: () => [
exitWithoutDependency({
dependency: 'albumData',
value: input.value([]),
}),

withThingsSortedAlphabetically({
things: 'albumData',
}),

exposeDependency({
dependency: '#sortedThings',
}),
],
};
45 changes: 45 additions & 0 deletions src/listing-spec/wiki/albums/by-tracks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,53 @@
import {input} from '#composite';
import {sortByCount} from '#sort';
import {filterByCount} from '#sugar';

import {exitWithoutDependency} from '#composite/control-flow';
import {withPropertyFromList} from '#composite/data';
import {withThingsSortedAlphabetically} from '#composite/wiki-data';

export default {
scope: 'wiki',
directory: 'albums/by-tracks',
target: 'album',

stringsKey: 'listAlbums.byTracks',
contentFunction: 'listAlbumsByTracks',

data: () => [
exitWithoutDependency({
dependency: 'albumData',
value: input.value([]),
}),

withThingsSortedAlphabetically({
things: 'albumData',
}).outputs({
'#sortedThings': '#albums',
}),

withPropertyFromList({
list: '#albums',
property: input.value('tracks'),
}),

withPropertyFromList({
list: '#albums.tracks',
property: input.value('length'),
}).outputs({
'#albums.tracks.length': '#counts',
}),

{
dependencies: ['#albums', '#counts'],
compute: ({
['#albums']: albums,
['#counts']: counts,
}) => {
filterByCount(albums, counts);
sortByCount(albums, counts, {greatestFirst: true});
return {albums, counts};
},
},
],
};

0 comments on commit a4ae6e7

Please sign in to comment.