« get me outta code hell

homepage.js « page « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/page/homepage.js
blob: 8b470e9beda1ccf281457b53ca2ad9d31281f3b0 (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
121
122
// Homepage specification.

// Imports

import fixWS from 'fix-whitespace';

import * as html from '../util/html.js';

import {
    getNewAdditions,
    getNewReleases
} from '../util/wiki-data.js';

// Page exports

export function writeTargetless({wikiData}) {
    const { newsData, staticPageData, homepageLayout, wikiInfo } = wikiData;

    const page = {
        type: 'page',
        path: ['home'],
        page: ({
            getAlbumGridHTML,
            getLinkThemeString,
            link,
            strings,
            to,
            transformInline,
            transformMultiline
        }) => ({
            title: wikiInfo.name,

            meta: {
                description: wikiInfo.description
            },

            main: {
                classes: ['top-index'],
                content: fixWS`
                    <h1>${wikiInfo.name}</h1>
                    ${homepageLayout.rows?.map((row, i) => fixWS`
                        <section class="row" style="${getLinkThemeString(row.color)}">
                            <h2>${row.name}</h2>
                            ${row.type === 'albums' && fixWS`
                                <div class="grid-listing">
                                    ${getAlbumGridHTML({
                                        entries: (
                                            row.sourceGroupByRef === 'new-releases' ? getNewReleases(row.countAlbumsFromGroup, {wikiData}) :
                                            row.sourceGroupByRef === 'new-additions' ? getNewAdditions(row.countAlbumsFromGroup, {wikiData}) :
                                            ((row.sourceGroup?.albums ?? [])
                                                .slice()
                                                .reverse()
                                                .filter(album => album.isListedOnHomepage)
                                                .slice(0, row.countAlbumsFromGroup)
                                                .map(album => ({item: album})))
                                        ).concat(row.sourceAlbums.map(album => ({item: album}))),
                                        lazy: i > 0
                                    })}
                                    ${row.actionLinks?.length && fixWS`
                                        <div class="grid-actions">
                                            ${row.actionLinks.map(action => transformInline(action)
                                                .replace('<a', '<a class="box grid-item"')).join('\n')}
                                        </div>
                                    `}
                                </div>
                            `}
                        </section>
                    `).join('\n')}
                `
            },

            sidebarLeft: homepageLayout.sidebarContent && {
                wide: true,
                collapse: false,
                // This is a pretty filthy hack! 8ut otherwise, the [[news]] part
                // gets treated like it's a reference to the track named "news",
                // which o8viously isn't what we're going for. Gotta catch that
                // 8efore we pass it to transformMultiline, 'cuz otherwise it'll
                // get repl8ced with just the word "news" (or anything else that
                // transformMultiline does with references it can't match) -- and
                // we can't match that for replacing it with the news column!
                //
                // And no, I will not make [[news]] into part of transformMultiline
                // (even though that would 8e hilarious).
                content: (transformMultiline(homepageLayout.sidebarContent.replace('[[news]]', '__GENERATE_NEWS__'))
                    .replace('<p>__GENERATE_NEWS__</p>', wikiInfo.enableNews ? fixWS`
                        <h1>${strings('homepage.news.title')}</h1>
                        ${newsData.slice(0, 3).map((entry, i) => html.tag('article',
                            {class: ['news-entry', i === 0 && 'first-news-entry']},
                            fixWS`
                                <h2><time>${strings.count.date(entry.date)}</time> ${link.newsEntry(entry)}</h2>
                                ${transformMultiline(entry.contentShort)}
                                ${entry.contentShort !== entry.content && link.newsEntry(entry, {
                                    text: strings('homepage.news.entry.viewRest')
                                })}
                            `)).join('\n')}
                    ` : `<p><i>News requested in content description but this feature isn't enabled</i></p>`))
            },

            nav: {
                content: fixWS`
                    <h2 class="dot-between-spans">
                        ${[
                            link.home('', {text: wikiInfo.nameShort, class: 'current', to}),
                            wikiInfo.enableListings &&
                            link.listingIndex('', {text: strings('listingIndex.title'), to}),
                            wikiInfo.enableNews &&
                            link.newsIndex('', {text: strings('newsIndex.title'), to}),
                            wikiInfo.enableFlashesAndGames &&
                            link.flashIndex('', {text: strings('flashIndex.title'), to}),
                            ...(staticPageData
                                .filter(page => page.showInNavigationBar)
                                .map(page => link.staticPage(page, {text: page.nameShort})))
                        ].filter(Boolean).map(link => `<span>${link}</span>`).join('\n')}
                    </h2>
                `
            }
        })
    };

    return [page];
}