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
|
import {stitchArrays} from '#sugar';
export default {
contentDependencies: [
'generateAdditionalFilesList',
'generateAdditionalFilesListChunk',
'generateAdditionalFilesListChunkItem',
'linkAlbumAdditionalFile',
'transformContent',
],
extraDependencies: ['getSizeOfAdditionalFile', 'html', 'urls'],
relations: (relation, album, additionalFiles) => ({
list:
relation('generateAdditionalFilesList', additionalFiles),
chunks:
additionalFiles
.map(() => relation('generateAdditionalFilesListChunk')),
chunkDescriptions:
additionalFiles
.map(({description}) =>
(description
? relation('transformContent', description)
: null)),
chunkItems:
additionalFiles
.map(({files}) =>
(files ?? [])
.map(() => relation('generateAdditionalFilesListChunkItem'))),
chunkItemFileLinks:
additionalFiles
.map(({files}) =>
(files ?? [])
.map(file => relation('linkAlbumAdditionalFile', album, file))),
}),
data: (album, additionalFiles) => ({
albumDirectory: album.directory,
chunkTitles:
additionalFiles
.map(({title}) => title),
chunkItemLocations:
additionalFiles
.map(({files}) => files ?? []),
}),
slots: {
showFileSizes: {type: 'boolean', default: true},
},
generate: (data, relations, slots, {getSizeOfAdditionalFile, urls}) =>
relations.list.slots({
chunks:
stitchArrays({
chunk: relations.chunks,
description: relations.chunkDescriptions,
title: data.chunkTitles,
}).map(({chunk, title, description}) =>
chunk.slots({
title,
description:
(description
? description.slot('mode', 'inline')
: null),
})),
chunkItems:
stitchArrays({
items: relations.chunkItems,
fileLinks: relations.chunkItemFileLinks,
locations: data.chunkItemLocations,
}).map(({items, fileLinks, locations}) =>
stitchArrays({
item: items,
fileLink: fileLinks,
location: locations,
}).map(({item, fileLink, location}) =>
item.slots({
fileLink: fileLink,
fileSize:
(slots.showFileSizes
? getSizeOfAdditionalFile(
urls
.from('media.root')
.to('media.albumAdditionalFile', data.albumDirectory, location))
: 0),
}))),
}),
};
|