|
2 | 2 | import { building } from '$app/environment'
|
3 | 3 | import { goto } from '$app/navigation'
|
4 | 4 | import { Card } from '$lib'
|
5 |
| - import { filter_tags, filtered_figs, search, tag_filter_mode } from '$lib/stores' |
6 |
| - import figs from '$lib/tikz-figures.json' |
| 5 | + import { |
| 6 | + diagrams, |
| 7 | + filter_tags, |
| 8 | + filtered_diagrams, |
| 9 | + search, |
| 10 | + tag_filter_mode, |
| 11 | + } from '$lib/stores' |
7 | 12 | import { homepage, repository } from '$root/package.json'
|
8 | 13 | import Icon from '@iconify/svelte'
|
9 | 14 | import MultiSelect from 'svelte-multiselect'
|
|
13 | 18 | $: cols = clamp(Math.floor(innerWidth / 300), 1, 6)
|
14 | 19 |
|
15 | 20 | const tags = Object.entries(
|
16 |
| - figs |
17 |
| - .flatMap((file) => file.tags) |
| 21 | + diagrams |
| 22 | + ?.flatMap((file) => file.tags) |
18 | 23 | .reduce(
|
19 | 24 | (acc, el) => {
|
20 | 25 | acc[el] = (acc[el] ?? 0) + 1
|
|
23 | 28 | {} as Record<string, number>,
|
24 | 29 | ),
|
25 | 30 | ).filter(([, count]) => count > 2)
|
26 |
| - tags.sort(([a], [b]) => a.localeCompare(b)) |
| 31 | + tags.sort(([t1], [t2]) => t1.localeCompare(t2)) |
27 | 32 |
|
28 | 33 | const clamp = (num: number, min: number, max: number) =>
|
29 | 34 | Math.min(Math.max(num, min), max)
|
30 | 35 |
|
31 |
| - $: $filtered_figs = figs |
| 36 | + $: $filtered_diagrams = diagrams |
32 | 37 | .filter((file) => {
|
33 | 38 | const searchTerms = $search?.toLowerCase().split(` `)
|
34 | 39 | const matches_search = searchTerms?.every((term) =>
|
|
45 | 50 | }
|
46 | 51 | return matches_search && matches_tags
|
47 | 52 | })
|
48 |
| - .sort((a, b) => { |
49 |
| - return a.title.localeCompare(b.title) |
| 53 | + .sort((d1, d2) => { |
| 54 | + return d1.title.localeCompare(d2.title) |
50 | 55 | })
|
51 | 56 |
|
52 |
| - const meta_description = `Random collection of ${figs.length} TikZ figures` |
| 57 | + const meta_description = `Collection of ${diagrams.length} math/physics/chemistry/ML diagrams` |
53 | 58 |
|
54 | 59 | let active_idx = -1
|
55 | 60 |
|
56 | 61 | function handle_keyup(event: KeyboardEvent) {
|
57 | 62 | if (event.key === `Enter` && active_idx >= 0) {
|
58 |
| - const site = figs[active_idx] |
| 63 | + const site = diagrams[active_idx] |
59 | 64 | goto(site.slug)
|
60 | 65 | }
|
61 | 66 | const to = {
|
62 | 67 | // wrap around
|
63 |
| - ArrowLeft: (active_idx - 1 + figs.length) % figs.length, |
64 |
| - ArrowRight: (active_idx + 1) % figs.length, |
| 68 | + ArrowLeft: (active_idx - 1 + diagrams.length) % diagrams.length, |
| 69 | + ArrowRight: (active_idx + 1) % diagrams.length, |
65 | 70 | Escape: -1,
|
66 | 71 | }[event.key]
|
67 | 72 | // if not arrow or escape key, return early for browser default behavior
|
|
86 | 91 | <svelte:window bind:innerWidth on:keyup={handle_keyup} />
|
87 | 92 |
|
88 | 93 | <h1>
|
89 |
| - Random |
90 | 94 | <img src="favicon.svg" alt="Logo" style="height: 2em; vertical-align: middle;" />
|
91 | 95 | Collection
|
92 | 96 | </h1>
|
93 | 97 | <p>
|
94 |
| - {figs.length} standalone TikZ figures, mostly about |
| 98 | + {diagrams.length} Cetz (Typst) and TikZ (LaTeX) diagrams, mostly about |
95 | 99 | {#each [`physics`, `chemistry`, `machine learning`] as tag, idx}
|
96 | 100 | {#if idx > 0},{/if}
|
97 | 101 | <button class="link" on:click={() => ($filter_tags = [{ label: tag, count: 0 }])}>
|
|
127 | 131 | </div>
|
128 | 132 |
|
129 | 133 | {#if $search?.length || $filter_tags?.length}
|
130 |
| - <p>{$filtered_figs.length} match{$filtered_figs.length != 1 ? `es` : ``}</p> |
| 134 | + <p>{$filtered_diagrams.length} match{$filtered_diagrams.length != 1 ? `es` : ``}</p> |
131 | 135 | {/if}
|
132 | 136 |
|
133 | 137 | {#if cols || building}
|
|
136 | 140 | style="column-gap: 1em;"
|
137 | 141 | use:highlight_matches={{ query: $search, css_class: `highlight-match` }}
|
138 | 142 | >
|
139 |
| - {#each $filtered_figs as item, idx (item.slug)} |
| 143 | + {#each $filtered_diagrams as item, idx (item.slug)} |
140 | 144 | <li class:active={active_idx == idx}>
|
141 | 145 | <Card {item} style="break-inside: avoid;" />
|
142 | 146 | </li>
|
|
0 commit comments