diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-02-11 10:08:54 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-02-12 07:43:58 -0400 |
commit | 6d691b3e99c67c07f53e368f376c24c8944233b8 (patch) | |
tree | e25f9159cd01fe076f401321ccb7ce17e58d9f15 /src | |
parent | bdef19f601a11c25e8d58b56d7f8135a94722505 (diff) |
content: generateWikiHomepage{*}: general expression cleanup
Diffstat (limited to 'src')
4 files changed, 94 insertions, 122 deletions
diff --git a/src/content/dependencies/generateGridActionLinks.js b/src/content/dependencies/generateGridActionLinks.js index f5b1aaa6..585a02b9 100644 --- a/src/content/dependencies/generateGridActionLinks.js +++ b/src/content/dependencies/generateGridActionLinks.js @@ -1,5 +1,3 @@ -import {empty} from '#sugar'; - export default { extraDependencies: ['html'], @@ -7,16 +5,12 @@ export default { actionLinks: {validate: v => v.sparseArrayOf(v.isHTML)}, }, - generate(slots, {html}) { - if (empty(slots.actionLinks)) { - return html.blank(); - } + generate: (slots, {html}) => + html.tag('div', {class: 'grid-actions'}, + {[html.onlyIfContent]: true}, - return ( - html.tag('div', {class: 'grid-actions'}, - slots.actionLinks - .filter(Boolean) - .map(link => link - .slot('attributes', {class: ['grid-item', 'box']})))); - }, + (slots.actionLinks ?? []) + .filter(link => link && !html.isBlank(link)) + .map(link => link + .slot('attributes', {class: ['grid-item', 'box']}))), }; diff --git a/src/content/dependencies/generateWikiHomepageAlbumsRow.js b/src/content/dependencies/generateWikiHomepageAlbumsRow.js index 047dca72..4ae48758 100644 --- a/src/content/dependencies/generateWikiHomepageAlbumsRow.js +++ b/src/content/dependencies/generateWikiHomepageAlbumsRow.js @@ -43,59 +43,50 @@ export default { return sprawl; }, - relations(relation, sprawl, row) { - const relations = {}; + relations: (relation, sprawl, row) => ({ + contentRow: + relation('generateWikiHomepageContentRow', row), - relations.contentRow = - relation('generateWikiHomepageContentRow', row); + coverGrid: + (row.displayStyle === 'grid' + ? relation('generateCoverGrid') + : null), - if (row.displayStyle === 'grid') { - relations.coverGrid = - relation('generateCoverGrid'); - } - - if (row.displayStyle === 'carousel') { - relations.coverCarousel = - relation('generateCoverCarousel'); - } + coverCarousel: + (row.displayStyle === 'carousel' + ? relation('generateCoverCarousel') + : null), - relations.links = + links: sprawl.albums - .map(album => relation('linkAlbum', album)); + .map(album => relation('linkAlbum', album)), - relations.images = + images: sprawl.albums - .map(album => relation('image', album.artTags)); - - if (row.actionLinks) { - relations.actionLinks = - row.actionLinks - .map(content => relation('transformContent', content)); - } + .map(album => relation('image', album.artTags)), - return relations; - }, - - data(sprawl, row) { - const data = {}; + actionLinks: + row.actionLinks + .map(content => relation('transformContent', content)), + }), - data.displayStyle = row.displayStyle; + data: (sprawl, row) => ({ + displayStyle: + row.displayStyle, - if (row.displayStyle === 'grid') { - data.names = - sprawl.albums - .map(album => album.name); - } + names: + (row.displayStyle === 'grid' + ? sprawl.albums + .map(album => album.name) + : null), - data.paths = + paths: sprawl.albums .map(album => (album.hasCoverArt ? ['media.albumCover', album.directory, album.coverArtFileExtension] - : null)); - - return data; - }, + : null)), + }), generate(data, relations, {language}) { // Grids and carousels share some slots! Very convenient. @@ -120,13 +111,11 @@ export default { })); commonSlots.actionLinks = - (relations.actionLinks - ? relations.actionLinks - .map(contents => - contents - .slot('mode', 'single-link') - .content) - : null); + relations.actionLinks + .map(contents => + contents + .slot('mode', 'single-link') + .content); let content; diff --git a/src/content/dependencies/generateWikiHomepageContentRow.js b/src/content/dependencies/generateWikiHomepageContentRow.js index 27b12e55..3a36033f 100644 --- a/src/content/dependencies/generateWikiHomepageContentRow.js +++ b/src/content/dependencies/generateWikiHomepageContentRow.js @@ -7,8 +7,10 @@ export default { relation('generateColorStyleAttribute', row.color), }), - data: (row) => - ({name: row.name}), + data: (row) => ({ + name: + row.name, + }), slots: { content: { diff --git a/src/content/dependencies/generateWikiHomepagePage.js b/src/content/dependencies/generateWikiHomepagePage.js index 73ab5dd4..6698f0ef 100644 --- a/src/content/dependencies/generateWikiHomepagePage.js +++ b/src/content/dependencies/generateWikiHomepagePage.js @@ -10,43 +10,37 @@ export default { extraDependencies: ['wikiData'], - sprawl({wikiInfo}) { - return { - wikiName: wikiInfo.name, + sprawl: ({wikiInfo}) => ({ + wikiName: + wikiInfo.name, - enableNews: wikiInfo.enableNews, - }; - }, + enableNews: + wikiInfo.enableNews, + }), - relations(relation, sprawl, homepageLayout) { - const relations = {}; + relations: (relation, sprawl, homepageLayout) => ({ + layout: + relation('generatePageLayout'), - relations.layout = - relation('generatePageLayout'); + sidebar: + relation('generatePageSidebar'), - relations.sidebar = - relation('generatePageSidebar'); + customSidebarBox: + relation('generatePageSidebarBox'), - if (homepageLayout.sidebarContent) { - relations.customSidebarBox = - relation('generatePageSidebarBox'); + customSidebarContent: + relation('transformContent', homepageLayout.sidebarContent), - relations.customSidebarContent = - relation('transformContent', homepageLayout.sidebarContent); - } + newsSidebarBox: + (sprawl.enableNews + ? relation('generateWikiHomepageNewsBox') + : null), - if (sprawl.enableNews) { - relations.newsSidebarBox = - relation('generateWikiHomepageNewsBox'); - } + customNavLinkContents: + homepageLayout.navbarLinks + .map(content => relation('transformContent', content)), - if (homepageLayout.navbarLinks) { - relations.customNavLinkContents = - homepageLayout.navbarLinks - .map(content => relation('transformContent', content)); - } - - relations.contentRows = + contentRows: homepageLayout.rows.map(row => { switch (row.type) { case 'albums': @@ -54,19 +48,16 @@ export default { default: return null; } - }); - - return relations; - }, + }), + }), - data(sprawl) { - return { - wikiName: sprawl.wikiName, - }; - }, + data: (sprawl) => ({ + wikiName: + sprawl.wikiName, + }), - generate(data, relations) { - return relations.layout.slots({ + generate: (data, relations) => + relations.layout.slots({ title: data.wikiName, showWikiNameInTitle: false, @@ -82,15 +73,14 @@ export default { wide: true, boxes: [ - relations.customSidebarContent && - relations.customSidebarBox.slots({ - attributes: {class: 'custom-content-sidebar-box'}, - collapsible: false, - - content: - relations.customSidebarContent - .slot('mode', 'multiline'), - }), + relations.customSidebarBox.slots({ + attributes: {class: 'custom-content-sidebar-box'}, + collapsible: false, + + content: + relations.customSidebarContent + .slot('mode', 'multiline'), + }), relations.newsSidebarBox, ], @@ -100,17 +90,14 @@ export default { navLinks: [ {auto: 'home', current: true}, - ...( - relations.customNavLinkContents - ?.map(content => ({ - html: - content.slots({ - mode: 'single-link', - preferShortLinkNames: true, - }), - })) - ?? []), + ... + relations.customNavLinkContents.map(content => ({ + html: + content.slots({ + mode: 'single-link', + preferShortLinkNames: true, + }), + })), ], - }); - }, + }), }; |