forked from mudassir0909/jsonresume-theme-elegant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
182 lines (140 loc) · 5.65 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
var fs = require('fs');
var jade = require('jade');
var _ = require('underscore');
var utils = require('jsonresume-themeutils');
var moment = require('moment');
var markdown = require('markdown-it')({
breaks: true
}).use(require('markdown-it-abbr'));
require('./moment-precise-range.js');
utils.setConfig({
date_format: 'MMM, YYYY'
});
function interpolate(object, keyPath) {
var keys = keyPath.split('.');
return _(keys).reduce(function(res, key) {
return (res || {})[key];
}, object);
}
function capitalize(str) {
if (str) {
str = str.toString();
return str[0].toUpperCase() + str.slice(1).toLowerCase();
}
return str;
}
function convertMarkdown(str) {
if (str != null) {
return markdown.render(str);
}
}
function getFloatingNavItems(resume) {
var floating_nav_items = [
{label: 'About', target: 'about', icon: 'board', requires: 'basics.summary'},
{label: 'Work Experience', target: 'work-experience', icon: 'office', requires: 'work'},
{label: 'Skills', target: 'skills', icon: 'tools', requires: 'skills'},
{label: 'Education', target: 'education', icon: 'graduation-cap', requires: 'education'},
{label: 'Awards', target: 'awards', icon: 'trophy', requires: 'awards'},
{label: 'Volunteer Work', target: 'volunteer-work', icon: 'child', requires: 'volunteer'},
{label: 'Publications', target: 'publications', icon: 'newspaper', requires: 'publications'},
{label: 'Interests', target: 'interests', icon: 'heart', requires: 'interests'},
{label: 'References', target: 'references', icon: 'thumbs-up', requires: 'references'}
];
return _(floating_nav_items).filter(function(item) {
var value = interpolate(resume, item.requires);
return !_.isEmpty(value);
});
}
function render(resume) {
var addressValues;
var addressAttrs = ['address', 'city', 'region', 'countryCode', 'postalCode'];
var css = fs.readFileSync(__dirname + '/assets/css/theme.css', 'utf-8');
resume.basics.picture = utils.getUrlForPicture(resume);
addressValues = _(addressAttrs).map(function(key) {
return resume.basics.location[key];
});
resume.basics.summary = convertMarkdown(resume.basics.summary);
resume.basics.computed_location = _.compact(addressValues).join(', ');
if (resume.languages) {
resume.basics.languages = _.pluck(resume.languages, 'language').join(', ');
}
_(resume.basics.profiles).each(function(profile) {
var label = profile.network.toLowerCase();
profile.url = utils.getUrlForProfile(resume, label);
profile.label = label;
});
resume.basics.top_five_profiles = resume.basics.profiles.slice(0, 5);
resume.basics.remaining_profiles = resume.basics.profiles.slice(5);
_.each(resume.work, function(work_info) {
var end_date;
var start_date = moment(work_info.startDate, "YYYY-MM-DD");
var did_leave_company = !!work_info.endDate;
work_info.summary = convertMarkdown(work_info.summary);
if (work_info.endDate) {
end_date = moment(work_info.endDate, "YYYY-MM-DD");
work_info.endDate = utils.getFormattedDate(end_date);
}
if (start_date) {
end_date = end_date ? moment(end_date) : moment();
work_info.startDate = utils.getFormattedDate(start_date);
work_info.duration = moment.preciseDiff(start_date, end_date);
}
work_info.highlights = _(work_info.highlights).map(function(highlight) {
return convertMarkdown(highlight);
});
});
_.each(resume.skills, function(skill_info) {
var levels = ['Beginner', 'Intermediate', 'Advanced', 'Master'];
if (skill_info.level) {
skill_info.skill_class = skill_info.level.toLowerCase();
skill_info.level = capitalize(skill_info.level.trim());
skill_info.display_progress_bar = _.contains(levels, skill_info.level);
}
});
_.each(resume.education, function(education_info) {
_.each(['startDate', 'endDate'], function(type) {
var date = education_info[type];
if (date) {
education_info[type] = utils.getFormattedDate(date);
}
});
});
_.each(resume.awards, function(award) {
var date = award.date;
award.summary = convertMarkdown(award.summary);
if (date) {
award.date = utils.getFormattedDate(date, 'MMM DD, YYYY');
}
});
_.each(resume.volunteer, function(volunteer_info) {
volunteer_info.summary = convertMarkdown(volunteer_info.summary);
_.each(['startDate', 'endDate'], function (type) {
var date = volunteer_info[type];
if (date) {
volunteer_info[type] = utils.getFormattedDate(date);
}
});
volunteer_info.highlights = _(volunteer_info.highlights).map(function(highlight) {
return convertMarkdown(highlight);
});
});
_.each(resume.publications, function(publication_info) {
var date = publication_info.releaseDate;
publication_info.summary = convertMarkdown(publication_info.summary);
if (date) {
publication_info.releaseDate = utils.getFormattedDate(date, 'MMM DD, YYYY');
}
});
_.each(resume.references, function(reference_info) {
reference_info.reference = convertMarkdown(reference_info.reference);
});
return jade.renderFile(__dirname + '/index.jade', {
resume: resume,
floating_nav_items: getFloatingNavItems(resume),
css: css,
_: _
});
}
module.exports = {
render: render
};