|
| 1 | +import { readFile } from 'node:fs/promises' |
| 2 | +import path from 'node:path' |
| 3 | +import { fileURLToPath } from 'node:url' |
| 4 | +import { profile, recommendationUrl, siteUrl } from '../data/profile' |
| 5 | + |
| 6 | +const rootDirectory = path.resolve( |
| 7 | + path.dirname(fileURLToPath(import.meta.url)), |
| 8 | + '..' |
| 9 | +) |
| 10 | + |
| 11 | +function markdownLink(label, href) { |
| 12 | + return `[${label}](${href})` |
| 13 | +} |
| 14 | + |
| 15 | +function homeMarkdown() { |
| 16 | + return `# ${profile.name} |
| 17 | +
|
| 18 | +> ${profile.title} |
| 19 | +
|
| 20 | +${profile.summary} |
| 21 | +
|
| 22 | +Based in ${profile.location}, I have more than six years of international remote engineering experience. I currently work at OnService.AI on Python services and conversational AI for airline workflows. |
| 23 | +
|
| 24 | +## Selected work |
| 25 | +
|
| 26 | +${profile.projects |
| 27 | + .slice(0, 2) |
| 28 | + .map( |
| 29 | + (project) => |
| 30 | + `### ${project.name}\n\n${project.homepageSummary}\n\n${project.homepageDetail}\n\n${markdownLink(`Visit ${project.name}`, project.href)}` |
| 31 | + ) |
| 32 | + .join('\n\n')} |
| 33 | +
|
| 34 | +## Professional links |
| 35 | +
|
| 36 | +- ${markdownLink('Résumé', `${siteUrl}/resume`)} |
| 37 | +- ${markdownLink('Recommendations', `${siteUrl}/recommendations`)} |
| 38 | +- ${markdownLink('Engineering writing', `${siteUrl}/posts`)} |
| 39 | +- ${markdownLink('GitHub', profile.links.github)} |
| 40 | +- ${markdownLink('LinkedIn', profile.links.linkedin)} |
| 41 | +- ${markdownLink('Email', profile.links.email)} |
| 42 | +` |
| 43 | +} |
| 44 | + |
| 45 | +function resumeMarkdown() { |
| 46 | + const roles = profile.roles |
| 47 | + .map( |
| 48 | + (role) => |
| 49 | + `### ${role.company} — ${role.title}\n\n${role.period}; ${role.location}\n\n${role.summary}` |
| 50 | + ) |
| 51 | + .join('\n\n') |
| 52 | + const skills = Object.entries(profile.skills) |
| 53 | + .map(([group, values]) => `- **${group}:** ${values.join(', ')}`) |
| 54 | + .join('\n') |
| 55 | + |
| 56 | + return `# ${profile.name} Résumé |
| 57 | +
|
| 58 | +> ${profile.title} |
| 59 | +
|
| 60 | +${profile.location} |
| 61 | +
|
| 62 | +## Summary |
| 63 | +
|
| 64 | +${profile.description} |
| 65 | +
|
| 66 | +## Experience |
| 67 | +
|
| 68 | +${roles} |
| 69 | +
|
| 70 | +## Skills |
| 71 | +
|
| 72 | +${skills} |
| 73 | +
|
| 74 | +## Education and achievements |
| 75 | +
|
| 76 | +${profile.education} |
| 77 | +
|
| 78 | +${profile.achievements.map((achievement) => `- ${achievement}`).join('\n')} |
| 79 | +` |
| 80 | +} |
| 81 | + |
| 82 | +function recommendationsMarkdown() { |
| 83 | + const linkedinRecommendations = profile.recommendations |
| 84 | + .map( |
| 85 | + (item) => |
| 86 | + `### ${item.company}\n\n> ${item.excerpt}\n> |
| 87 | +> — ${item.name}, ${item.role}${item.additionalRole ? `; ${item.additionalRole}` : ''}\n\n${markdownLink('View LinkedIn recommendation', recommendationUrl)}` |
| 88 | + ) |
| 89 | + .join('\n\n') |
| 90 | + const employerReferences = profile.employerRecommendations |
| 91 | + .map( |
| 92 | + (item) => |
| 93 | + `### ${item.company}\n\n> ${item.excerpt}\n> |
| 94 | +> — ${item.name}, ${item.role}\n\n${markdownLink(item.linkLabel, `${siteUrl}${item.href}`)}` |
| 95 | + ) |
| 96 | + .join('\n\n') |
| 97 | + const testimonials = profile.clientTestimonials |
| 98 | + .map( |
| 99 | + (item) => |
| 100 | + `### ${item.project}\n\n> ${item.excerpt}\n> |
| 101 | +> — ${item.name} (${item.role.replace('Client feedback · ', '')})` |
| 102 | + ) |
| 103 | + .join('\n\n') |
| 104 | + |
| 105 | + return `# Recommendations for ${profile.name} |
| 106 | +
|
| 107 | +## Verified LinkedIn recommendations |
| 108 | +
|
| 109 | +${linkedinRecommendations} |
| 110 | +
|
| 111 | +## Employer references |
| 112 | +
|
| 113 | +${employerReferences} |
| 114 | +
|
| 115 | +## Clients’ testimonials |
| 116 | +
|
| 117 | +${testimonials} |
| 118 | +
|
| 119 | +## Certifications |
| 120 | +
|
| 121 | +${profile.certifications |
| 122 | + .map( |
| 123 | + (item) => |
| 124 | + `- **${item.name}** — ${item.issuer}, ${item.date}. ${markdownLink(item.linkLabel, `${siteUrl}${item.href}`)}` |
| 125 | + ) |
| 126 | + .join('\n')} |
| 127 | +` |
| 128 | +} |
| 129 | + |
| 130 | +async function postsMarkdown() { |
| 131 | + const { getPosts } = await import('../app/posts/get-posts') |
| 132 | + const posts = await getPosts() |
| 133 | + return `# Engineering Writing | ${profile.name} |
| 134 | +
|
| 135 | +Dated personal writing by ${profile.name} on engineering, remote work, and software careers. |
| 136 | +
|
| 137 | +${posts |
| 138 | + .map( |
| 139 | + (post) => |
| 140 | + `- ${markdownLink(post.frontMatter.title, `${siteUrl}${post.route}`)} — ${post.frontMatter.description}` |
| 141 | + ) |
| 142 | + .join('\n')} |
| 143 | +` |
| 144 | +} |
| 145 | + |
| 146 | +async function articleMarkdown(slug) { |
| 147 | + if (!/^[a-z0-9-]+$/.test(slug)) return null |
| 148 | + |
| 149 | + try { |
| 150 | + const source = await readFile( |
| 151 | + path.join(rootDirectory, 'app', 'posts', slug, 'page.md'), |
| 152 | + 'utf8' |
| 153 | + ) |
| 154 | + const match = source.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/) |
| 155 | + if (!match) return null |
| 156 | + const title = match[1].match(/^title:\s*['"]?(.+?)['"]?$/m)?.[1] |
| 157 | + if (!title) return null |
| 158 | + return `# ${title}\n\n${match[2].trim()}\n` |
| 159 | + } catch { |
| 160 | + return null |
| 161 | + } |
| 162 | +} |
| 163 | + |
| 164 | +export async function markdownForPath(requestPath) { |
| 165 | + const pathname = requestPath.split('?')[0].replace(/\/$/, '') || '/' |
| 166 | + if (pathname === '/') return homeMarkdown() |
| 167 | + if (pathname === '/resume') return resumeMarkdown() |
| 168 | + if (pathname === '/recommendations') return recommendationsMarkdown() |
| 169 | + if (pathname === '/posts') return postsMarkdown() |
| 170 | + if (pathname.startsWith('/posts/')) |
| 171 | + return articleMarkdown(pathname.slice('/posts/'.length)) |
| 172 | + return null |
| 173 | +} |
0 commit comments