Skip to content

Commit 4caed1c

Browse files
committed
add more icons
1 parent b6d4439 commit 4caed1c

File tree

11 files changed

+332
-45
lines changed

11 files changed

+332
-45
lines changed

package-lock.json

Lines changed: 226 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"vite": "^5.4.1",
6464
"vite-plugin-dts": "^4.2.2",
6565
"vite-plugin-libcss": "^1.1.1",
66+
"vite-svg-loader": "^5.1.0",
6667
"vitepress": "^1.3.4",
6768
"vue-tsc": "^2.0.29"
6869
},

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<CodeBlock
44
theme="dracula"
55
:code="code"
6-
language="js"
6+
language="python"
77
:numbered="true"
88
file-name="">
99
</CodeBlock>

src/components/code-block/CodeBlock.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<template>
2+
<img
3+
width="240"
4+
:src="icons[props.language]"
5+
alt="" />
26
<!-- Code Block Component -->
37
<div
48
:id="props.id"
@@ -32,6 +36,7 @@
3236
</template>
3337

3438
<script setup lang="ts">
39+
import { icons } from '../icons';
3540
import {
3641
computed,
3742
defineComponent,
@@ -52,6 +57,8 @@
5257
import { addThemeToCodeBlock, themes } from '../themes';
5358
5459
const props = defineProps(codeBlockProps());
60+
const langIcon = ref(`../icons/${props.language}.svg`);
61+
5562
const codeBlock: Ref<HTMLDivElement | null> = ref(null);
5663
5764
const code = computed(() => parseCodeIntoLines(props.code, props.language));

src/components/icons/document.svg

Lines changed: 1 addition & 0 deletions
Loading

src/components/icons/index.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { SupportedLanguageTypes } from 'code-block';
2+
3+
const iconModules = import.meta.glob('./*.svg', { eager: true });
4+
5+
const aliasMap: Record<string, string> = {
6+
DFS: 'svg',
7+
coffeescript: 'coffee',
8+
clike: 'c',
9+
extend: 'markdown',
10+
js: 'javascript',
11+
jsx: 'typescript',
12+
kts: 'kotlin',
13+
kt: 'kotlin',
14+
markup: 'html',
15+
mathml: 'xml',
16+
md: 'markdown',
17+
objc: 'c',
18+
objectivec: 'c',
19+
plain: 'document',
20+
plaintext: 'document',
21+
py: 'python',
22+
ssml: 'xml',
23+
ts: 'typescript',
24+
tsx: 'typescript',
25+
txt: 'document',
26+
text: 'document',
27+
webmanifest: 'json',
28+
xml: 'markup',
29+
yml: 'yaml'
30+
};
31+
32+
export const icons = Object.fromEntries(
33+
Object.entries(iconModules).flatMap(([key, value]) => {
34+
// remove './' prefix and '.svg' suffix
35+
const name = key.slice(2, -4);
36+
37+
const defaultExport = (value as { default: any }).default;
38+
const entries = [[name, defaultExport]];
39+
40+
// Check if the name has an alias
41+
const aliases = Object.entries(aliasMap).filter(
42+
([aliasKey, originalKey]) => originalKey === name
43+
);
44+
45+
aliases.forEach(([aliasKey]) => {
46+
entries.push([aliasKey, defaultExport]);
47+
});
48+
49+
return entries;
50+
})
51+
);

src/components/icons/regex.svg

Lines changed: 2 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy