-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
68 lines (56 loc) · 2.34 KB
/
index.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
'use strict';
const fs = require('fs');
const obj = require('./list.json');
let content = '# 2016 Web Development Conferences\nA list of 2016 web development conferences.\nA list of [2017 conferences](https://github.com/ryanburgess/2017-conferences).\n\n';
// create contributing instructions
const contribute = ('## Contributing \n' +
'1. Fork it\n' +
'2. Add your conference to `list.json`\n' +
'3. Run `node index` to update `README.md` with your changes\n' +
'4. Create your feature branch (`git checkout -b my-new-feature`)\n' +
'5. Commit your changes (`git commit -am "Add some feature"`)\n' +
'6. Push to the branch (`git push origin my-new-feature`)\n' +
'7. Create new Pull Request');
content += contribute + '\n';
// create heading for conference list
content += '\n#Conference List\n';
let formatDateYYYYMMDD = (_dateString) => {
let _d = new Date(_dateString);
return new Date(_d - _d.getTimezoneOffset() * 60 * 1000).toJSON().split(/T/)[0].replace(/-/g, '');
};
let getCalendarUrl = (_conf) => {
let _date = (function () {
let _when = _conf.when.replace(/(\d)(st|nd|rd|th)/g, '$1');
let _startDay = _when.match(/\d+/);
let _startDate = formatDateYYYYMMDD(`${_conf.month} ${_startDay}, 2016`);
let _endDay = _when.match(/(\d+)(?:-|–)(\d+)/);
let _endMonth = _when.match(/\d+(?:-|–)([^\d\s]+)/);
let _endDate;
_endMonth = _endMonth ? _endMonth[1] : null;
if (_endDay) {
_endDate = formatDateYYYYMMDD(`${_endMonth || _conf.month} ${_endDay[2]}, 2016`);
} else if (_endMonth) {
_endDay = _when.match(/(\d)+, 2016/)[1];
_endDate = formatDateYYYYMMDD(`${_endMonth || _conf.month} ${_endDay}, 2016`);
}
if (_endDate) {
return `${_startDate}/${_endDate}`;
} else {
return `${_startDate}/${_startDate}`;
}
})();
return `https://www.google.com/calendar/event?action=TEMPLATE&dates=${_date}&text=${_conf.title}&location=${_conf.where}&details=${_conf.url}`;
};
// create list of conferences
for (const conference of obj) {
content += (
`\n## [${conference.title}](${conference.url}) [📆](${getCalendarUrl(conference)}, Google Calendar)
**Where:** ${conference.where}\n
**When:** ${conference.when}\n\n`
);
}
// create README with the list of conferences
fs.writeFile('./README.md', content, function (err) {
if (err) throw err;
console.log('Updated conference list');
});