import {
bundledLanguages,
type ThemeRegistration
} from 'shikiji'
import {
getHighlighter,
} from 'shikiji'
type CodeExampleType = {
title: string,
language: string,
code: string,
}[]
const getIconCodes = (): CodeExampleType => {
return [
{
language: 'html',
title: 'HTML',
code: ``
},
{
language: 'tsx',
title: 'React',
code: `import { PascalCase } from 'lucide-react';
const App = () => {
return (
);
};
export default App;
`,
},
{
language: 'vue',
title: 'Vue',
code: `
`,
},
{
language: 'svelte',
title: 'Svelte',
code: `
`,
},
{
language: 'tsx',
title: 'Preact',
code: `import { PascalCase } from 'lucide-preact';
const App = () => {
return (
);
};
export default App;
`,
},
{
language: 'tsx',
title: 'Solid',
code: `import { PascalCase } from 'lucide-solid';
const App = () => {
return (
);
};
export default App;
`,
},
{
language: 'tsx',
title: 'Angular',
code: `// app.module.ts
import { LucideAngularModule, PascalCase } from 'lucide-angular';
@NgModule({
imports: [
LucideAngularModule.pick({ PascalCase })
],
})
// app.component.html
`,
},
{
language: 'html',
title: 'Icon Font',
code: `
`,
}
]
}
export type ThemeOptions =
| ThemeRegistration
| { light: ThemeRegistration; dark: ThemeRegistration }
const highLightCode = async (code: string, lang: string, active?: boolean) => {
const highlighter = await getHighlighter({
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);
}