-
Notifications
You must be signed in to change notification settings - Fork 1
/
dato.config.js
110 lines (102 loc) · 3.97 KB
/
dato.config.js
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
105
106
107
108
109
110
const generatePapers = require('./src/lib/generate-papers')
const dataDir = `src/static/data/`
module.exports = (dato, root, i18n) => {
generateAlphabeticalIndex(dato, root, i18n);
generateIndex(dato, root, i18n);
generateTopics(dato, root, i18n);
}
// Extract the Dropbox Paper ID from its URL.
const getPaperID = URL => URL ? URL.substring(URL.lastIndexOf('-') + 1) : null
function generateAlphabeticalIndex(dato, root, i18n) {
root.createDataFile(`${dataDir}alphabetical-index.json`, 'json', {
footer: dato.siteInfo.footer,
headerButton: {
label: dato.siteInfo.alphabeticalPageHeaderButton.label,
url: dato.siteInfo.alphabeticalPageHeaderButton.url
},
headerColor: dato.siteInfo.headerColor.hex,
headerImage: dato.siteInfo.seoImage.url(),
introduction: dato.siteInfo.introduction,
topicColor: dato.siteInfo.topicColor.hex,
topics: dato.topics.sort((a, b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0))
.map(topic => {
return {
name: topic.name,
slug: topic.slug
}
}),
seoImage: dato.siteInfo.seoImage.url(),
title: dato.siteInfo.title
});
}
function generateIndex(dato, root, i18n) {
root.createDataFile(`${dataDir}index.json`, 'json', {
concepts: dato.concepts.map(concept => {
const paperID = getPaperID(concept.paperUrl)
generatePapers(paperID)
return {
paperID,
color: concept.color.hex,
icon: concept.icon.url(),
image: concept.image.url(),
topics: concept.topics.sort((a, b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0))
.map(topic => {
return {
color: dato.siteInfo.topicColor.hex,
name: topic.name,
slug: topic.slug
}
}),
name: concept.name,
slug: concept.slug
}
}),
footer: dato.siteInfo.footer,
headerButton: {
label: dato.siteInfo.indexPageHeaderButton.label,
url: dato.siteInfo.indexPageHeaderButton.url
},
headerColor: dato.siteInfo.headerColor.hex,
headerImage: dato.siteInfo.headerImage.url(),
introduction: dato.siteInfo.introduction,
seoImage: dato.siteInfo.seoImage.url(),
title: dato.siteInfo.title
});
}
function generateTopics(dato, root, i18n) {
dato.topics.forEach(topic => {
const paperID = getPaperID(topic.paperUrl)
generatePapers(paperID)
root.createDataFile(`${dataDir}topics/${topic.slug}.json`, 'json', {
paperID,
concepts: dato.concepts.filter(concept => {
return concept.topics.some(conceptTopic => {
return conceptTopic.id === topic.id
});
}).sort((a, b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0))
.map(relatedConcept => {
return {
color: relatedConcept.color.hex,
icon: relatedConcept.icon.url(),
name: relatedConcept.name,
slug: relatedConcept.slug
}
}),
footer: dato.siteInfo.footer,
headerColor: dato.siteInfo.headerColor.hex,
image: topic.image ? topic.image.url() : '',
name: topic.name,
relatedTopics: topic.relatedTopics.sort((a, b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0))
.map(relatedTopic => {
return {
color: dato.siteInfo.topicColor.hex,
name: relatedTopic.name,
slug: relatedTopic.slug,
}
}),
seoImage: dato.siteInfo.seoImage.url(),
slug: topic.slug,
title: dato.siteInfo.title
});
});
}