2023-06-04 16:59:38 +02:00
|
|
|
import {
|
2023-11-28 21:02:23 +01:00
|
|
|
bundledLanguages,
|
|
|
|
|
type ThemeRegistration
|
|
|
|
|
} from 'shikiji'
|
2023-06-04 16:59:38 +02:00
|
|
|
import {
|
|
|
|
|
getHighlighter,
|
2023-11-28 21:02:23 +01:00
|
|
|
} from 'shikiji'
|
|
|
|
|
|
2023-06-04 16:59:38 +02:00
|
|
|
|
|
|
|
|
type CodeExampleType = {
|
|
|
|
|
title: string,
|
2023-11-28 21:02:23 +01:00
|
|
|
language: string,
|
|
|
|
|
code: string,
|
2023-06-04 16:59:38 +02:00
|
|
|
}[]
|
|
|
|
|
|
|
|
|
|
const getIconCodes = (): CodeExampleType => {
|
|
|
|
|
return [
|
|
|
|
|
{
|
2023-11-28 21:02:23 +01:00
|
|
|
language: 'html',
|
2023-06-04 16:59:38 +02:00
|
|
|
title: 'HTML',
|
2023-11-28 21:02:23 +01:00
|
|
|
code: `<i data-lucide="Name"></i>`
|
2023-06-04 16:59:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
2023-11-28 21:02:23 +01:00
|
|
|
language: 'tsx',
|
2023-06-04 16:59:38 +02:00
|
|
|
title: 'React',
|
2023-11-28 21:02:23 +01:00
|
|
|
code: `import { PascalCase } from 'lucide-react';
|
2023-06-04 16:59:38 +02:00
|
|
|
|
|
|
|
|
const App = () => {
|
|
|
|
|
return (
|
|
|
|
|
<PascalCase />
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default App;
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-11-28 21:02:23 +01:00
|
|
|
language: 'vue',
|
|
|
|
|
title: 'Vue',
|
|
|
|
|
code: `<script setup>
|
2023-06-04 16:59:38 +02:00
|
|
|
import { PascalCase } from 'lucide-vue-next';
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<PascalCase />
|
|
|
|
|
</template>
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-11-28 21:02:23 +01:00
|
|
|
language: 'svelte',
|
2023-06-04 16:59:38 +02:00
|
|
|
title: 'Svelte',
|
2023-11-28 21:02:23 +01:00
|
|
|
code: `<script>
|
2023-06-04 16:59:38 +02:00
|
|
|
import { PascalCase } from 'lucide-svelte';
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<PascalCase />
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-11-28 21:02:23 +01:00
|
|
|
language: 'tsx',
|
2023-06-04 16:59:38 +02:00
|
|
|
title: 'Preact',
|
2023-11-28 21:02:23 +01:00
|
|
|
code: `import { PascalCase } from 'lucide-preact';
|
2023-06-04 16:59:38 +02:00
|
|
|
|
|
|
|
|
const App = () => {
|
|
|
|
|
return (
|
|
|
|
|
<PascalCase />
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default App;
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-11-28 21:02:23 +01:00
|
|
|
language: 'tsx',
|
2023-06-04 16:59:38 +02:00
|
|
|
title: 'Solid',
|
2023-11-28 21:02:23 +01:00
|
|
|
code: `import { PascalCase } from 'lucide-solid';
|
2023-06-04 16:59:38 +02:00
|
|
|
|
|
|
|
|
const App = () => {
|
|
|
|
|
return (
|
|
|
|
|
<PascalCase />
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default App;
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-11-28 21:02:23 +01:00
|
|
|
language: 'tsx',
|
2023-06-04 16:59:38 +02:00
|
|
|
title: 'Angular',
|
2023-11-28 21:02:23 +01:00
|
|
|
code: `// app.module.ts
|
2023-06-04 16:59:38 +02:00
|
|
|
import { LucideAngularModule, PascalCase } from 'lucide-angular';
|
|
|
|
|
|
|
|
|
|
@NgModule({
|
|
|
|
|
imports: [
|
|
|
|
|
LucideAngularModule.pick({ PascalCase })
|
|
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// app.component.html
|
|
|
|
|
<lucide-icon name="Name"></lucide-icon>
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-11-28 21:02:23 +01:00
|
|
|
language: 'html',
|
2023-06-04 16:59:38 +02:00
|
|
|
title: 'Icon Font',
|
2023-11-28 21:02:23 +01:00
|
|
|
code: `<style>
|
2023-06-04 16:59:38 +02:00
|
|
|
@import ('~lucide-static/font/Lucide.css');
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<div class="icon-Name"></div>
|
|
|
|
|
`,
|
2023-11-28 21:02:23 +01:00
|
|
|
}
|
2023-06-04 16:59:38 +02:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type ThemeOptions =
|
2023-11-28 21:02:23 +01:00
|
|
|
| ThemeRegistration
|
|
|
|
|
| { light: ThemeRegistration; dark: ThemeRegistration }
|
2023-06-04 16:59:38 +02:00
|
|
|
|
|
|
|
|
const highLightCode = async (code: string, lang: string, active?: boolean) => {
|
|
|
|
|
const highlighter = await getHighlighter({
|
2023-11-28 21:02:23 +01:00
|
|
|
themes: ['github-light', 'github-dark'],
|
|
|
|
|
langs: Object.keys(bundledLanguages)
|
2023-06-04 16:59:38 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const highlightedCode = highlighter.codeToHtml(code, {
|
|
|
|
|
lang,
|
2023-11-28 21:02:23 +01:00
|
|
|
themes: {
|
|
|
|
|
light: 'github-light',
|
|
|
|
|
dark: 'github-dark'
|
|
|
|
|
},
|
|
|
|
|
defaultColor: false
|
|
|
|
|
}).replace('shiki-themes', 'shiki-themes vp-code')
|
2023-06-04 16:59:38 +02:00
|
|
|
|
|
|
|
|
return `<div class="language-${lang} ${active ? 'active' : ''}">
|
|
|
|
|
<button title="Copy Code" class="copy"></button>
|
|
|
|
|
<span class="lang">${lang}</span>
|
|
|
|
|
${highlightedCode}
|
|
|
|
|
</div>`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default async function createCodeExamples() {
|
|
|
|
|
const codes = getIconCodes();
|
|
|
|
|
|
2023-11-28 21:02:23 +01:00
|
|
|
const codeExamplePromises = codes.map(async ({ title, language, code }, index) => {
|
2023-06-04 16:59:38 +02:00
|
|
|
const isFirst = index === 0;
|
|
|
|
|
|
2023-11-28 21:02:23 +01:00
|
|
|
const codeString = await highLightCode(code, language, isFirst);
|
2023-06-04 16:59:38 +02:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
title,
|
2023-11-28 21:02:23 +01:00
|
|
|
language: language,
|
|
|
|
|
code: codeString,
|
2023-06-04 16:59:38 +02:00
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return Promise.all(codeExamplePromises);
|
|
|
|
|
}
|