Skip to content

Commit

Permalink
add nerdfont iconts to the preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Localghost385 committed Sep 7, 2024
1 parent 684b837 commit 2a9e676
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions docs/vercel/src/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
let showMenu: boolean;
const languages: Language[] = Object.entries(data as Languages).map(
([name, { type, ascii, colors }]) => ({
([name, { type, ascii, colors, icon }]) => ({
name,
type,
ascii,
colors,
icon,
})
);
Expand All @@ -30,6 +31,15 @@
return languages.filter(({ type }) => $filter.checkboxes.includes(type));
});
function escapeToUnicode(unicodeEscape: string): string {
if (unicodeEscape) {
let codePoint = parseInt(unicodeEscape.slice(3, -1), 16); // extract the relevent portion of the escape
return String.fromCodePoint(codePoint);
} else {
return '\u{25CF}';
}
}
onMount(async () => {
const response = await fetch(
'https://api.github.com/repos/o2sh/onefetch/releases/latest'
Expand Down Expand Up @@ -102,7 +112,8 @@
ansi={language.colors.ansi}
hex={language.colors.hex}
ascii={language.ascii}
chip={language.colors.chip} />
chip={language.colors.chip}
nerdfont={escapeToUnicode(language.icon)} />
{/each}
</main>

Expand Down
4 changes: 4 additions & 0 deletions docs/vercel/src/components/AsciiPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export let hex: string[] | null = null;
export let chip: string;
export let ascii: string = '';
export let nerdfont: string;
let dark = true;
let trueColor = hex != null;
Expand All @@ -34,6 +35,7 @@
<div class="language-name">
<Chip id={name} color={chip} width={24} height={24} />
<TitleLink {name} />
<h3 class="nerd-font">{nerdfont}</h3>
</div>
<div class="checkbox">
<input id="dark-checkbox-{name}" type="checkbox" bind:checked={dark} />
Expand All @@ -54,6 +56,8 @@
</div>

<style>
@import url('https://www.nerdfonts.com/assets/css/webfont.css');
.logo-container {
display: flex;
justify-content: center;
Expand Down
1 change: 1 addition & 0 deletions docs/vercel/src/yaml.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare module '*/languages.yaml' {
type: string;
ascii: string;
colors: LanguageColors;
icon: string | null;
}

export type Languages = Record<string, Language>;
Expand Down

0 comments on commit 2a9e676

Please sign in to comment.