« get me outta code hell

getContentEntryTotals.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/getContentEntryTotals.js
blob: ce590887fc6717858502bd76cdf400b65d1b4f26 (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
import multilingualWordCount from 'word-count';

import {accumulateSum} from '#sugar';

export default {
  relations: (relation, entries) => ({
    bodies:
      entries
        .map(entry => relation('transformContent', entry.body)),
  }),

  data: (entries) => ({
    entries:
      entries.length,
  }),

  generate: (data, relations, {html}) => ({
    entryCount:
      data.entries,

    wordCount:
      accumulateSum(
        relations.bodies.flatMap(body =>
          multilingualWordCount(
            html.resolve(
              body.slot('mode', 'multiline'),
              {normalize: 'plain'})))),
  }),
};