« get me outta code hell

move around a bunch of utility functions - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/page
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-06-04 17:30:16 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-06-04 17:30:16 -0300
commitb2469c03bd4bdb29c5e80752f812203a6755c159 (patch)
tree85f951c70568457a78c25055bb600709de4214cb /src/page
parentc7e4b06ff1e899659f043ebfbd3723152b0c93d9 (diff)
move around a bunch of utility functions
Diffstat (limited to 'src/page')
-rw-r--r--src/page/album-commentary.js7
-rw-r--r--src/page/album.js275
-rw-r--r--src/page/flash.js7
-rw-r--r--src/page/group.js32
-rw-r--r--src/page/homepage.js5
-rw-r--r--src/page/listing.js77
-rw-r--r--src/page/tag.js5
-rw-r--r--src/page/track.js7
8 files changed, 218 insertions, 197 deletions
diff --git a/src/page/album-commentary.js b/src/page/album-commentary.js
index 77ca3ef1..c03ae3db 100644
--- a/src/page/album-commentary.js
+++ b/src/page/album-commentary.js
@@ -5,11 +5,6 @@
 import fixWS from 'fix-whitespace';
 
 import {
-    getLinkThemeString,
-    getThemeString
-} from '../util/colors.js';
-
-import {
     filterAlbumsByCommentary
 } from '../util/wiki-data.js';
 
