« 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: 610f4665a8ec3baf1a1a0fb8cd9e827f3132b4d8 (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
// Art tag page specification.

// Imports

import fixWS from 'fix-whitespace';

// Page exports

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

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

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

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

            main: {
                classes: ['top-index'],
                content: fixWS`
                    <h1>${strings('tagPage.title', {tag: tag.name})}</h1>
                    <p class="quick-info">${strings('tagPage.infoLine', {
                        coverArts: strings.count.coverArts(things.length, {unit: true})
                    })}</p>
                    <div class="grid-listing">
                        ${getGridHTML({
                            entries: things.map(item => ({item})),
                            srcFn: thing => (thing.album
                                ? getTrackCover(thing)
                                : getAlbumCover(thing)),
                            hrefFn: thing => (thing.album
                                ? to('localized.track', thing.directory)
                                : to('localized.album', thing.directory))
                        })}
                    </div>
                `
            },

            nav: {
                links: [
                    {toHome: true},
                    wikiInfo.features.listings &&
                    {
                        path: ['localized.listingIndex'],
                        title: strings('listingIndex.title')
                    },
                    {toCurrentPage: true}
                ]
            }
        })
    };

    return [page];
}