|
1 | 1 | <script lang="ts">
|
2 | 2 | import AsciiPreview from './lib/AsciiPreview.svelte';
|
3 | 3 | import data from '../../../languages.yaml';
|
4 |
| - import type { Languages } from '../../../languages.yaml'; |
| 4 | + import type { Languages, Language } from '../../../languages.yaml'; |
5 | 5 | import { onMount } from 'svelte';
|
| 6 | + import { writable, derived } from 'svelte/store'; |
6 | 7 |
|
7 |
| - let tag_name: string; |
8 |
| - let html_url: string; |
| 8 | + let tagName: string; |
| 9 | + let htmlUrl: string; |
9 | 10 |
|
10 |
| - const languages = Object.entries(data as Languages).map( |
11 |
| - ([name, { ascii, colors }]) => ({ |
| 11 | + const languages: Language[] = Object.entries(data as Languages).map( |
| 12 | + ([name, { type, ascii, colors }]) => ({ |
12 | 13 | name,
|
| 14 | + type, |
13 | 15 | ascii,
|
14 |
| - ...colors, |
| 16 | + colors, |
15 | 17 | })
|
16 | 18 | );
|
17 | 19 |
|
| 20 | + const languageTypes: string[] = Array.from( |
| 21 | + new Set<string>(Object.values(data as Languages).map(({ type }) => type)) |
| 22 | + ); |
| 23 | +
|
| 24 | + const filter = writable({ |
| 25 | + checkboxes: languageTypes, |
| 26 | + }); |
| 27 | +
|
| 28 | + const filteredLanguages = derived(filter, ($filter) => { |
| 29 | + return languages.filter(({ type }) => $filter.checkboxes.includes(type)); |
| 30 | + }); |
| 31 | +
|
18 | 32 | onMount(async () => {
|
19 |
| - try { |
20 |
| - const response = await fetch( |
21 |
| - 'https://api.github.com/repos/o2sh/onefetch/releases/latest' |
22 |
| - ); |
23 |
| - const data = await response.json(); |
24 |
| -
|
25 |
| - tag_name = data.tag_name; |
26 |
| - html_url = data.html_url; |
27 |
| - } catch (error) { |
28 |
| - console.error('Error:', error); |
29 |
| - } |
| 33 | + const response = await fetch( |
| 34 | + 'https://api.github.com/repos/o2sh/onefetch/releases/latest' |
| 35 | + ); |
| 36 | + const data = await response.json(); |
| 37 | +
|
| 38 | + tagName = data.tag_name; |
| 39 | + htmlUrl = data.html_url; |
30 | 40 | });
|
31 | 41 | </script>
|
32 | 42 |
|
33 | 43 | <header>
|
34 |
| - {#if tag_name && html_url} |
| 44 | + {#if tagName && htmlUrl} |
35 | 45 | <div class="banner">
|
36 | 46 | <small
|
37 |
| - >Version {tag_name} is available 🎉 Check the |
38 |
| - <a href={html_url}>release notes</a>!!</small> |
| 47 | + >Version {tagName} is available 🎉 Check the |
| 48 | + <a href={htmlUrl}>release notes</a>!!</small> |
39 | 49 | </div>
|
40 | 50 | {/if}
|
41 | 51 | <h1>Onefetch</h1>
|
|
61 | 71 | Suggestions and PRs are welcome at <a
|
62 | 72 | href="https://github.com/o2sh/onefetch">github.com/o2sh/onefetch</a>
|
63 | 73 | </p>
|
64 |
| - <h3>Languages <small>({languages.length})</small></h3> |
65 |
| - {#each languages as language} |
| 74 | + |
| 75 | + <h3>Languages <small>({$filteredLanguages.length})</small></h3> |
| 76 | + |
| 77 | + <strong>Filter by type</strong> |
| 78 | + |
| 79 | + <div class="checkbox-group"> |
| 80 | + {#each languageTypes as type} |
| 81 | + <label for={type}> |
| 82 | + <input |
| 83 | + id={type} |
| 84 | + type="checkbox" |
| 85 | + value={type} |
| 86 | + bind:group={$filter.checkboxes} /> |
| 87 | + {type} |
| 88 | + </label> |
| 89 | + {/each} |
| 90 | + </div> |
| 91 | + |
| 92 | + <small |
| 93 | + >Note: By default, onefetch will only recognize <strong>programming</strong> |
| 94 | + and <strong>markup</strong> types. Use the |
| 95 | + <code>--type</code> flag to configure.</small> |
| 96 | + |
| 97 | + {#each $filteredLanguages as language} |
66 | 98 | <AsciiPreview
|
67 | 99 | name={language.name}
|
68 |
| - ansi={language.ansi} |
69 |
| - hex={language.hex} |
| 100 | + ansi={language.colors.ansi} |
| 101 | + hex={language.colors.hex} |
70 | 102 | ascii={language.ascii}
|
71 |
| - chip={language.chip} /> |
| 103 | + chip={language.colors.chip} /> |
72 | 104 | {/each}
|
73 | 105 | </main>
|
74 | 106 |
|
|
82 | 114 | text-align: center;
|
83 | 115 | padding: 0.5rem 0;
|
84 | 116 | }
|
| 117 | +
|
| 118 | + .checkbox-group { |
| 119 | + margin-top: 1.5rem; |
| 120 | + } |
| 121 | +
|
| 122 | + .checkbox-group label { |
| 123 | + width: fit-content; |
| 124 | + } |
| 125 | +
|
| 126 | + .checkbox-group label { |
| 127 | + text-transform: capitalize; |
| 128 | + } |
85 | 129 | </style>
|
0 commit comments