Skip to content

Commit a58f6ca

Browse files
committed
fix: Ensure resume is generated from profile.yaml
1 parent 4e0e1a4 commit a58f6ca

File tree

3 files changed

+22
-41
lines changed

3 files changed

+22
-41
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ jobs:
2525
- name: Compile latex
2626
run: |
2727
node scripts/1.compile-latex-template.js
28-
env:
29-
DATABASE_URL: ${{ secrets.DATABASE_URL }}
30-
DIRECT_URL: ${{ secrets.DIRECT_URL }}
31-
28+
3229
- name: Cache LaTeX files
3330
uses: actions/cache@v4
3431
with:
@@ -44,7 +41,7 @@ jobs:
4441

4542
- name: Install Docker
4643
uses: docker/setup-buildx-action@v3
47-
44+
4845
- name: Build Docker image
4946
run: docker build -t texlive-extended .
5047
working-directory: ./tex
@@ -107,8 +104,6 @@ jobs:
107104
- name: build
108105
env:
109106
BASE_PATH: '/${{ github.event.repository.name }}'
110-
DATABASE_URL: ${{ secrets.DATABASE_URL }}
111-
DIRECT_URL: ${{ secrets.DIRECT_URL }}
112107
run: |
113108
npm run build
114109

scripts/1.compile-latex-template.js

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,17 @@
11
// compile-latex-template.js
22

33
import fs from 'fs';
4+
import YAML from 'yaml';
45
import { Command } from 'commander';
5-
import { PrismaClient } from '@prisma/client';
66
import { default as nunjucks } from 'nunjucks';
77
import { default as nunjucksDate } from 'nunjucks-date';
88

9-
// Load the Prisma Client
10-
const prisma = new PrismaClient();
9+
const main = (templatePath, outputPath, profilePath) => {
10+
console.log(`Compiling ${templatePath} with ${profilePath}`);
11+
// Read and parse profile from profilePath
12+
const profileString = fs.readFileSync(profilePath, 'utf8');
13+
const profile = YAML.parse(profileString);
1114

12-
// Function to load data from the database
13-
const loadData = async (profileVisibility) => {
14-
console.log('Loading data from the database...');
15-
// Read and parse profile from database
16-
const profile = await prisma.profile.findFirstOrThrow({ where: { visibility: profileVisibility } });
17-
if (!profile) {
18-
throw new Error('Profile not found');
19-
}
20-
const educations = await prisma.education.findMany();
21-
const skills = await prisma.skill.findMany();
22-
const experiences = await prisma.experience.findMany();
23-
const resumes = await prisma.resume.findFirst({ include: { projects: { include: { project: true } } } });
24-
const projects = resumes.projects.map((resume) => resume.project).sort((a, b) => parseInt(b.year) - parseInt(a.year));
25-
return { profile, educations, skills, experiences, projects };
26-
}
27-
28-
29-
// Main function to compile the template
30-
const main = async (templatePath, outputPath, profileVisibility) => {
31-
console.log(`Compiling ${templatePath}`);
32-
const data = await loadData(profileVisibility);
3315
// Configure Nunjucks with Custom Tags for LaTeX
3416
const env = nunjucks.configure({
3517
autoescape: false,
@@ -48,7 +30,7 @@ const main = async (templatePath, outputPath, profileVisibility) => {
4830
nunjucksDate.install(env);
4931

5032
// Compile the Template based on profile.yaml
51-
const result = env.render(templatePath, data);
33+
const result = env.render(templatePath, profile);
5234

5335
// Write the result to a file
5436
fs.writeFileSync(outputPath, result);
@@ -62,7 +44,7 @@ program
6244
.description('Compile and export LATEX template using nunjucks')
6345
.option('-t, --template <path>', 'Path to template.tex', './tex/template.tex')
6446
.option('-o, --output <path>', 'Path to output.tex', './tex/WongZhaoWu-resume.tex')
65-
.option('-p, --profile <visibility>', 'Profile visibility. Only `PUBLIC` or `PRIVATE` are accepted', 'PUBLIC')
47+
.option('-p, --profile <path>', 'Path to profile.yaml', './src/lib/profile.yaml')
6648
.action((options) => {
6749
return main(options.template, options.output, options.profile);
6850
});

tex/template.tex

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
% Set applicant's personal data for header
3030
\name{\underline{<$ profile.lastName $>} <$ profile.firstName $>, <$ profile.nickName $>}
3131
\address{}
32-
\webpage{<$ profile.website $>}
33-
\call{<$ profile.mobile $>}
34-
\email{<$ profile.email $>}
35-
\github{<$ profile.github $>}
36-
\linkedin{<$ profile.linkedin $>}
32+
\webpage{<$ contact.website $>}
33+
\call{(+65) XXXX XXXX}
34+
\email{<$ contact.email $>}
35+
\github{<$ contact.github $>}
36+
\linkedin{<$ contact.linkedin $>}
3737

3838
\begin{document}
3939

@@ -43,7 +43,7 @@
4343
% Print the content
4444

4545
\begin{cvsection}{Education}
46-
<% for edu in educations %>
46+
<% for edu in education %>
4747
\begin{cvsubsection}{<$ edu.school $>}{}{<$ edu.startDate | date $> -- <$ edu.endDate | date $>}
4848
\begin{itemize}
4949
<% for d in edu.descriptions %>
@@ -55,7 +55,7 @@
5555
\end{cvsection}
5656

5757
\begin{cvsection}{Employment}
58-
<% for exp in experiences %>
58+
<% for exp in experience %>
5959
<% if exp.isJob %>
6060
\begin{cvsubsection}{<$ exp.title $>}{<$ exp.org $>}{<$ exp.startDate | date $> - <$ exp.endDate | date $>}
6161
\begin{itemize}
@@ -69,14 +69,18 @@
6969
\end{cvsection}
7070

7171
\begin{cvsection}{Projects}
72-
<% for project in projects %>
72+
<% for name, cat in projects %>
73+
<% for project in cat %>
74+
<% if project.title in resume.projects %>
7375
\begin{cvsubsection}{<$ project.title $>}{}{<$ project.year $>}
7476
\begin{itemize}
7577
<% for description in project.longDescriptions %>
7678
\item <$ description $>
7779
<% endfor %>
7880
\end{itemize}
7981
\end{cvsubsection}
82+
<% endif %>
83+
<% endfor %>
8084
<% endfor %>
8185
\end{cvsection}
8286

0 commit comments

Comments
 (0)