-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_manifests
executable file
·92 lines (79 loc) · 2.54 KB
/
make_manifests
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
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const yaml = require("yaml");
const { Feed } = require("feed");
const projects = require("./projects.json");
const list = [];
const feed = new Feed({
title: "Field Ready OKH Projects",
description: "Field Ready Open Know-How Projects",
link: "https://field-ready-projects.openknowhow.org",
favicon: "https://field-ready-projects.openknowhow.org/icon.jpg",
feedLinks: {
json: "https://field-ready-projects.openknowhow.org/feed-okh.json",
},
});
for (const project of projects) {
const id = project["Part No."];
const manifest = {
title: `${project["Part No."]} - ${project.Name}`,
description: project.Description,
contributors: [{ name: project.Designer }],
"date-created": new Date().toISOString().split("T")[0],
"manifest-language": "En-US",
"documentation-language": "En-US",
image: project.images[0].fullscreen,
license: {
documentation: project.Licence || null,
hardware: project["Open Hardware Licence"] || null,
},
licensor: "Field Ready",
made: project.Maker != null,
"design-files": project.CAD.map(({ filename, url }) => {
return { path: url, title: filename };
}),
schematics: project["Eng Dwg"].map(({ filename, url }) => {
return { path: url, title: filename };
}),
"documentation-home": `https://field-ready-projects.openknowhow.org/${id.toLowerCase()}`,
};
fs.writeFileSync(
path.join("public", "manifests", `okh-${id}.yml`),
yaml.stringify(manifest)
);
fs.writeFileSync(
path.join("public", "manifests", `okh-${id}.json`),
JSON.stringify(manifest, null, 2)
);
list.push(
`https://field-ready-projects.openknowhow.org/manifests/okh-${id}.yml`
);
const manifestJsonUrl = `https://field-ready-projects.openknowhow.org/manifests/okh-${id}.json`;
feed.addItem({
title: manifest.title,
id: manifestJsonUrl,
link: manifestJsonUrl,
content: manifest.description,
image: manifest.image,
});
}
fs.writeFileSync(
path.join("public", "manifests", `list.yml`),
yaml.stringify(list)
);
// we'd like to use content_text but the feed lib does not support it yet
const feedRemapped = JSON.parse(feed.json1());
feedRemapped.items = feedRemapped.items.map((i) => ({
...i,
content_html: undefined,
content_text: i.content_html,
}));
fs.writeFileSync(
path.join("public", "feed-okh.json"),
JSON.stringify(feedRemapped, null, 2)
);
fs.writeFileSync(
path.join("public", "manifests", `list.json`),
JSON.stringify(list, null, 2)
);