Skip to content

Commit

Permalink
feat: add downloadable CV from Work page
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc committed Sep 14, 2023
1 parent e5ba1ab commit 36cb064
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 64 deletions.
9 changes: 9 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ const nextConfig = {
},

staticPageGenerationTimeout: 600,

async rewrites() {
return [
{
source: '/downloads/cv.pdf',
destination: '/api/cv.pdf',
},
];
},
};

module.exports = nextConfig;
2 changes: 1 addition & 1 deletion src/app/(public)/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const AboutFreeTimePage = async () => {
<main className='min-h-main'>
<section className='dark:bg-dark bg-white'>
<div className='layout relative flex flex-col py-12'>
<h1 className='mb-5'>Free Time</h1>
<h1 className='mb-5'>About me</h1>

<div className='mb-5'>
<p>
Expand Down
24 changes: 0 additions & 24 deletions src/app/(public)/cv/cv/page.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions src/app/(public)/cv/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Intro from '@/components/organisms/about-work/Intro';
import Languages from '@/components/organisms/about-work/Languages';
import Publications from '@/components/organisms/about-work/Publications';
import WorkExperience from '@/components/organisms/about-work/WorkExperience';
import CvCard from '@/components/organisms/cv/CvCard';

import { queryJobs } from '@/queries/jobs';
import { queryLanguages } from '@/queries/languages';
Expand Down Expand Up @@ -99,6 +100,10 @@ const AboutPage = async () => {
<hr />

<Publications publications={publications} />

<hr />

<CvCard />
</div>
</section>
</main>
Expand Down
40 changes: 8 additions & 32 deletions src/components/organisms/cv/CvCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import Image from 'next/image';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { FaDownload } from 'react-icons/fa';
Expand All @@ -10,38 +9,15 @@ import Button from '@/components/buttons/Button';
const CvCard = () => {
const { t } = useTranslation();

const width = 1200;

return (
<>
<div className='flex justify-center p-3'>
<a
href='http://bit.ly/pancaldi_cv'
target='_blank'
rel='noopener noreferrer'
>
<Button color='dark'>
<FaDownload className='me-2' />
{t('cv.download')}
</Button>
</a>
</div>

<div className='md:p-4 drop-shadow-xl'>
<Image
src='https://res.cloudinary.com/dwrurydlt/image/upload/v1694635077/Pancaldi_CV_aug23_1_103473c4e7.webp'
alt='CV Page 1'
width={width}
height={0}
/>
<Image
src='https://res.cloudinary.com/dwrurydlt/image/upload/v1694635671/Pancaldi_CV_aug23_77a1e29cab.webp'
alt='CV Page 2'
width={width}
height={0}
/>
</div>
</>
<div className='flex justify-center p-3 mt-6'>
<a href='/downloads/cv.pdf' target='_blank' rel='noopener noreferrer'>
<Button color='dark'>
<FaDownload className='me-2' />
{t('cv.download')}
</Button>
</a>
</div>
);
};

Expand Down
4 changes: 3 additions & 1 deletion src/data/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"icon": "https://res.cloudinary.com/dwrurydlt/image/upload/v1692894192/newspaper_e15ec94d21.svg"
}
},
"aboutFreeTime": {},
"about": {
"title": "Su di me"
},
"projects": {
"readMore": "Read More"
},
Expand Down
15 changes: 9 additions & 6 deletions src/data/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@
"publications": {
"title": "Pubblicazioni",
"icon": "https://res.cloudinary.com/dwrurydlt/image/upload/v1692894192/newspaper_e15ec94d21.svg"
},
"projects": {
"readMore": "Leggi di più"
},
"cv": {
"download": "Scarica PDF"
}
},
"about": {
"title": "About me"
},
"projects": {
"readMore": "Leggi di più"
},
"cv": {
"download": "Scarica PDF"
}
}
32 changes: 32 additions & 0 deletions src/pages/api/cv.pdf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable no-console */
import { NextApiRequest, NextApiResponse } from 'next';
import fetch from 'node-fetch';

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
try {
const cloudinaryUrl =
'https://res.cloudinary.com/dwrurydlt/image/upload/v1694634540/Pancaldi_CV_aug23_258811b6b1.pdf';

const cloudinaryResponse = await fetch(cloudinaryUrl);

if (!cloudinaryResponse.ok) {
console.error(
'Error fetching the PDF from Cloudinary:',
cloudinaryResponse.statusText,
);
res.status(500).end('Internal Server Error');
return;
}

res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', 'inline; filename=cv.pdf');

cloudinaryResponse.body.pipe(res);
} catch (error) {
console.error('Error:', error);
res.status(500).end('Internal Server Error');
}
}

0 comments on commit 36cb064

Please sign in to comment.