« 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: 4253120e31ad3b76d547ea73711204ad84d5aa3f (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
// 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;

    // 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: ({
            generatePreviousNextLinks,
            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,
                            srcFn: thing => (thing.album
                                ? getTrackCover(thing)
                                : getAlbumCover(thing)),
                            hrefFn: thing => (thing.album
                                ? to('localized.track', thing.directory)
                                : to('localized.album', thing.directory))
                        })}
                    </div>
                `
            },

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

    return [page];
}

// Utility functions

function generateTagNav(tag, {
    generatePreviousNextLinks,
    link,
    strings,
    wikiData
}) {
    const previousNextLinks = generatePreviousNextLinks(tag, {
        data: wikiData.tagData.filter(tag => !tag.isCW),
        linkKey: 'tag'
    });

    return {
        links: [
            {toHome: true},
            wikiData.wikiInfo.features.listings &&
            {
                path: ['localized.listingIndex'],
                title: strings('listingIndex.title')
            },
            {
                html: strings('tagPage.nav.tag', {
                    tag: link.tag(tag, {class: 'current'})
                })
            },
            /*
            previousNextLinks && {
                divider: false,
                html: `(${previousNextLinks})`
            }
            */
        ]
    };
}