« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/page/album-commentary.js146
-rw-r--r--src/page/index.js1
-rwxr-xr-xsrc/upd8.js139
-rw-r--r--src/util/wiki-data.js4
4 files changed, 151 insertions, 139 deletions
diff --git a/src/page/album-commentary.js b/src/page/album-commentary.js
new file mode 100644
index 00000000..77ca3ef1
--- /dev/null
+++ b/src/page/album-commentary.js
@@ -0,0 +1,146 @@
+// Album commentary page and index specifications.
+
+// Imports
+
+import fixWS from 'fix-whitespace';
+
+import {
+    getLinkThemeString,
+    getThemeString
+} from '../util/colors.js';
+
+import {
+    filterAlbumsByCommentary
+} from '../util/wiki-data.js';
+
+// Page exports
+
+export function condition({wikiData}) {
+    return filterAlbumsByCommentary(wikiData.albumData).length;
+}
+
+export function targets({wikiData}) {
+    return filterAlbumsByCommentary(wikiData.albumData);
+}
+
+export function write(album, {wikiData}) {
+    const { wikiInfo } = wikiData;
+
+    const entries = [album, ...album.tracks].filter(x => x.commentary).map(x => x.commentary);
+    const words = entries.join(' ').split(' ').length;
+
+    const page = {
+        type: 'page',
+        path: ['albumCommentary', album.directory],
+        page: ({
+            getAlbumStylesheet,
+            link,
+            strings,
+            to,
+            transformMultiline
+        }) => ({
+            title: strings('albumCommentaryPage.title', {album: album.name}),
+            stylesheet: getAlbumStylesheet(album),
+            theme: getThemeString(album.color),
+
+            main: {
+                content: fixWS`
+                    <div class="long-content">
+                        <h1>${strings('albumCommentaryPage.title', {
+                            album: link.album(album)
+                        })}</h1>
+                        <p>${strings('albumCommentaryPage.infoLine', {
+                            words: `<b>${strings.count.words(words, {unit: true})}</b>`,
+                            entries: `<b>${strings.count.commentaryEntries(entries.length, {unit: true})}</b>`
+                        })}</p>
+                        ${album.commentary && fixWS`
+                            <h3>${strings('albumCommentaryPage.entry.title.albumCommentary')}</h3>
+                            <blockquote>
+                                ${transformMultiline(album.commentary)}
+                            </blockquote>
+                        `}
+                        ${album.tracks.filter(t => t.commentary).map(track => fixWS`
+                            <h3 id="${track.directory}">${strings('albumCommentaryPage.entry.title.trackCommentary', {
+                                track: link.track(track)
+                            })}</h3>
+                            <blockquote style="${getLinkThemeString(track.color)}">
+                                ${transformMultiline(track.commentary)}
+                            </blockquote>
+                        `).join('\n')}
+                    </div>
+                `
+            },
+
+            nav: {
+                links: [
+                    {toHome: true},
+                    {
+                        path: ['localized.commentaryIndex'],
+                        title: strings('commentaryIndex.title')
+                    },
+                    {
+                        html: strings('albumCommentaryPage.nav.album', {
+                            album: link.albumCommentary(album, {class: 'current'})
+                        })
+                    }
+                ]
+            }
+        })
+    };
+
+    return [page];
+}
+
+export function writeTargetless({wikiData}) {
+    const data = filterAlbumsByCommentary(wikiData.albumData)
+        .map(album => ({
+            album,
+            entries: [album, ...album.tracks].filter(x => x.commentary).map(x => x.commentary)
+        }))
+        .map(({ album, entries }) => ({
+            album, entries,
+            words: entries.join(' ').split(' ').length
+        }));
+
+    const totalEntries = data.reduce((acc, {entries}) => acc + entries.length, 0);
+    const totalWords = data.reduce((acc, {words}) => acc + words, 0);
+
+    const page = {
+        type: 'page',
+        path: ['commentaryIndex'],
+        page: ({
+            link,
+            strings
+        }) => ({
+            title: strings('commentaryIndex.title'),
+
+            main: {
+                content: fixWS`
+                    <div class="long-content">
+                        <h1>${strings('commentaryIndex.title')}</h1>
+                        <p>${strings('commentaryIndex.infoLine', {
+                            words: `<b>${strings.count.words(totalWords, {unit: true})}</b>`,
+                            entries: `<b>${strings.count.commentaryEntries(totalEntries, {unit: true})}</b>`
+                        })}</p>
+                        <p>${strings('commentaryIndex.albumList.title')}</p>
+                        <ul>
+                            ${data
+                                .map(({ album, entries, words }) => fixWS`
+                                    <li>${strings('commentaryIndex.albumList.item', {
+                                        album: link.albumCommentary(album),
+                                        words: strings.count.words(words, {unit: true}),
+                                        entries: strings.count.commentaryEntries(entries.length, {unit: true})
+                                    })}</li>
+                                `)
+                                .join('\n')}
+                        </ul>
+                    </div>
+                `
+            },
+
+            nav: {simple: true}
+        })
+    };
+
+    return [page];
+}
diff --git a/src/page/index.js b/src/page/index.js
index 4ef57976..101a1688 100644
--- a/src/page/index.js
+++ b/src/page/index.js
@@ -40,6 +40,7 @@
 // pertain only to site page generation.
 
 export * as album from './album.js';
+export * as albumCommentary from './album-commentary.js';
 export * as artist from './artist.js';
 export * as artistAlias from './artist-alias.js';
 export * as flash from './flash.js';
