forked from protect-earth/protect.earth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.js
74 lines (64 loc) · 2.58 KB
/
convert.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
const fs = require('fs');
const yaml = require('js-yaml');
const slugify = require('slugify');
const srcLinksFolder = './src/data/links/';
const statamicActionsFolder = './api/content/collections/actions/';
const categorySlugIdMap = {
'carbon-reduction': '207559a4-fe66-4c3d-bc6c-4f721f9562a4',
clothing: 'f92ca585-ad4d-43bc-9430-43c2fad14aa1',
cooking: 'e71796f8-4b3d-4f40-a1a8-527fb0fdf854',
'consumer-products': 'a68b7a57-c0a5-4b27-81d2-93a19f2787a1',
documentaries: '49f0ae64-b03a-4d50-bbdc-edd765ef4500',
food: '1e06ea25-373d-440c-9abd-408710b475d0',
finance: 'd8a27ec4-c533-4a8d-a8fe-c217f073c790',
'footprint-calculators': '681bffaf-a44c-4449-ae96-bf780506c862',
'home-improvements': '6ad9cfc5-eac0-455e-9ad0-f537896373ba',
hygiene: '7adab10c-985b-42e2-ab8c-eee35b5a8817',
jobs: '1fcc2840-32ba-44fb-9b99-efe4d1397ff4',
'land-management': '411e32f8-59bc-4fbb-ac7f-3d2a908b039e',
news: '0ec6e5b5-0a80-4c8d-b45f-b78c99492d8d',
politics: '3d78ba9a-4f85-464b-a330-1cfb5c137328',
podcasts: '9db93577-0b4a-4bdb-ad1a-f9a188f463df',
reforestation: '63a7cfb3-7cd5-4282-af9d-e5ed41572d1b',
'renewable-energy': 'f9b2c5ee-8da3-446b-b865-0d716debed30',
transportation: '0a32cb28-6330-4881-8671-824476ed5859',
travel: '97826809-ed97-424c-9c46-cedba824add8',
volunteering: 'ee42a632-ac6a-4f89-802a-8111cf674d4c',
'zero-waste': 'a1a4ac88-627d-4bc7-a5b5-d3dcdc10cc43',
waste: 'a1a4ac88-627d-4bc7-a5b5-d3dcdc10cc43',
};
fs.readdir(srcLinksFolder, (err, files) => {
files.forEach(file => {
const fileDate = file.match(/([0-9]{4}-[0-9]{2}-[0-9]{2})/)[0];
const linkData = yaml.load(
fs.readFileSync(`${srcLinksFolder}/${file}`, 'utf8')
);
const newActionData = {
title: linkData.title,
countries: linkData.countries || [],
featured: linkData.featured === true,
description: linkData.description,
action_url: linkData.url,
categories: linkData.categories
.map(slug => categorySlugIdMap[slug])
.filter(id => id !== null),
twitter: linkData.twitter || null,
instagram: linkData.instagram || null,
image: linkData.instagram || null,
tags: linkData.tags || [],
blueprint: 'action',
};
// url is reserved in statamic 3
const newActionMarkdown = `---\n${yaml.dump(newActionData)}\n---`;
const newFilename = `${fileDate}.${slugify(linkData.title, {
remove: /[*+~.()'"?!:@,]/g,
lower: true,
})}.md`;
console.log(`creating ${newFilename}`);
fs.writeFileSync(
`${statamicActionsFolder}/${newFilename}`,
newActionMarkdown,
'utf8'
);
});
});