Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nerdfont iconts to the preview #1411

Merged
merged 3 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

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