« get me outta code hell

module-ify tag pages - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-06-04 16:27:15 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-06-04 16:27:15 -0300
commit9fb4baa667f76c51abc0c6469d95351f90266a6a (patch)
tree0a6e55cd98275e1a66af6abeaf082c4c10df7fc7
parentc60b3722f23d88680c7ceee72c32ef87545752ea (diff)
module-ify tag pages
-rw-r--r--src/page/index.js3
-rw-r--r--src/page/tag.js76
-rwxr-xr-xsrc/upd8.js68
3 files changed, 78 insertions, 69 deletions
diff --git a/src/page/index.js b/src/page/index.js
index 101a168..f580cbe 100644
--- a/src/page/index.js
+++ b/src/page/index.js
@@ -47,6 +47,7 @@ export * as flash from './flash.js';
 export * as group from './group.js';
 export * as homepage from './homepage.js';
 export * as listing from './listing.js';
-export * as static from './static.js';
 export * as news from './news.js';
+export * as static from './static.js';
+export * as tag from './tag.js';
 export * as track from './track.js';
diff --git a/src/page/tag.js b/src/page/tag.js
new file mode 100644
index 0000000..c6f64bf
--- /dev/null
+++ b/src/page/tag.js
@@ -0,0 +1,76 @@
+// Art tag page specification.
+
+// Imports
+
+import fixWS from 'fix-whitespace';
+
+import {
+    getThemeString
+} from '../util/colors.js';
+
+// Page exports
+
+export function condition({wikiData}) {
+    return wikiData.wikiInfo.features.artTagUI;
+}
+
+export function targets({wikiData}) {
+    return wikiData.tagData.filter(tag => !tag.isCW);
+}
+
+export function write(tag, {wikiData}) {
+    const { wikiInfo } = wikiData;
+    const { things } = tag;
+
+    const page = {
+        type: 'page',
+        path: ['tag', tag.directory],
+        page: ({
+            getAlbumCover,
+            getGridHTML,
+            getTrackCover,
+            link,
+            strings,
+            to
+        }) => ({
+            title: strings('tagPage.title', {tag: tag.name}),
+            theme: getThemeString(tag.color),
+
+            main: {
+                classes: ['top-index'],
+                content: fixWS`
+                    <h1>${strings('tagPage.title', {tag: tag.name})}</h1>
+                    <p class="quick-info">${strings('tagPage.infoLine', {
+                        coverArts: strings.count.coverArts(things.length, {unit: true})
+                    })}</p>
+                    <div class="grid-listing">
+                        ${getGridHTML({
+                            entries: things.map(item => ({item})),
+                            srcFn: thing => (thing.album
+                                ? getTrackCover(thing)
+                                : getAlbumCover(thing)),
+                            hrefFn: thing => (thing.album
+                                ? to('localized.track', thing.directory)
+                                : to('localized.album', thing.directory))
+                        })}
+                    </div>
+                `
+            },
+
+            nav: {
+                links: [
+                    {toHome: true},
+                    wikiInfo.features.listings &&
+                    {
+                        path: ['localized.listingIndex'],
+                        title: strings('listingIndex.title')
+                    },
+                    {toCurrentPage: true}
+                ]
+            }
+        })
+    };
+
+    return [page];
+}
+
diff --git a/src/upd8.js b/src/upd8.js
index 05b997c..1aa1b5d 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -2215,74 +2215,6 @@ function generateRedirectPage(title, target, {strings}) {
     `;
 }
 
-function writeTagPages({wikiData}) {
-    const { tagData, wikiInfo } = wikiData;
-
-    if (!wikiInfo.features.artTagUI) {
-        return;
-    }
-
-    return tagData
-        .filter(tag => !tag.isCW)
-        .map(tag => writeTagPage(tag, {wikiData}));
-}
-
-function writeTagPage(tag, {wikiData}) {
-    const { wikiInfo } = wikiData;
-    const { things } = tag;
-
-    const page = {
-        type: 'page',
-        path: ['tag', tag.directory],
-        page: ({
-            getAlbumCover,
-            getGridHTML,
-            getTrackCover,
-            link,
-            strings,
-            to
-        }) => ({
-            title: strings('tagPage.title', {tag: tag.name}),
-            theme: getThemeString(tag.color),
-
-            main: {
-                classes: ['top-index'],
-                content: fixWS`
-                    <h1>${strings('tagPage.title', {tag: tag.name})}</h1>
-                    <p class="quick-info">${strings('tagPage.infoLine', {
-                        coverArts: strings.count.coverArts(things.length, {unit: true})
-                    })}</p>
-                    <div class="grid-listing">
-                        ${getGridHTML({
-                            entries: things.map(item => ({item})),
-                            srcFn: thing => (thing.album
-                                ? getTrackCover(thing)
-                                : getAlbumCover(thing)),
-                            hrefFn: thing => (thing.album
-                                ? to('localized.track', thing.directory)
-                                : to('localized.album', thing.directory))
-                        })}
-                    </div>
-                `
-            },
-
-            nav: {
-                links: [
-                    {toHome: true},
-                    wikiInfo.features.listings &&
-                    {
-                        path: ['localized.listingIndex'],
-                        title: strings('listingIndex.title')
-                    },
-                    {toCurrentPage: true}
-                ]
-            }
-        })
-    };
-
-    return [page];
-}
-
 function getArtistString(artists, {
     iconifyURL, link, strings,
     showIcons = false,