import { bundledLanguages, type ThemeRegistration } from 'shiki'; import { createHighlighter } from 'shiki'; type CodeExampleType = { title: string; language: string; code: string; }[]; const getIconCodes = (): CodeExampleType => { return [ { language: 'html', title: 'Vanilla', code: `\ \ `, }, { language: 'tsx', title: 'React', code: `import { Icon } from 'lucide-react'; import { $CamelCase } from '@lucide/lab'; const App = () => { return ( ); }; export default App; `, }, { language: 'vue', title: 'Vue', code: ` `, }, { language: 'svelte', title: 'Svelte', code: ` `, }, { language: 'tsx', title: 'Preact', code: `import { Icon } from 'lucide-preact'; import { $CamelCase } from '@lucide/lab'; const App = () => { return ( ); }; export default App; `, }, { language: 'tsx', title: 'Solid', code: `import { Icon } from 'lucide-solid'; import { $CamelCase } from '@lucide/lab'; const App = () => { return ( ); }; export default App; `, }, { language: 'tsx', title: 'Angular', code: `// app.module.ts import { LucideAngularModule } from 'lucide-angular'; import { $CamelCase } from '@lucide/lab'; @NgModule({ imports: [ LucideAngularModule.pick({ $CamelCase }) ], }) // app.component.html `, }, ]; }; export type ThemeOptions = | ThemeRegistration | { light: ThemeRegistration; dark: ThemeRegistration }; const highLightCode = async (code: string, lang: string, active?: boolean) => { const highlighter = await createHighlighter({ themes: ['github-light', 'github-dark'], langs: Object.keys(bundledLanguages), }); const highlightedCode = highlighter .codeToHtml(code, { lang, themes: { light: 'github-light', dark: 'github-dark', }, defaultColor: false, }) .replace('shiki-themes', 'shiki-themes vp-code'); return `
${lang} ${highlightedCode}
`; }; export default async function createCodeExamples() { const codes = getIconCodes(); const codeExamplePromises = codes.map(async ({ title, language, code }, index) => { const isFirst = index === 0; const codeString = await highLightCode(code, language, isFirst); return { title, language: language, code: codeString, }; }); return Promise.all(codeExamplePromises); }