« get me outta code hell

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:
Diffstat (limited to 'src/page')
-rw-r--r--src/page/index.js3
-rw-r--r--src/page/tag.js76
2 files changed, 78 insertions, 1 deletions
diff --git a/src/page/index.js b/src/page/index.js
index 101a1688..f580cbea 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 00000000..c6f64bfc
--- /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];
+}
+