« get me outta code hell

tag.js « page « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/page/tag.js
blob: 38f7e21334584e9c3cf22fd5272c6e02fd745003 (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
/** @format */

// Art tag page specification.

// Imports

import fixWS from 'fix-whitespace';

// Page exports

export function condition({wikiData}) {
  return wikiData.wikiInfo.enableArtTagUI;
}

export function targets({wikiData}) {
  return wikiData.artTagData.filter((tag) => !tag.isContentWarning);
}

export function write(tag, {wikiData}) {
  const {taggedInThings: things} = tag;

  // Display things featuring this art tag in reverse chronological order,
  // sticking the most recent additions near the top!
  const thingsReversed = things.slice().reverse();

  const entries = thingsReversed.map((item) => ({item}));

  const page = {
    type: 'page',
    path: ['tag', tag.directory],
    page: ({
      getAlbumCover,
      getGridHTML,
      getThemeString,
      getTrackCover,
      link,
      language,
    }) => ({
      title: language.$('tagPage.title', {tag: tag.name}),
      theme: getThemeString(tag.color),

      main: {
        classes: ['top-index'],
        content: fixWS`
                    <h1>${language.$('tagPage.title', {tag: tag.name})}</h1>
                    <p class="quick-info">${language.$('tagPage.infoLine', {
                      coverArts: language.countCoverArts(things.length, {
                        unit: true,
                      }),
                    })}</p>
                    <div class="grid-listing">
                        ${getGridHTML({
                          entries,
                          srcFn: (thing) =>
                            thing.album
                              ? getTrackCover(thing)
                              : getAlbumCover(thing),
                          linkFn: (thing, opts) =>
                            thing.album
                              ? link.track(thing, opts)
                              : link.album(thing, opts),
                        })}
                    </div>
                `,
      },

      nav: generateTagNav(tag, {
        link,
        language,
        wikiData,
      }),
    }),
  };

  return [page];
}

// Utility functions

function generateTagNav(
  tag,
  {link, language, wikiData}
) {
  return {
    linkContainerClasses: ['nav-links-hierarchy'],
    links: [
      {toHome: true},
      wikiData.wikiInfo.enableListings && {
        path: ['localized.listingIndex'],
        title: language.$('listingIndex.title'),
      },
      {
        html: language.$('tagPage.nav.tag', {
          tag: link.tag(tag, {class: 'current'}),
        }),
      },
    ],
  };
}