Skip to content

Commit 0b007e2

Browse files
feat(frontend): prepare all data loading, add basic pages
1 parent 3173675 commit 0b007e2

File tree

5 files changed

+103
-2
lines changed

5 files changed

+103
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { error } from "@sveltejs/kit";
2+
import { discoverer } from "$lib/server/package-discoverer";
3+
import { svelteGitHubCache } from "$lib/server/github-cache";
4+
5+
export async function load({ params }) {
6+
const { package: pkg } = params;
7+
8+
// Discover packages, if this one doesn't exist, return 404
9+
const discovered = await discoverer.getOrDiscover();
10+
for (const { repoName, packages } of discovered) {
11+
for (const pkgName of packages) {
12+
if (pkgName.toLowerCase() === pkg.toLowerCase()) {
13+
return {
14+
releases: svelteGitHubCache.getReleases(repoName)
15+
};
16+
}
17+
}
18+
}
19+
20+
error(404);
21+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script lang="ts">
2+
let { data } = $props();
3+
</script>
4+
5+
{#await data.releases then release}
6+
{JSON.stringify(release, null, 2)}
7+
{/await}

src/routes/package/[package]/+page.svelte

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { repositories } from "$lib/repositories";
2+
import { discoverer } from "$lib/server/package-discoverer";
3+
4+
export async function load() {
5+
// Get all the packages and map them to their associated repo
6+
const packagesMapping = (await discoverer.getOrDiscover())
7+
.map(({ repoName, packages }) => {
8+
const matchingRepoInfo = repositories.find(([, { repos }]) =>
9+
repos.some(({ repoName: name }) => name === repoName)
10+
);
11+
if (!matchingRepoInfo) return null;
12+
const [, { name: category }] = matchingRepoInfo;
13+
return {
14+
category,
15+
packages: packages
16+
.map(pkg => ({ name: pkg, repoName }))
17+
.toSorted((a, b) => a.name.localeCompare(b.name))
18+
};
19+
})
20+
.filter(Boolean);
21+
22+
// Unify the result with identical repos by merging their packages
23+
const flattened = packagesMapping.reduce<Record<string, (typeof packagesMapping)[number]>>(
24+
(acc, { category, packages }) => {
25+
if (!acc[category]) {
26+
acc[category] = { category, packages: [] };
27+
}
28+
acc[category].packages.push(...packages);
29+
return acc;
30+
},
31+
{}
32+
);
33+
34+
return {
35+
// Return the processed unify array
36+
packages: Object.values(flattened)
37+
};
38+
}

src/routes/packages/+page.svelte

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
11
<script lang="ts">
2+
import { Separator } from "$lib/components/ui/separator";
3+
import { ChevronRight } from "@lucide/svelte";
4+
5+
let { data } = $props();
26
</script>
7+
8+
<div class="container py-8">
9+
<ul class="space-y-8">
10+
{#each data.packages as { category, packages } (category)}
11+
<li>
12+
<h3 class="text-2xl font-bold text-primary">{category}</h3>
13+
<ul class="mt-2">
14+
{#each packages as { name, repoName }, index (name)}
15+
{#if index > 0}
16+
<Separator class="mx-auto my-1 w-[95%]" />
17+
{/if}
18+
<li>
19+
<a
20+
href="/package/{name}"
21+
class="group flex items-center rounded-lg px-4 py-3 transition-colors hover:bg-neutral-800"
22+
>
23+
<div class="flex flex-col">
24+
<h4 class="font-medium">{name}</h4>
25+
{#if category === "Other"}
26+
<span class="text-muted-foreground">
27+
sveltejs/{repoName}
28+
</span>
29+
{/if}
30+
</div>
31+
<ChevronRight class="mr-1 ml-auto transition-transform group-hover:translate-x-1" />
32+
</a>
33+
</li>
34+
{/each}
35+
</ul>
36+
</li>
37+
{/each}
38+
</ul>
39+
</div>

0 commit comments

Comments
 (0)