Skip to content

Commit 3db9da3

Browse files
committed
chore: add upgrade step while processing resume
1 parent de02411 commit 3db9da3

File tree

4 files changed

+114
-21
lines changed

4 files changed

+114
-21
lines changed

index.js

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,112 @@ Handlebars.registerHelper('link', (body) => {
7575
return `<a href="${body}">${host}</a>`;
7676
});
7777

78+
/**
79+
* Many users still have JSON Resumes written against old versions of the
80+
* schema. We detect this and upgrade them to the latest version behind the
81+
* scenes.
82+
*
83+
* Writes to the object directly.
84+
*
85+
* @param {any} resume
86+
* @returns {boolean}
87+
* If the JSON Resume was modified, so it was using outdated property names.
88+
*
89+
* @see https://github.com/jsonresume/resume-schema/releases/tag/v0.0.17
90+
* @see https://github.com/jsonresume/resume-schema/releases/tag/v0.0.12
91+
*/
92+
function upgradeOutdatedResume(resume) {
93+
let upgraded = false;
94+
95+
if (resume.bio && !resume.basics) {
96+
resume.basics = resume.bio;
97+
upgraded = true;
98+
}
99+
100+
if ((resume.basics?.firstName || resume.basics?.lastName) && !resume.basics.name) {
101+
const names = [];
102+
103+
if (resume.basics.firstName) {
104+
names.push(resume.basics.firstName);
105+
}
106+
107+
if (resume.basics.lastName) {
108+
names.push(resume.basics.lastName);
109+
}
110+
111+
resume.basics.name = names.join(' ');
112+
upgraded = true;
113+
}
114+
115+
if (resume.basics?.picture && !resume.basics.image) {
116+
resume.basics.image = resume.basics.picture;
117+
upgraded = true;
118+
}
119+
120+
if (resume.basics?.website && !resume.basics.url) {
121+
resume.basics.url = resume.basics.website;
122+
upgraded = true;
123+
}
124+
125+
if (resume.basics?.state && !resume.basics?.region) {
126+
resume.basics.region = resume.basics.state;
127+
upgraded = true;
128+
}
129+
130+
if (Array.isArray(resume.work)) {
131+
for (const work of resume.work) {
132+
if (work?.company && !work.name) {
133+
work.name = work.company;
134+
upgraded = true;
135+
}
136+
137+
if (work?.website && !work.url) {
138+
work.url = work.website;
139+
upgraded = true;
140+
}
141+
}
142+
}
143+
144+
if (Array.isArray(resume.volunteer)) {
145+
for (const volunteer of resume.volunteer) {
146+
if (volunteer?.website && !volunteer.url) {
147+
volunteer.url = volunteer.website;
148+
upgraded = true;
149+
}
150+
}
151+
}
152+
153+
if (Array.isArray(resume.publications)) {
154+
for (const publication of resume.publications) {
155+
if (publication?.website && !publication.url) {
156+
publication.url = publication.website;
157+
upgraded = true;
158+
}
159+
}
160+
}
161+
162+
if (resume.hobbies && !resume.interests) {
163+
resume.interests = resume.hobbies;
164+
upgraded = true;
165+
}
166+
167+
if (Array.isArray(resume.languages)) {
168+
for (const language of resume.languages) {
169+
if (language?.name && !language.language) {
170+
language.language = language.name;
171+
upgraded = true;
172+
}
173+
174+
if (language?.level && !language.fluency) {
175+
language.fluency = language.level;
176+
upgraded = true;
177+
}
178+
}
179+
}
180+
181+
return upgraded;
182+
}
183+
78184
/**
79185
* @param {any} resume
80186
* @returns {Promise<string>}
@@ -85,9 +191,12 @@ export async function render(resume) {
85191
fs.readFile(import.meta.dirname + '/resume.handlebars', 'utf-8'),
86192
]);
87193

88-
const { profiles } = resume.basics;
194+
if (upgradeOutdatedResume(resume)) {
195+
console.warn('⚠️ Resume is written against an outdated version of the JSON Resume schema.\n⚠️ This will still work, but you should consider updating your resume.\n⚠️ See: https://jsonresume.org/schema');
196+
}
89197

90-
if (Array.isArray(profiles)) {
198+
if (Array.isArray(resume.basics?.profiles)) {
199+
const { profiles } = resume.basics;
91200
const xTwitter = profiles.find((profile) => {
92201
const name = profile.network.toLowerCase();
93202
return name === 'x' || name === 'twitter';

resume.handlebars

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@
6565

6666
{{{link url}}}
6767
</div>
68-
{{else if website}}
69-
<div class="website">
70-
<strong>Website</strong>
71-
<a href="{{website}}">{{website}}</a>
72-
</div>
7368
{{/if}}
7469
{{#if email}}
7570
<div class="email">
@@ -129,10 +124,6 @@
129124
<h3 class="work_name">
130125
{{name}}
131126
</h3>
132-
{{else if company}}
133-
<h3 class="work_name">
134-
{{company}}
135-
</h3>
136127
{{/if}}
137128

138129
<div class="split">
@@ -152,10 +143,6 @@
152143
<div class="work_website">
153144
{{{link url}}}
154145
</div>
155-
{{else if website}}
156-
<div class="work_website">
157-
<a href="{{website}}">{{website}}</a>
158-
</div>
159146
{{/if}}
160147
</div>
161148

@@ -209,10 +196,6 @@
209196
<div class="work_website">
210197
{{{link url}}}
211198
</div>
212-
{{else if website}}
213-
<div class="work_website">
214-
<a href="{{website}}">{{website}}</a>
215-
</div>
216199
{{/if}}
217200
</div>
218201

test/fixture.resume.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"work": [
2929
{
30-
"name": "JSON Resume",
30+
"company": "JSON Resume",
3131
"location": "Remote",
3232
"position": "Open Sourcerer 🧙‍♂️",
3333
"url": "https://jsonresume.org",

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"checkJs": true,
1111
"strict": true,
1212
"resolveJsonModule": true,
13-
"skipLibCheck": true
13+
"skipLibCheck": true,
14+
"noImplicitAny": false
1415
},
1516
"exclude": [
1617
".yarn/",

0 commit comments

Comments
 (0)