« get me outta code hell

generateAlbumStyleRules.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/generateAlbumStyleRules.js
blob: 1acaea174234ff237a4cd03bb3f5b6bb5469b3b3 (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
import {empty} from '#sugar';

export default {
  extraDependencies: ['to'],

  data(album) {
    const data = {};

    data.hasWallpaper = !empty(album.wallpaperArtistContribs);
    data.hasBanner = !empty(album.bannerArtistContribs);

    if (data.hasWallpaper) {
      data.hasWallpaperStyle = !!album.wallpaperStyle;
      data.wallpaperPath = ['media.albumWallpaper', album.directory, album.wallpaperFileExtension];
      data.wallpaperStyle = album.wallpaperStyle;
    }

    if (data.hasBanner) {
      data.hasBannerStyle = !!album.bannerStyle;
      data.bannerStyle = album.bannerStyle;
    }

    return data;
  },

  generate(data, {to}) {
    const wallpaperPart =
      (data.hasWallpaper
        ? [
            `body::before {`,
            `    background-image: url("${to(...data.wallpaperPath)}");`,
            ...(data.hasWallpaperStyle
              ? data.wallpaperStyle
                  .split('\n')
                  .map(line => `    ${line}`)
              : []),
            `}`,
          ]
        : []);

    const bannerPart =
      (data.hasBannerStyle
        ? [
            `#banner img {`,
            ...data.bannerStyle
              .split('\n')
              .map(line => `    ${line}`),
            `}`,
          ]
        : []);

    return [
      ...wallpaperPart,
      ...bannerPart,
    ]
      .filter(Boolean)
      .join('\n');
  },
};