@@ -34,6 +29,8 @@ export function write(album, {wikiData}) {
         path: ['albumCommentary', album.directory],
         page: ({
             getAlbumStylesheet,
+            getLinkThemeString,
+            getThemeString,
             link,
             strings,
             to,
diff --git a/src/page/album.js b/src/page/album.js
index 16da6021..adcc0584 100644
--- a/src/page/album.js
+++ b/src/page/album.js
@@ -4,14 +4,13 @@
 
 import fixWS from 'fix-whitespace';
 
-import {
-    getLinkThemeString,
-    getThemeString
-} from '../util/colors.js';
-
 import * as html from '../util/html.js';
 
 import {
+    bindOpts
+} from '../util/sugar.js';
+
+import {
     getAlbumCover,
     getAlbumListTag,
     getTotalDuration
@@ -26,7 +25,12 @@ export function targets({wikiData}) {
 export function write(album, {wikiData}) {
     const { wikiInfo } = wikiData;
 
-    const trackToListItem = (track, {getArtistString, link, strings}) => {
+    const unbound_trackToListItem = (track, {
+        getArtistString,
+        getLinkThemeString,
+        link,
+        strings
+    }) => {
         const itemOpts = {
             duration: strings.count.duration(track.duration),
             track: link.track(track)
@@ -96,140 +100,152 @@ export function write(album, {wikiData}) {
             generateCoverLink,
             getAlbumStylesheet,
             getArtistString,
+            getLinkThemeString,
+            getThemeString,
             link,
             strings,
             transformMultiline
-        }) => ({
-            title: strings('albumPage.title', {album: album.name}),
-            stylesheet: getAlbumStylesheet(album),
-            theme: getThemeString(album.color, [
-                `--album-directory: ${album.directory}`
-            ]),
+        }) => {
+            const trackToListItem = bindOpts(unbound_trackToListItem, {
+                getArtistString,
+                getLinkThemeString,
+                link,
+                strings
+            });
 
-            banner: album.bannerArtists && {
-                dimensions: album.bannerDimensions,
-                path: ['media.albumBanner', album.directory],
-                alt: strings('misc.alt.albumBanner'),
-                position: 'top'
-            },
+            return {
+                title: strings('albumPage.title', {album: album.name}),
+                stylesheet: getAlbumStylesheet(album),
+                theme: getThemeString(album.color, [
+                    `--album-directory: ${album.directory}`
+                ]),
 
-            main: {
-                content: fixWS`
-                    ${generateCoverLink({
-                        path: ['media.albumCover', album.directory],
-                        alt: strings('misc.alt.albumCover'),
-                        tags: album.artTags
-                    })}
-                    <h1>${strings('albumPage.title', {album: album.name})}</h1>
-                    <p>
-                        ${[
-                            album.artists && strings('releaseInfo.by', {
-                                artists: getArtistString(album.artists, {
-                                    showContrib: true,
-                                    showIcons: true
-                                })
-                            }),
-                            album.coverArtists && strings('releaseInfo.coverArtBy', {
-                                artists: getArtistString(album.coverArtists, {
-                                    showContrib: true,
-                                    showIcons: true
-                                })
-                            }),
-                            album.wallpaperArtists && strings('releaseInfo.wallpaperArtBy', {
-                                artists: getArtistString(album.wallpaperArtists, {
-                                    showContrib: true,
-                                    showIcons: true
+                banner: album.bannerArtists && {
+                    dimensions: album.bannerDimensions,
+                    path: ['media.albumBanner', album.directory],
+                    alt: strings('misc.alt.albumBanner'),
+                    position: 'top'
+                },
+
+                main: {
+                    content: fixWS`
+                        ${generateCoverLink({
+                            path: ['media.albumCover', album.directory],
+                            alt: strings('misc.alt.albumCover'),
+                            tags: album.artTags
+                        })}
+                        <h1>${strings('albumPage.title', {album: album.name})}</h1>
+                        <p>
+                            ${[
+                                album.artists && strings('releaseInfo.by', {
+                                    artists: getArtistString(album.artists, {
+                                        showContrib: true,
+                                        showIcons: true
+                                    })
+                                }),
+                                album.coverArtists && strings('releaseInfo.coverArtBy', {
+                                    artists: getArtistString(album.coverArtists, {
+                                        showContrib: true,
+                                        showIcons: true
+                                    })
+                                }),
+                                album.wallpaperArtists && strings('releaseInfo.wallpaperArtBy', {
+                                    artists: getArtistString(album.wallpaperArtists, {
+                                        showContrib: true,
+                                        showIcons: true
+                                    })
+                                }),
+                                album.bannerArtists && strings('releaseInfo.bannerArtBy', {
+                                    artists: getArtistString(album.bannerArtists, {
+                                        showContrib: true,
+                                        showIcons: true
+                                    })
+                                }),
+                                strings('releaseInfo.released', {
+                                    date: strings.count.date(album.date)
+                                }),
+                                +album.coverArtDate !== +album.date && strings('releaseInfo.artReleased', {
+                                    date: strings.count.date(album.coverArtDate)
+                                }),
+                                strings('releaseInfo.duration', {
+                                    duration: strings.count.duration(albumDuration, {approximate: album.tracks.length > 1})
                                 })
-                            }),
-                            album.bannerArtists && strings('releaseInfo.bannerArtBy', {
-                                artists: getArtistString(album.bannerArtists, {
-                                    showContrib: true,
-                                    showIcons: true
+                            ].filter(Boolean).join('<br>\n')}
+                        </p>
+                        ${commentaryEntries && `<p>${
+                            strings('releaseInfo.viewCommentary', {
+                                link: link.albumCommentary(album, {
+                                    text: strings('releaseInfo.viewCommentary.link')
                                 })
-                            }),
-                            strings('releaseInfo.released', {
-                                date: strings.count.date(album.date)
-                            }),
-                            +album.coverArtDate !== +album.date && strings('releaseInfo.artReleased', {
-                                date: strings.count.date(album.coverArtDate)
-                            }),
-                            strings('releaseInfo.duration', {
-                                duration: strings.count.duration(albumDuration, {approximate: album.tracks.length > 1})
-                            })
-                        ].filter(Boolean).join('<br>\n')}
-                    </p>
-                    ${commentaryEntries && `<p>${
-                        strings('releaseInfo.viewCommentary', {
-                            link: link.albumCommentary(album, {
-                                text: strings('releaseInfo.viewCommentary.link')
                             })
-                        })
-                    }</p>`}
-                    ${album.urls.length && `<p>${
-                        strings('releaseInfo.listenOn', {
-                            links: strings.list.or(album.urls.map(url => fancifyURL(url, {album: true})))
-                        })
-                    }</p>`}
-                    ${album.trackGroups ? fixWS`
-                        <dl class="album-group-list">
-                            ${album.trackGroups.map(({ name, color, startIndex, tracks }) => fixWS`
-                                <dt>${
-                                    strings('trackList.group', {
-                                        duration: strings.count.duration(getTotalDuration(tracks), {approximate: tracks.length > 1}),
-                                        group: name
-                                    })
-                                }</dt>
-                                <dd><${listTag === 'ol' ? `ol start="${startIndex + 1}"` : listTag}>
-                                    ${tracks.map(t => trackToListItem(t, {getArtistString, link, strings})).join('\n')}
-                                </${listTag}></dd>
-                            `).join('\n')}
-                        </dl>
-                    ` : fixWS`
-                        <${listTag}>
-                            ${album.tracks.map(t => trackToListItem(t, {getArtistString, link, strings})).join('\n')}
-                        </${listTag}>
-                    `}
-                    <p>
-                        ${[
-                            strings('releaseInfo.addedToWiki', {
-                                date: strings.count.date(album.dateAdded)
+                        }</p>`}
+                        ${album.urls.length && `<p>${
+                            strings('releaseInfo.listenOn', {
+                                links: strings.list.or(album.urls.map(url => fancifyURL(url, {album: true})))
                             })
-                        ].filter(Boolean).join('<br>\n')}
-                    </p>
-                    ${album.commentary && fixWS`
-                        <p>${strings('releaseInfo.artistCommentary')}</p>
-                        <blockquote>
-                            ${transformMultiline(album.commentary)}
-                        </blockquote>
-                    `}
-                `
-            },
+                        }</p>`}
+                        ${album.trackGroups ? fixWS`
+                            <dl class="album-group-list">
+                                ${album.trackGroups.map(({ name, color, startIndex, tracks }) => fixWS`
+                                    <dt>${
+                                        strings('trackList.group', {
+                                            duration: strings.count.duration(getTotalDuration(tracks), {approximate: tracks.length > 1}),
+                                            group: name
+                                        })
+                                    }</dt>
+                                    <dd><${listTag === 'ol' ? `ol start="${startIndex + 1}"` : listTag}>
+                                        ${tracks.map(trackToListItem).join('\n')}
+                                    </${listTag}></dd>
+                                `).join('\n')}
+                            </dl>
+                        ` : fixWS`
+                            <${listTag}>
+                                ${album.tracks.map(trackToListItem).join('\n')}
+                            </${listTag}>
+                        `}
+                        <p>
+                            ${[
+                                strings('releaseInfo.addedToWiki', {
+                                    date: strings.count.date(album.dateAdded)
+                                })
+                            ].filter(Boolean).join('<br>\n')}
+                        </p>
+                        ${album.commentary && fixWS`
+                            <p>${strings('releaseInfo.artistCommentary')}</p>
+                            <blockquote>
+                                ${transformMultiline(album.commentary)}
+                            </blockquote>
+                        `}
+                    `
+                },
 
-            sidebarLeft: generateAlbumSidebar(album, null, {
-                fancifyURL,
-                link,
-                strings,
-                transformMultiline,
-                wikiData
-            }),
+                sidebarLeft: generateAlbumSidebar(album, null, {
+                    fancifyURL,
+                    getLinkThemeString,
+                    link,
+                    strings,
+                    transformMultiline,
+                    wikiData
+                }),
 
-            nav: {
-                links: [
-                    {toHome: true},
-                    {
-                        html: strings('albumPage.nav.album', {
-                            album: link.album(album, {class: 'current'})
-                        })
-                    },
-                    album.tracks.length > 1 &&
-                    {
-                        divider: false,
-                        html: generateAlbumNavLinks(album, null, {strings})
-                    }
-                ],
-                content: html.tag('div', generateAlbumChronologyLinks(album, null, {generateChronologyLinks}))
-            }
-        })
+                nav: {
+                    links: [
+                        {toHome: true},
+                        {
+                            html: strings('albumPage.nav.album', {
+                                album: link.album(album, {class: 'current'})
+                            })
+                        },
+                        album.tracks.length > 1 &&
+                        {
+                            divider: false,
+                            html: generateAlbumNavLinks(album, null, {strings})
+                        }
+                    ],
+                    content: html.tag('div', generateAlbumChronologyLinks(album, null, {generateChronologyLinks}))
+                }
+            };
+        }
     };
 
     return [page, data];
@@ -239,6 +255,7 @@ export function write(album, {wikiData}) {
 
 export function generateAlbumSidebar(album, currentTrack, {
     fancifyURL,
+    getLinkThemeString,
     link,
     strings,
     transformMultiline,
diff --git a/src/page/flash.js b/src/page/flash.js
index 4ffaefc6..9c59016d 100644
--- a/src/page/flash.js
+++ b/src/page/flash.js
@@ -4,11 +4,6 @@
 
 import fixWS from 'fix-whitespace';
 
-import {
-    getLinkThemeString,
-    getThemeString
-} from '../util/colors.js';
-
 import * as html from '../util/html.js';
 
 import {
@@ -36,6 +31,7 @@ export function write(flash, {wikiData}) {
             generatePreviousNextLinks,
             getArtistString,
             getFlashCover,
+            getThemeString,
             link,
             strings,
             transformInline
@@ -118,6 +114,7 @@ export function writeTargetless({wikiData}) {
         path: ['flashIndex'],
         page: ({
             getFlashGridHTML,
+            getLinkThemeString,
             link,
             strings
         }) => ({
diff --git a/src/page/group.js b/src/page/group.js
index 5db5a8ff..698c17ec 100644
--- a/src/page/group.js
+++ b/src/page/group.js
@@ -8,11 +8,6 @@ import {
     UNRELEASED_TRACKS_DIRECTORY
 } from '../util/magic-constants.js';
 
-import {
-    getLinkThemeString,
-    getThemeString
-} from '../util/colors.js';
-
 import * as html from '../util/html.js';
 
 import {
@@ -44,6 +39,8 @@ export function write(group, {wikiData}) {
         page: ({
             generateInfoGalleryLinks,
             generatePreviousNextLinks,
+            getLinkThemeString,
+            getThemeString,
             fancifyURL,
             link,
             strings,
@@ -92,7 +89,13 @@ export function write(group, {wikiData}) {
                 `
             },
 
-            sidebarLeft: generateGroupSidebar(group, false, {link, strings, wikiData}),
+            sidebarLeft: generateGroupSidebar(group, false, {
+                getLinkThemeString,
+                link,
+                strings,
+                wikiData
+            }),
+
             nav: generateGroupNav(group, false, {
                 generateInfoGalleryLinks,
                 generatePreviousNextLinks,
@@ -110,6 +113,8 @@ export function write(group, {wikiData}) {
             generateInfoGalleryLinks,
             generatePreviousNextLinks,
             getAlbumGridHTML,
+            getLinkThemeString,
+            getThemeString,
             link,
             strings
         }) => ({
@@ -144,7 +149,13 @@ export function write(group, {wikiData}) {
                 `
             },
 
-            sidebarLeft: generateGroupSidebar(group, true, {link, strings, wikiData}),
+            sidebarLeft: generateGroupSidebar(group, true, {
+                getLinkThemeString,
+                link,
+                strings,
+                wikiData
+            }),
+
             nav: generateGroupNav(group, true, {
                 generateInfoGalleryLinks,
                 generatePreviousNextLinks,
@@ -160,7 +171,12 @@ export function write(group, {wikiData}) {
 
 // Utility functions
 
-function generateGroupSidebar(currentGroup, isGallery, {link, strings, wikiData}) {
+function generateGroupSidebar(currentGroup, isGallery, {
+    getLinkThemeString,
+    link,
+    strings,
+    wikiData
+}) {
     const { groupCategoryData, wikiInfo } = wikiData;
 
     if (!wikiInfo.features.groupUI) {
diff --git a/src/page/homepage.js b/src/page/homepage.js
index d1dcc680..37ec4426 100644
--- a/src/page/homepage.js
+++ b/src/page/homepage.js
@@ -4,10 +4,6 @@
 
 import fixWS from 'fix-whitespace';
 
-import {
-    getLinkThemeString
-} from '../util/colors.js';
-
 import find from '../util/find.js';
 
 import * as html from '../util/html.js';
@@ -27,6 +23,7 @@ export function writeTargetless({wikiData}) {
         path: ['home'],
         page: ({
             getAlbumGridHTML,
+            getLinkThemeString,
             link,
             strings,
             to,
diff --git a/src/page/listing.js b/src/page/listing.js
index b0766b28..d4021747 100644
--- a/src/page/listing.js
+++ b/src/page/listing.js
@@ -46,44 +46,45 @@ export function write(listing, {wikiData}) {
     const page = {
         type: 'page',
         path: ['listing', listing.directory],
-        page: ({
-            link,
-            strings
-        }) => ({
-            title: listing.title({strings}),
-
-            main: {
-                content: fixWS`
-                    <h1>${listing.title({strings})}</h1>
-                    ${listing.html && (listing.data
-                        ? listing.html(data, {link, strings})
-                        : listing.html({link, strings}))}
-                    ${listing.row && fixWS`
-                        <ul>
-                            ${(data
-                                .map(item => listing.row(item, {link, strings}))
-                                .map(row => `<li>${row}</li>`)
-                                .join('\n'))}
-                        </ul>
-                    `}
-                `
-            },
-
-            sidebarLeft: {
-                content: generateSidebarForListings(listing, {link, strings, wikiData})
-            },
-
-            nav: {
-                links: [
-                    {toHome: true},
-                    {
-                        path: ['localized.listingIndex'],
-                        title: strings('listingIndex.title')
-                    },
-                    {toCurrentPage: true}
-                ]
-            }
-        })
+        page: opts => {
+            const { link, strings } = opts;
+
+            return {
+                title: listing.title({strings}),
+
+                main: {
+                    content: fixWS`
+                        <h1>${listing.title({strings})}</h1>
+                        ${listing.html && (listing.data
+                            ? listing.html(data, opts)
+                            : listing.html(opts))}
+                        ${listing.row && fixWS`
+                            <ul>
+                                ${(data
+                                    .map(item => listing.row(item, opts))
+                                    .map(row => `<li>${row}</li>`)
+                                    .join('\n'))}
+                            </ul>
+                        `}
+                    `
+                },
+
+                sidebarLeft: {
+                    content: generateSidebarForListings(listing, {link, strings, wikiData})
+                },
+
+                nav: {
+                    links: [
+                        {toHome: true},
+                        {
+                            path: ['localized.listingIndex'],
+                            title: strings('listingIndex.title')
+                        },
+                        {toCurrentPage: true}
+                    ]
+                }
+            };
+        }
     };
 
     return [page];
diff --git a/src/page/tag.js b/src/page/tag.js
index c6f64bfc..610f4665 100644
--- a/src/page/tag.js
+++ b/src/page/tag.js
@@ -4,10 +4,6 @@
 
 import fixWS from 'fix-whitespace';
 
-import {
-    getThemeString
-} from '../util/colors.js';
-
 // Page exports
 
 export function condition({wikiData}) {
@@ -28,6 +24,7 @@ export function write(tag, {wikiData}) {
         page: ({
             getAlbumCover,
             getGridHTML,
+            getThemeString,
             getTrackCover,
             link,
             strings,
diff --git a/src/page/track.js b/src/page/track.js
index 2dec9bd3..0941ee89 100644
--- a/src/page/track.js
+++ b/src/page/track.js
@@ -10,10 +10,6 @@ import {
     generateAlbumSidebar
 } from './album.js';
 
-import {
-    getThemeString
-} from '../util/colors.js';
-
 import * as html from '../util/html.js';
 
 import {
@@ -134,6 +130,8 @@ export function write(track, {wikiData}) {
             generatePreviousNextLinks,
             getAlbumStylesheet,
             getArtistString,
+            getLinkThemeString,
+            getThemeString,
             getTrackCover,
             link,
             strings,
@@ -284,6 +282,7 @@ export function write(track, {wikiData}) {
 
                 sidebarLeft: generateAlbumSidebar(album, track, {
                     fancifyURL,
+                    getLinkThemeString,
                     link,
                     strings,
                     transformMultiline,