-
Notifications
You must be signed in to change notification settings - Fork 1
/
makeIndex.js
71 lines (62 loc) · 1.67 KB
/
makeIndex.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
const datasets = require("./datasets.json");
// dump fiches summary for data/index.json
const getFiche = (type, id) => require(`./data/${type}/${id}.json`);
const getFicheMeta = (fiche, name) =>
fiche &&
fiche.children &&
fiche.children.length &&
fiche.children[0].children.find((c) => c.name === name);
const getFicheMetaText = (fiche, name) => {
const node = getFicheMeta(fiche, name);
return (
(node &&
node.children &&
node.children.length &&
node.children[0] &&
node.children[0].text) ||
null
);
};
const getFicheAriane = (data) => {
const fil = getFicheMeta(data, "FilDAriane");
return (
(fil &&
fil.children &&
fil.children.length &&
fil.children.map((c) => c.children[0].text).join(" > ")) ||
null
);
};
const getFicheBreacrumbs = (data) => {
const fil = getFicheMeta(data, "FilDAriane");
return (
(fil &&
fil.children &&
fil.children.length &&
fil.children.map((c) => ({
id: c.attributes.ID,
text: c.children[0].text,
}))) ||
[]
);
};
const makeIndex = () =>
Object.keys(datasets).flatMap((key) => {
const fiches = require(`./data/${key}/index.json`);
return fiches.map((id) => {
const data = getFiche(key, id);
return {
breadcrumbs: getFicheBreacrumbs(data),
date: getFicheMetaText(data, "dc:date"),
id: data.id,
subject: getFicheMetaText(data, "dc:subject"),
theme: getFicheAriane(data),
title: getFicheMetaText(data, "dc:title"),
type: key,
};
});
});
module.exports = makeIndex;
if (require.main === module) {
console.log(JSON.stringify(makeIndex(), null, 2));
}