« get me outta code hell

album-commentary.js « page « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/page/album-commentary.js
blob: eb462d9acb8c44fcc86bc608a8e8ccd01eb3c725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Album commentary page and index specifications.

import {generateAlbumExtrasPageNav} from './album.js';
import {accumulateSum} from '../util/sugar.js';
import {filterAlbumsByCommentary} from '../util/wiki-data.js';

export const description = `per-album artist commentary pages & index`

export function condition({wikiData}) {
  return filterAlbumsByCommentary(wikiData.albumData).length;
}

export function targets({wikiData}) {
  return filterAlbumsByCommentary(wikiData.albumData);
}

export function write(album) {
  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,
      getLinkThemeString,
      getThemeString,
      html,
      language,
      link,
      transformMultiline,
    }) => ({
      title: language.$('albumCommentaryPage.title', {album: album.name}),
      stylesheet: getAlbumStylesheet(album),
      theme: getThemeString(album.color),

      main: {
        classes: ['long-content'],
        headingMode: 'sticky',

        content: [
          html.tag('p',
            language.$('albumCommentaryPage.infoLine', {
              words: html.tag('b', language.formatWordCount(words, {unit: true})),
              entries: html.tag('b', language.countCommentaryEntries(entries.length, {unit: true})),
            })),

          ...html.fragment(album.commentary && [
            html.tag('h3',
              {class: ['content-heading']},
              language.$('albumCommentaryPage.entry.title.albumCommentary')),

            html.tag('blockquote',
              transformMultiline(album.commentary)),
          ]),

          ...album.tracks.filter(t => t.commentary).flatMap(track => [
            html.tag('h3',
              {id: track.directory, class: ['content-heading']},
              language.$('albumCommentaryPage.entry.title.trackCommentary', {
                track: link.track(track),
              })),

            html.tag('blockquote',
              {style: getLinkThemeString(track.color)},
              transformMultiline(track.commentary)),
          ])
        ],
      },

      nav: generateAlbumExtrasPageNav(album, 'commentary', {
        html,
        language,
        link,
      }),
    }),
  };

  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 = accumulateSum(data, ({entries}) => entries.length);
  const totalWords = accumulateSum(data, ({words}) => words);

  const page = {
    type: 'page',
    path: ['commentaryIndex'],
    page: ({
      html,
      language,
      link,
    }) => ({
      title: language.$('commentaryIndex.title'),

      main: {
        classes: ['long-content'],
        headingMode: 'static',

        content: [
          html.tag('p', language.$('commentaryIndex.infoLine', {
            words: html.tag('b', language.formatWordCount(totalWords, {unit: true})),
            entries: html.tag('b', language.countCommentaryEntries(totalEntries, {unit: true})),
          })),

          html.tag('p', language.$('commentaryIndex.albumList.title')),

          html.tag('ul', data.map(({album, entries, words}) =>
            html.tag('li', language.$('commentaryIndex.albumList.item', {
              album: link.albumCommentary(album),
              words: language.formatWordCount(words, {unit: true}),
              entries: language.countCommentaryEntries(entries.length, {unit: true}),
            })))),
        ],
      },

      nav: {simple: true},
    }),
  };

  return [page];
}