Skip to content

Commit c7fd1d5

Browse files
committed
feat: package descriptions with hover tooltips, redesigned Overview with category cards
1 parent 87da20e commit c7fd1d5

File tree

3 files changed

+348
-57
lines changed

3 files changed

+348
-57
lines changed

src/routes/[username]/[slug]/+page.server.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,43 @@ export const load: PageServerLoad = async ({ params, platform, request, cookies
3939
console.error('Failed to parse config JSON', e);
4040
}
4141

42+
const pkgs: {name: string; type: string; desc?: string}[] = Array.isArray(config.packages)
43+
? config.packages.map((p: any) => typeof p === 'string' ? {name: p, type: 'formula'} : p)
44+
: [];
45+
46+
const missing = pkgs.filter(p => !p.desc);
47+
if (missing.length > 0) {
48+
const descResults = await Promise.allSettled(
49+
missing.map(async (p) => {
50+
try {
51+
if (p.type === 'npm') {
52+
const r = await fetch(`https://registry.npmjs.org/${p.name}`, { cf: { cacheTtl: 86400, cacheEverything: true } } as RequestInit);
53+
if (r.ok) { const d = await r.json() as any; return { name: p.name, desc: d.description || '' }; }
54+
} else {
55+
const kind = p.type === 'cask' ? 'cask' : 'formula';
56+
const r = await fetch(`https://formulae.brew.sh/api/${kind}/${p.name}.json`, { cf: { cacheTtl: 86400, cacheEverything: true } } as RequestInit);
57+
if (r.ok) { const d = await r.json() as any; return { name: p.name, desc: d.desc || '' }; }
58+
}
59+
} catch {}
60+
return { name: p.name, desc: '' };
61+
})
62+
);
63+
for (const r of descResults) {
64+
if (r.status === 'fulfilled' && r.value.desc) {
65+
const pkg = pkgs.find(p => p.name === r.value.name);
66+
if (pkg) pkg.desc = r.value.desc;
67+
}
68+
}
69+
}
70+
71+
const packageDescriptions: Record<string, string> = {};
72+
for (const p of pkgs) {
73+
if (p.desc) packageDescriptions[p.name] = p.desc;
74+
}
75+
4276
return {
4377
configUser: targetUser,
44-
config
78+
config,
79+
packageDescriptions
4580
};
4681
};

0 commit comments

Comments
 (0)