forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategories.ts
More file actions
39 lines (33 loc) 路 1.06 KB
/
Copy pathcategories.ts
File metadata and controls
39 lines (33 loc) 路 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import YAML from "yaml";
import { type PortEntry, ports } from "./ports.ts";
export type Category = {
key: string;
name: string;
description: string;
emoji: string;
};
const CATEGORIES_URL =
"https://raw.githubusercontent.com/catppuccin/catppuccin/d4f82739e687cfd19d168be355367fdbbcc8e029/resources/categories.yml";
const content = await fetch(
CATEGORIES_URL,
).then((res) => res.text());
const parsed = YAML.parse(content) as Category[];
// Turn into a lookup table by key
export const categories = Object.fromEntries(parsed.map((c) => [c.key, c]));
// Group ports by category
export const categoryMap: Record<string, typeof ports> = ports.reduce(
(acc, port) => {
for (const cat of port.categories) {
if (!acc[cat]) acc[cat] = [];
acc[cat].push(port);
}
return acc;
},
{} as Record<string, PortEntry[]>,
);
// Sort categories by name
export const sortedCategories = Object.keys(categoryMap).sort((a, b) => {
const aName = categories[a]?.name ?? a;
const bName = categories[b]?.name ?? b;
return aName.localeCompare(bName);
});