diff options
Diffstat (limited to 'src/content/dependencies')
-rw-r--r-- | src/content/dependencies/generateWikiHomeAlbumsRow.js | 140 | ||||
-rw-r--r-- | src/content/dependencies/generateWikiHomeContentRow.js | 34 | ||||
-rw-r--r-- | src/content/dependencies/generateWikiHomePage.js | 15 |
3 files changed, 188 insertions, 1 deletions
diff --git a/src/content/dependencies/generateWikiHomeAlbumsRow.js b/src/content/dependencies/generateWikiHomeAlbumsRow.js new file mode 100644 index 00000000..1e438a12 --- /dev/null +++ b/src/content/dependencies/generateWikiHomeAlbumsRow.js @@ -0,0 +1,140 @@ +import {empty, stitchArrays} from '../../util/sugar.js'; +import {getNewAdditions, getNewReleases} from '../../util/wiki-data.js'; + +export default { + contentDependencies: [ + 'generateWikiHomeContentRow', + 'generateCoverCarousel', + 'generateCoverGrid', + 'image', + 'linkAlbum', + 'transformContent', + ], + + extraDependencies: ['wikiData'], + + sprawl({albumData}, row) { + const sprawl = {}; + + switch (row.sourceGroupByRef) { + case 'new-releases': + sprawl.albums = getNewReleases(row.countAlbumsFromGroup, {albumData}); + break; + + case 'new-additions': + sprawl.albums = getNewAdditions(row.countAlbumsFromGroup, {albumData}); + break; + + default: + sprawl.albums = + (row.sourceGroup + ? row.sourceGroup.albums + .slice() + .reverse() + .filter(album => album.isListedOnHomepage) + .slice(0, row.countAlbumsFromGroup) + : []); + } + + if (!empty(row.sourceAlbums)) { + sprawl.albums.push(...row.sourceAlbums); + } + + return sprawl; + }, + + relations(relation, sprawl, row) { + const relations = {}; + + relations.contentRow = + relation('generateWikiHomeContentRow', row); + + if (row.displayStyle === 'grid') { + relations.coverGrid = + relation('generateCoverGrid'); + } + + if (row.displayStyle === 'carousel') { + relations.coverCarousel = + relation('generateCoverCarousel'); + } + + relations.links = + sprawl.albums + .map(album => relation('linkAlbum', album)); + + relations.images = + sprawl.albums + .map(album => relation('image', album.artTags)); + + if (row.actionLinks) { + relations.actionLinks = + row.actionLinks + .map(content => relation('transformContent', content)); + } + + return relations; + }, + + data(sprawl, row) { + const data = {}; + + data.displayStyle = row.displayStyle; + + if (row.displayStyle === 'grid') { + data.names = + sprawl.albums + .map(album => album.name); + } + + data.paths = + sprawl.albums + .map(album => + ['media.albumCover', album.directory, album.coverArtFileExtension]); + + return data; + }, + + generate(data, relations) { + // Grids and carousels share some slots! Very convenient. + const commonSlots = {}; + + commonSlots.links = + relations.links; + + commonSlots.images = + stitchArrays({ + image: relations.images, + path: data.paths, + }).map(({image, path}) => + image.slot('path', path)); + + commonSlots.actionLinks = + (relations.actionLinks + ? relations.actionLinks + .map(contents => + contents + .slot('mode', 'single-link') + .content) + : null); + + let content; + + switch (data.displayStyle) { + case 'grid': + content = + relations.coverGrid.slots({ + ...commonSlots, + names: data.names, + }); + break; + + case 'carousel': + content = + relations.coverCarousel.slots(commonSlots); + break; + } + + return relations.contentRow.slots({content}); + }, +}; diff --git a/src/content/dependencies/generateWikiHomeContentRow.js b/src/content/dependencies/generateWikiHomeContentRow.js new file mode 100644 index 00000000..90622801 --- /dev/null +++ b/src/content/dependencies/generateWikiHomeContentRow.js @@ -0,0 +1,34 @@ +export default { + contentDependencies: ['generateColorStyleVariables'], + extraDependencies: ['html'], + + relations(relation, row) { + return { + colorVariables: + relation('generateColorStyleVariables', row.color), + }; + }, + + data(row) { + return { + name: row.name, + }; + }, + + slots: { + content: {type: 'html'}, + }, + + generate(data, relations, slots, {html}) { + return ( + html.tag('section', + { + class: 'row', + style: [relations.colorVariables], + }, + [ + html.tag('h2', data.name), + slots.content, + ])); + }, +}; diff --git a/src/content/dependencies/generateWikiHomePage.js b/src/content/dependencies/generateWikiHomePage.js index d3d05c40..40a6b1c5 100644 --- a/src/content/dependencies/generateWikiHomePage.js +++ b/src/content/dependencies/generateWikiHomePage.js @@ -1,6 +1,7 @@ export default { contentDependencies: [ 'generatePageLayout', + 'generateWikiHomeAlbumsRow', 'generateWikiHomeNewsBox', 'transformContent', ], @@ -37,6 +38,16 @@ export default { .map(content => relation('transformContent', content)); } + relations.contentRows = + homepageLayout.rows.map(row => { + switch (row.type) { + case 'albums': + return relation('generateWikiHomeAlbumsRow', row); + default: + return null; + } + }); + return relations; }, @@ -54,7 +65,9 @@ export default { mainClasses: ['top-index'], headingMode: 'static', - mainContent: [], + mainContent: [ + relations.contentRows, + ], leftSidebarCollapse: false, leftSidebarWide: true, |