« get me outta code hell

generateWikiHomePage.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/generateWikiHomePage.js
blob: 40a6b1c5e648d63e64a1bd554a65ee670f0cd30d (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
export default {
  contentDependencies: [
    'generatePageLayout',
    'generateWikiHomeAlbumsRow',
    'generateWikiHomeNewsBox',
    'transformContent',
  ],

  extraDependencies: ['wikiData'],

  sprawl({wikiInfo}) {
    return {
      wikiName: wikiInfo.name,

      enableNews: wikiInfo.enableNews,
    };
  },

  relations(relation, sprawl, homepageLayout) {
    const relations = {};

    relations.layout =
      relation('generatePageLayout');

    if (homepageLayout.sidebarContent) {
      relations.customSidebarContent =
        relation('transformContent', homepageLayout.sidebarContent);
    }

    if (sprawl.enableNews) {
      relations.newsSidebarBox =
        relation('generateWikiHomeNewsBox');
    }

    if (homepageLayout.navbarLinks) {
      relations.customNavLinkContents =
        homepageLayout.navbarLinks
          .map(content => relation('transformContent', content));
    }

    relations.contentRows =
      homepageLayout.rows.map(row => {
        switch (row.type) {
          case 'albums':
            return relation('generateWikiHomeAlbumsRow', row);
          default:
            return null;
        }
      });

    return relations;
  },

  data(sprawl) {
    return {
      wikiName: sprawl.wikiName,
    };
  },

  generate(data, relations) {
    return relations.layout.slots({
      title: data.wikiName,
      showWikiNameInTitle: false,

      mainClasses: ['top-index'],
      headingMode: 'static',

      mainContent: [
        relations.contentRows,
      ],

      leftSidebarCollapse: false,
      leftSidebarWide: true,

      leftSidebarMultiple: [
        (relations.customSidebarContent
          ? {
              content:
                relations.customSidebarContent
                  .slot('mode', 'multiline'),
            }
          : null),

        relations.newsSidebarBox ?? null,
      ],

      navLinkStyle: 'index',
      navLinks: [
        {auto: 'home', current: true},

        ...(
          relations.customNavLinkContents
            ?.map(content => ({
              html:
                content.slots({
                  mode: 'single-link',
                  preferShortLinkNames: true,
                }),
            }))
          ?? []),
      ],
    });
  },
};