diff --git a/src/upd8.js b/src/upd8.js
index 40e763cd..05b997ce 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -2215,145 +2215,6 @@ function generateRedirectPage(title, target, {strings}) {
     `;
 }
 
-function filterAlbumsByCommentary(albums) {
-    return albums.filter(album => [album, ...album.tracks].some(x => x.commentary));
-}
-
-function writeCommentaryPages({wikiData}) {
-    const albums = filterAlbumsByCommentary(wikiData.albumData);
-
-    if (!albums.length) {
-        return;
-    }
-
-    return [
-        writeCommentaryIndex({wikiData}),
-        ...albums.map(album => writeAlbumCommentaryPage(album, {wikiData}))
-    ];
-}
-
-function writeCommentaryIndex({wikiData}) {
-    const data = filterAlbumsByCommentary(wikiData.albumData)
-        .map(album => ({
-            album,
-            entries: [album, ...album.tracks].filter(x => x.commentary).map(x => x.commentary)
-        }))
-        .map(({ album, entries }) => ({
-            album, entries,
-            words: entries.join(' ').split(' ').length
-        }));
-
-    const totalEntries = data.reduce((acc, {entries}) => acc + entries.length, 0);
-    const totalWords = data.reduce((acc, {words}) => acc + words, 0);
-
-    const page = {
-        type: 'page',
-        path: ['commentaryIndex'],
-        page: ({
-            link,
-            strings
-        }) => ({
-            title: strings('commentaryIndex.title'),
-
-            main: {
-                content: fixWS`
-                    <div class="long-content">
-                        <h1>${strings('commentaryIndex.title')}</h1>
-                        <p>${strings('commentaryIndex.infoLine', {
-                            words: `<b>${strings.count.words(totalWords, {unit: true})}</b>`,
-                            entries: `<b>${strings.count.commentaryEntries(totalEntries, {unit: true})}</b>`
-                        })}</p>
-                        <p>${strings('commentaryIndex.albumList.title')}</p>
-                        <ul>
-                            ${data
-                                .map(({ album, entries, words }) => fixWS`
-                                    <li>${strings('commentaryIndex.albumList.item', {
-                                        album: link.albumCommentary(album),
-                                        words: strings.count.words(words, {unit: true}),
-                                        entries: strings.count.commentaryEntries(entries.length, {unit: true})
-                                    })}</li>
-                                `)
-                                .join('\n')}
-                        </ul>
-                    </div>
-                `
-            },
-
-            nav: {simple: true}
-        })
-    };
-
-    return [page];
-}
-
-function writeAlbumCommentaryPage(album, {wikiData}) {
-    const { wikiInfo } = wikiData;
-
-    const entries = [album, ...album.tracks].filter(x => x.commentary).map(x => x.commentary);
-    const words = entries.join(' ').split(' ').length;
-
-    const page = {
-        type: 'page',
-        path: ['albumCommentary', album.directory],
-        page: ({
-            getAlbumStylesheet,
-            link,
-            strings,
-            to,
-            transformMultiline
-        }) => ({
-            title: strings('albumCommentaryPage.title', {album: album.name}),
-            stylesheet: getAlbumStylesheet(album),
-            theme: getThemeString(album.color),
-
-            main: {
-                content: fixWS`
-                    <div class="long-content">
-                        <h1>${strings('albumCommentaryPage.title', {
-                            album: link.album(album)
-                        })}</h1>
-                        <p>${strings('albumCommentaryPage.infoLine', {
-                            words: `<b>${strings.count.words(words, {unit: true})}</b>`,
-                            entries: `<b>${strings.count.commentaryEntries(entries.length, {unit: true})}</b>`
-                        })}</p>
-                        ${album.commentary && fixWS`
-                            <h3>${strings('albumCommentaryPage.entry.title.albumCommentary')}</h3>
-                            <blockquote>
-                                ${transformMultiline(album.commentary)}
-                            </blockquote>
-                        `}
-                        ${album.tracks.filter(t => t.commentary).map(track => fixWS`
-                            <h3 id="${track.directory}">${strings('albumCommentaryPage.entry.title.trackCommentary', {
-                                track: link.track(track)
-                            })}</h3>
-                            <blockquote style="${getLinkThemeString(track.color)}">
-                                ${transformMultiline(track.commentary)}
-                            </blockquote>
-                        `).join('\n')}
-                    </div>
-                `
-            },
-
-            nav: {
-                links: [
-                    {toHome: true},
-                    {
-                        path: ['localized.commentaryIndex'],
-                        title: strings('commentaryIndex.title')
-                    },
-                    {
-                        html: strings('albumCommentaryPage.nav.album', {
-                            album: link.albumCommentary(album, {class: 'current'})
-                        })
-                    }
-                ]
-            }
-        })
-    };
-
-    return [page];
-}
-
 function writeTagPages({wikiData}) {
     const { tagData, wikiInfo } = wikiData;
 
diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js
index 2527a4b3..87c4b22a 100644
--- a/src/util/wiki-data.js
+++ b/src/util/wiki-data.js
@@ -93,6 +93,10 @@ export function sortByArtDate(data) {
 
 // Specific data utilities
 
+export function filterAlbumsByCommentary(albums) {
+    return albums.filter(album => [album, ...album.tracks].some(x => x.commentary));
+}
+
 export function getAlbumCover(album, {to}) {
     return to('media.albumCover', album.directory);
 }