« get me outta code hell

generateAlbumGalleryPage.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/generateAlbumGalleryPage.js
blob: 354c84011ec65df43090001b107335092852c24a (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
export default {
  contentDependencies: [
    'generateAlbumGalleryInfoLine',
    'generateAlbumNavAccent',
    'generateAlbumStyleRules',
    'generateColorStyleRules',
    'generateCoverGrid',
    'generatePageLayout',
    'image',
    'linkAlbum',
    'linkTrack',
  ],

  extraDependencies: ['html', 'language'],

  relations(relation, album) {
    const relations = {};

    relations.layout =
      relation('generatePageLayout');

    relations.albumStyleRules =
      relation('generateAlbumStyleRules', album);

    relations.colorStyleRules =
      relation('generateColorStyleRules', album.color);

    relations.albumLink =
      relation('linkAlbum', album);

    relations.albumNavAccent =
      relation('generateAlbumNavAccent', album, null);

    relations.infoLine =
      relation('generateAlbumGalleryInfoLine', album);

    relations.coverGrid =
      relation('generateCoverGrid');

    relations.links =
      album.tracks.map(track =>
        relation('linkTrack', track));

    relations.images =
      album.tracks.map(track =>
        (track.hasUniqueCoverArt
          ? relation('image', track.artTags)
          : relation('image')));

    return relations;
  },

  data(album) {
    const data = {};

    data.name = album.name;

    data.names =
      album.tracks.map(track => track.name);

    data.paths =
      album.tracks.map(track =>
        (track.hasUniqueCoverArt
          ? ['media.trackCover', track.album.directory, track.directory, track.coverArtFileExtension]
          : null));

    return data;
  },

  generate(data, relations, {language}) {
    return relations.layout
      .slots({
        title:
          language.$('albumGalleryPage.title', {
            album: data.name,
          }),

        headingMode: 'static',

        colorStyleRules: [relations.colorStyleRules],
        additionalStyleRules: [relations.albumStyleRules],

        mainClasses: ['top-index'],
        mainContent: [
          relations.infoLine,

          relations.coverGrid
            .slots({
              links: relations.links,
              names: data.names,
              images:
                relations.images.map((image, i) =>
                  image.slots({
                    path: data.paths[i],
                    missingSourceContent:
                      language.$('misc.albumGalleryGrid.noCoverArt', {
                        name: data.names[i],
                      }),
                  })),
            }),
        ],

        navLinkStyle: 'hierarchical',
        navLinks: [
          {auto: 'home'},
          {
            html:
              relations.albumLink
                .slot('attributes', {class: 'current'}),
            accent:
              relations.albumNavAccent.slots({
                showTrackNavigation: false,
                showExtraLinks: true,
                currentExtra: 'gallery',
              }),
          },
        ],
      });
  },
};