forked from OnedocLabs/react-print-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildExample.tsx
56 lines (46 loc) · 1.47 KB
/
buildExample.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { EnrichedExample } from "./types";
import { formatSnippet } from "./utils";
import { renderPreview, baseCss } from "./renderPreview";
import type { CompileOptions } from "../src/compile/compile";
export const buildExample = async (
example: EnrichedExample,
component: string,
outputPath: string,
compileOptions?: CompileOptions
) => {
let markdown = ``;
const snippet = await formatSnippet(example.templateString);
const paths = await renderPreview(
example.template,
component,
outputPath,
true,
compileOptions
);
if (example.description) {
markdown += `${example.description}\n\n`;
}
markdown += `<Frame background="subtle"><img src="${paths.imagePath}" style={{ width: '100%', height: 'auto', maxHeight: '500px', borderRadius: "0.25rem", overflow: "hidden", border: '1px solid #E5E4E2' }} /></Frame>\n\n`;
// Check if the folder docs/previews contain the image
markdown += `<div style={{paddingTop: "1rem", paddingBottom: "1rem"}}><CodeBlocks>
<CodeBlock title="template.tsx">
\`\`\`jsx
import { ${component}${
example.imports ? `, ${example.imports.join(", ")}` : ""
} } from "@fileforge/react-print";${
example.externalImports ? `\n${example.externalImports.join("\n")}` : ""
}
${snippet}
\`\`\`
</CodeBlock>
<CodeBlock title="styles.css">
\`\`\`css
${baseCss}
\`\`\`
</CodeBlock>
</CodeBlocks></div>\n\n`;
// markdown += `<a href="${pdfPath}">Download the PDF example ↓</a>\n\n`;
return {
markdown,
};
};