« get me outta code hell

generateGroupSecondaryNavCategoryPart.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/generateGroupSecondaryNavCategoryPart.js
blob: b2adb9f8430742b4be91baecb8ea7ce177c4664e (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
import {atOffset} from '#sugar';

export default {
  contentDependencies: [
    'generateColorStyleAttribute',
    'generateSecondaryNavParentSiblingsPart',
    'linkGroupDynamically',
    'linkListing',
  ],

  extraDependencies: ['html', 'language', 'wikiData'],

  sprawl: ({listingSpec, wikiInfo}) => ({
    groupsByCategoryListing:
      (wikiInfo.enableListings
        ? listingSpec
            .find(l => l.directory === 'groups/by-category')
        : null),
  }),

  query(sprawl, category, group) {
    const groups = category.groups;
    const index = groups.indexOf(group);

    return {
      previousGroup:
        atOffset(groups, index, -1),

      nextGroup:
        atOffset(groups, index, +1),
    };
  },

  relations: (relation, query, sprawl, category, group) => ({
    parentSiblingsPart:
      relation('generateSecondaryNavParentSiblingsPart'),

    categoryLink:
      (sprawl.groupsByCategoryListing
        ? relation('linkListing', sprawl.groupsByCategoryListing)
        : null),

    colorStyle:
      relation('generateColorStyleAttribute', group.category.color),

    previousGroupLink:
      (query.previousGroup
        ? relation('linkGroupDynamically', query.previousGroup)
        : null),

    nextGroupLink:
      (query.nextGroup
        ? relation('linkGroupDynamically', query.nextGroup)
        : null),
  }),

  data: (_query, _sprawl, category, _group) => ({
    name: category.name,
  }),

  generate: (data, relations, {language}) =>
    relations.parentSiblingsPart.slots({
      colorStyle: relations.colorStyle,
      id: true,

      mainLink:
        (relations.categoryLink
          ? relations.categoryLink.slots({
              content: language.sanitize(data.name),
            })
          : null),

      previousLink: relations.previousGroupLink,
      nextLink: relations.nextGroupLink,

      stringsKey: 'groupPage.secondaryNav.category',
      mainLinkOption: 'category',
    }),
};