Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 37 additions & 0 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { PageServerLoad } from './$types';
import { getPublicConfigs } from '$lib/server/db';
import { countPackageTypes } from '$lib/fingerprint';

// Top community configs shown on the landing page. Featured first; falls back to
// an empty list if the DB binding isn't available so the section just hides.
export const load: PageServerLoad = async ({ platform }) => {
const db = platform?.env?.DB;
if (!db) return { communityConfigs: [] };

try {
const { results } = await getPublicConfigs(db, {
sort: 'featured',
visibility: 'public',
limit: 3,
offset: 0
});
const communityConfigs = results.map((c) => {
let pkgs: unknown[] = [];
try {
const parsed = JSON.parse(c.packages);
if (Array.isArray(parsed)) pkgs = parsed;
} catch {
pkgs = [];
}
return {
name: c.name,
slug: c.slug,
username: c.username,
counts: countPackageTypes(pkgs)
};
});
return { communityConfigs };
} catch {
return { communityConfigs: [] };
}
};
Loading
Loading