@@ -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' ;
0 commit comments