« get me outta code hell

generateAbsoluteDatetimestamp.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/generateAbsoluteDatetimestamp.js
blob: 930b6f132273e992e70d643da6631169f3dda07e (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
export default {
  contentDependencies: [
    'generateDatetimestampTemplate',
    'generateTooltip',
  ],

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

  data: (date) =>
    ({date}),

  relations: (relation) => ({
    template:
      relation('generateDatetimestampTemplate'),

    tooltip:
      relation('generateTooltip'),
  }),

  slots: {
    style: {
      validate: v => v.is('full', 'year'),
      default: 'full',
    },

    // Only has an effect for 'year' style.
    tooltip: {
      type: 'boolean',
      default: false,
    },
  },

  generate: (data, relations, slots, {language}) =>
    relations.template.slots({
      mainContent:
        (slots.style === 'full'
          ? language.formatDate(data.date)
       : slots.style === 'year'
          ? data.date.getFullYear().toString()
          : null),

      tooltip:
        slots.tooltip &&
        slots.style === 'year' &&
          relations.tooltip.slots({
            content:
              language.formatDate(data.date),
          }),

      datetime:
        data.date.toISOString(),
    }),
};