« get me outta code hell

generateAlbumGalleryStatsLine.js « dependencies « content « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateAlbumGalleryStatsLine.js
blob: 08c0abebea617a8d65a922e54858b419a79e583c (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
import {getTotalDuration} from '#wiki-data';

export default {
  extraDependencies: ['html', 'language'],

  data(album) {
    return {
      name: album.name,
      date: album.date,
      duration: getTotalDuration(album.tracks),
      numTracks: album.tracks.length,
    };
  },

  generate(data, {html, language}) {
    const parts = ['albumGalleryPage.statsLine'];
    const options = {};

    options.tracks =
      html.tag('b',
        language.countTracks(data.numTracks, {unit: true}));

    options.duration =
      html.tag('b',
        language.formatDuration(data.duration, {unit: true}));

    if (data.date) {
      parts.push('withDate');
      options.date =
        html.tag('b',
          language.formatDate(data.date));
    }

    return (
      html.tag('p', {class: 'quick-info'},
        language.formatString(parts.join('.'), options)));
  },
};