Skip to content

Commit

Permalink
add nerdfont iconts to the preview (#1411)
Browse files Browse the repository at this point in the history
Co-authored-by: o2sh <[email protected]>
  • Loading branch information
Localghost385 and o2sh authored Sep 8, 2024
1 parent f56faa1 commit f58517c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 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} />
chipColor={language.colors.chip}
chipIcon={escapeToUnicode(language.icon)} />
{/each}
</main>

Expand Down
8 changes: 5 additions & 3 deletions docs/vercel/src/components/AsciiPreview.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script lang="ts">
import { mapToDefaultTerminalFgColor } from '../lib/utils';
import Chip from './Chip.svelte';
import TitleLink from './TitleLink.svelte';
export let name: string;
export let ansi: string[];
export let hex: string[] | null = null;
export let chip: string;
export let chipColor: string;
export let ascii: string = '';
export let chipIcon: string;
let dark = true;
let trueColor = hex != null;
Expand All @@ -32,7 +32,7 @@

<div class="title-row">
<div class="language-name">
<Chip id={name} color={chip} width={24} height={24} />
<h3 class="nerd-font" style="color: {chipColor}">{chipIcon}</h3>
<TitleLink {name} />
</div>
<div class="checkbox">
Expand All @@ -54,6 +54,8 @@
</div>

<style>
@import url('https://www.nerdfonts.com/assets/css/webfont.css');
.logo-container {
display: flex;
justify-content: center;
Expand Down
19 changes: 0 additions & 19 deletions docs/vercel/src/components/Chip.svelte

This file was deleted.

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;
}

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

0 comments on commit f58517c

Please sign in to comment.