( example: EnrichedExample, component: string, outputPath: string, compileOptions?: CompileOptions )
| 4 | import type { CompileOptions } from "../src/compile/compile"; |
| 5 | |
| 6 | export const buildExample = async ( |
| 7 | example: EnrichedExample, |
| 8 | component: string, |
| 9 | outputPath: string, |
| 10 | compileOptions?: CompileOptions |
| 11 | ) => { |
| 12 | let markdown = ``; |
| 13 | |
| 14 | const snippet = await formatSnippet(example.templateString); |
| 15 | |
| 16 | const paths = await renderPreview( |
| 17 | example.template, |
| 18 | component, |
| 19 | outputPath, |
| 20 | true, |
| 21 | compileOptions |
| 22 | ); |
| 23 | |
| 24 | if (example.description) { |
| 25 | markdown += `${example.description}\n\n`; |
| 26 | } |
| 27 | |
| 28 | 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`; |
| 29 | |
| 30 | // Check if the folder docs/previews contain the image |
| 31 | |
| 32 | markdown += `<div style={{paddingTop: "1rem", paddingBottom: "1rem"}}><CodeBlocks> |
| 33 | <CodeBlock title="template.tsx"> |
| 34 | \`\`\`jsx |
| 35 | import { ${component}${ |
| 36 | example.imports ? `, ${example.imports.join(", ")}` : "" |
| 37 | } } from "@fileforge/react-print";${ |
| 38 | example.externalImports ? `\n${example.externalImports.join("\n")}` : "" |
| 39 | } |
| 40 | |
| 41 | ${snippet} |
| 42 | \`\`\` |
| 43 | </CodeBlock> |
| 44 | <CodeBlock title="styles.css"> |
| 45 | \`\`\`css |
| 46 | ${baseCss} |
| 47 | \`\`\` |
| 48 | </CodeBlock> |
| 49 | </CodeBlocks></div>\n\n`; |
| 50 | |
| 51 | // markdown += `<a href="${pdfPath}">Download the PDF example ↓</a>\n\n`; |
| 52 | |
| 53 | return { |
| 54 | markdown, |
| 55 | }; |
| 56 | }; |
no test coverage detected