Skip to content

Commit df510d0

Browse files
authored
feat: add the base form enabling the download of pdf files (#406)
1 parent 051bf9c commit df510d0

File tree

9 files changed

+156
-59
lines changed

9 files changed

+156
-59
lines changed

_data/downloadFiles/PT_BR/agile.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<head>
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>Guia Ágil - TechGuide</title>
7+
<title>Template - TechGuide</title>
88
<style>
99
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
1010

@@ -50,7 +50,6 @@
5050
color: #0066cc;
5151
margin: 30px 0 20px 0;
5252
padding-bottom: 10px;
53-
border-bottom: 2px solid #e0e0e0;
5453
}
5554

5655
h2 {
@@ -205,8 +204,8 @@
205204

206205
<body>
207206
<div class="header">
208-
<h1>Guia Ágil</h1>
209-
<div class="subtitle">TechGuide - Alura</div>
207+
<h1>Guia Agile</h1>
208+
<div class="subtitle">TechGuide - Alura, FIAP e PM3</div>
210209
</div>
211210

212211
<div class="content">
@@ -412,4 +411,4 @@ <h2>Habilidade Auxiliar: Product management</h2>
412411
</div>
413412
</body>
414413

415-
</html>
414+
</html>
13.9 KB
Binary file not shown.

_scripts/modules/shareable_guides_pdf/index.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ function shouldRegeneratePDF(markdownPath: string, pdfPath: string): boolean {
5454
async function generatePDFForFile(
5555
markdownPath: string,
5656
browser: Browser,
57-
template: string
57+
template: string,
58+
forceRegenerate: string[] = []
5859
): Promise<void> {
5960
const fileName = path.basename(markdownPath, ".md");
6061
const dirPath = path.dirname(markdownPath);
@@ -63,7 +64,8 @@ async function generatePDFForFile(
6364
log(`Processing: ${fileName}.md`);
6465

6566
// Check if regeneration is needed
66-
if (!shouldRegeneratePDF(markdownPath, pdfPath)) {
67+
const shouldForce = forceRegenerate.includes(fileName);
68+
if (!shouldForce && !shouldRegeneratePDF(markdownPath, pdfPath)) {
6769
log(`✓ Skipped (no changes): ${fileName}.pdf`);
6870
return;
6971
}
@@ -77,9 +79,11 @@ async function generatePDFForFile(
7779

7880
// Process HTML with custom transformations
7981
const styledHtmlContent = processHtml(htmlContent);
82+
const guideName = markdownContent.split("\n")[0].replace("# ", "");
8083

8184
// Create the complete HTML document with fixed date for determinism
8285
const completeHtml = template
86+
.replace("{{guideName}}", guideName)
8387
.replace("{{content}}", styledHtmlContent)
8488
.replace("{{date}}", "2024-01-01"); // Fixed date for deterministic output
8589

@@ -127,6 +131,7 @@ async function generatePDFForFile(
127131
}
128132

129133
const main = async () => {
134+
const forceRegenerate = ["agile"];
130135
try {
131136
log("Starting PDF generation for all markdown files...");
132137

@@ -189,8 +194,16 @@ const main = async () => {
189194
const markdownPath = path.join(languagePath, markdownFile);
190195
const pdfPath = markdownPath.replace(".md", ".pdf");
191196

192-
if (shouldRegeneratePDF(markdownPath, pdfPath)) {
193-
await generatePDFForFile(markdownPath, browser, template);
197+
const fileName = path.basename(markdownFile, ".md");
198+
const shouldForce = forceRegenerate.includes(fileName);
199+
200+
if (shouldForce || shouldRegeneratePDF(markdownPath, pdfPath)) {
201+
await generatePDFForFile(
202+
markdownPath,
203+
browser,
204+
template,
205+
forceRegenerate
206+
);
194207
totalProcessed++;
195208
} else {
196209
totalSkipped++;

_scripts/modules/shareable_guides_pdf/parseMarkdownToHTML.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ export function parseMarkdownToHTML({
2222

2323
function trimLines(str: string) {
2424
return str?.replace(/^ +/gm, "");
25-
}
25+
}

_scripts/modules/shareable_guides_pdf/template.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<head>
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>Guia Ágil - TechGuide</title>
7+
<title>Template - TechGuide</title>
88
<style>
99
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
1010

@@ -50,7 +50,6 @@
5050
color: #0066cc;
5151
margin: 30px 0 20px 0;
5252
padding-bottom: 10px;
53-
border-bottom: 2px solid #e0e0e0;
5453
}
5554

5655
h2 {
@@ -205,8 +204,8 @@
205204

206205
<body>
207206
<div class="header">
208-
<h1>Guia Ágil</h1>
209-
<div class="subtitle">TechGuide - Alura</div>
207+
<h1>Guia {{guideName}}</h1>
208+
<div class="subtitle">TechGuide - Alura, FIAP e PM3</div>
210209
</div>
211210

212211
<div class="content">
@@ -220,4 +219,4 @@ <h1>Guia Ágil</h1>
220219
</div>
221220
</body>
222221

223-
</html>
222+
</html>

src/components/HubspotForm/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export function HubspotForm({
5555
/* Container styles */
5656
.hubspot-form {
5757
min-height: 200px;
58+
min-width: 200px;
59+
display: flex;
60+
justify-content: center;
61+
align-items: center;
5862
padding: 20px;
5963
border-radius: 12px;
6064
background: linear-gradient(
@@ -124,7 +128,7 @@ export function HubspotForm({
124128
margin-top: 23px;
125129
background: #0052ff;
126130
color: white !important;
127-
border: none !important;
131+
border: 1px solid #0052ff !important;
128132
padding: 14px 28px !important;
129133
border-radius: 8px !important;
130134
font-size: 16px !important;
@@ -140,7 +144,9 @@ export function HubspotForm({
140144
}
141145
142146
.hubspot-form .hs-button:hover {
143-
background-color: red;
147+
background-color: transparent;
148+
color: #0052ff;
149+
border: 1px solid #0052ff;
144150
}
145151
146152
.hubspot-form .hs-button:active {

src/screens/PathScreen/index.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import ScreenHeroContainer from "@src/patterns/ScreenHeroContainer";
33
import { pageHOC } from "@src/wrappers/pageHOC";
44
import TShape from "./patterns/TShape";
55
import { PathScreenGetGuideBySlugQuery } from "@src/gql_types";
6-
// import { HubspotForm } from "@src/components/HubspotForm";
76

87
interface PathScreenProps {
98
external?: string;
@@ -12,18 +11,6 @@ interface PathScreenProps {
1211
function PathScreen({ external, guide }: PathScreenProps) {
1312
return (
1413
<ScreenHeroContainer guide={guide}>
15-
{/* {guide.pdfFormId && (
16-
<HubspotForm
17-
formId={guide.pdfFormId}
18-
onFormSubmitted={() => {
19-
// eslint-disable-next-line no-console
20-
console.log("form submitted");
21-
// - slug
22-
// - locale
23-
// https://raw.githubusercontent.com/alura/techguide/refs/heads/main/_data/downloadFiles/PT_BR/agile.pdf
24-
}}
25-
/>
26-
)} */}
2714
<TShape guide={guide} externalGuideCreator={external} />
2815
</ScreenHeroContainer>
2916
);

src/screens/PathScreen/patterns/TShape/index.tsx

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TItemCard } from "./patterns/TItemCard";
55
import { useI18n, useI18nLocale } from "@src/infra/i18n";
66
import { parseContent } from "@src/infra/i18n/parseContent";
77
import { OptionalIcon } from "@src/theme/icons/OptionalIcon";
8+
import { LeadForm } from "./patterns/LeadForm";
89

910
interface TShapeProps {
1011
guide: PathScreenGetGuideBySlugQuery["guide"];
@@ -255,35 +256,40 @@ export default function TShape({ guide, externalGuideCreator }: TShapeProps) {
255256
{i18n.content("TSHAPE.OPTIONAL.DESCRIPTION")}
256257
</Text>
257258
{!isExternalGuide && (
258-
<Link
259-
href={`https://github.com/alura/techguide/blob/main/_data/downloadFiles/${locale}/${guide.slug}.md`}
260-
styleSheet={{
261-
marginTop: "23px",
262-
width: "100%",
263-
maxWidth: "400px",
264-
display: "flex",
265-
gap: "6px",
266-
alignItems: "center",
267-
justifyContent: "center",
268-
flexDirection: "row",
269-
borderRadius: "8px",
270-
border: "1px solid #0052FF",
271-
textDecoration: "none",
272-
padding: "14px",
273-
fontSize: "14px",
274-
backgroundColor: "#0052FF",
275-
hover: {
276-
opacity: 1,
277-
backgroundColor: "transparent",
278-
},
279-
focus: {
280-
opacity: 1,
281-
backgroundColor: "transparent",
282-
},
283-
}}
284-
>
285-
{i18n.content("TSHAPE.BUTTON.DOWNLOAD_T_FILE")}
286-
</Link>
259+
<>
260+
{guide.pdfFormId && <LeadForm guide={guide} />}
261+
{!guide.pdfFormId && (
262+
<Link
263+
href={`https://github.com/alura/techguide/blob/main/_data/downloadFiles/${locale}/${guide.slug}.md`}
264+
styleSheet={{
265+
marginTop: "23px",
266+
width: "100%",
267+
maxWidth: "400px",
268+
display: "flex",
269+
gap: "6px",
270+
alignItems: "center",
271+
justifyContent: "center",
272+
flexDirection: "row",
273+
borderRadius: "8px",
274+
border: "1px solid #0052FF",
275+
textDecoration: "none",
276+
padding: "14px",
277+
fontSize: "14px",
278+
backgroundColor: "#0052FF",
279+
hover: {
280+
opacity: 1,
281+
backgroundColor: "transparent",
282+
},
283+
focus: {
284+
opacity: 1,
285+
backgroundColor: "transparent",
286+
},
287+
}}
288+
>
289+
{i18n.content("TSHAPE.BUTTON.DOWNLOAD_T_FILE")}
290+
</Link>
291+
)}
292+
</>
287293
)}
288294
<Link
289295
href="/"
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import React from "react";
2+
import Box from "@src/components/Box";
3+
import { useModal } from "@src/components/Modal";
4+
import { useI18n } from "@src/infra/i18n";
5+
import { HubspotForm } from "@src/components/HubspotForm";
6+
import { PathScreenGetGuideBySlugQuery } from "@src/gql_types";
7+
8+
export function LeadForm({
9+
guide,
10+
}: {
11+
guide: PathScreenGetGuideBySlugQuery["guide"];
12+
}) {
13+
const modal = useModal();
14+
const i18n = useI18n();
15+
return (
16+
<>
17+
<Box
18+
tag="button"
19+
onClick={() => {
20+
modal.open(
21+
<Box
22+
styleSheet={{
23+
width: "100%",
24+
maxWidth: "600px",
25+
margin: "0 auto",
26+
gap: "16px",
27+
padding: "16px",
28+
justifySelf: "center",
29+
flex: 1,
30+
display: "flex",
31+
flexDirection: "column",
32+
alignItems: "center",
33+
justifyContent: "center",
34+
}}
35+
onClick={(e) => {
36+
if (e.target.closest(".hubspot-form")) {
37+
return;
38+
}
39+
modal.close();
40+
}}
41+
>
42+
<HubspotForm
43+
formId={guide.pdfFormId}
44+
onFormSubmitted={() => {
45+
// eslint-disable-next-line no-console
46+
console.log("form submitted");
47+
const slug = guide.slug;
48+
const locale = "PT_BR";
49+
const pdfUrl = `https://raw.githubusercontent.com/alura/techguide/refs/heads/main/_data/downloadFiles/${locale}/${slug}.pdf`;
50+
window.open(pdfUrl, "_blank");
51+
modal.close();
52+
}}
53+
/>
54+
</Box>
55+
);
56+
}}
57+
styleSheet={{
58+
color: "#FFFFFF",
59+
marginTop: "23px",
60+
width: "100%",
61+
maxWidth: "400px",
62+
display: "flex",
63+
gap: "6px",
64+
alignItems: "center",
65+
justifyContent: "center",
66+
flexDirection: "row",
67+
borderRadius: "8px",
68+
border: "1px solid #0052FF",
69+
textDecoration: "none",
70+
padding: "14px",
71+
fontSize: "14px",
72+
backgroundColor: "#0052FF",
73+
hover: {
74+
opacity: 1,
75+
backgroundColor: "transparent",
76+
},
77+
focus: {
78+
opacity: 1,
79+
backgroundColor: "transparent",
80+
},
81+
}}
82+
>
83+
{i18n.content("TSHAPE.BUTTON.DOWNLOAD_T_FILE")}
84+
</Box>
85+
</>
86+
);
87+
}

0 commit comments

Comments
 (0)