Skip to content

Commit 4722b20

Browse files
committed
lets give this a shot
1 parent 93f090c commit 4722b20

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

v4/src/routes/(view)/view/[name]/+page.server.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
<script lang="ts">
22
import { cn } from "$lib/utils.js";
3-
import { Blocks } from "$lib/../__registry__/blocks.js";
43
import type { PageProps } from "./$types.js";
54
65
let { data }: PageProps = $props();
7-
8-
const block = $derived(Blocks[data.block.name]);
96
</script>
107

11-
<div class={cn("bg-background", data.block?.container?.className)}>
12-
{#await block.component() then BlockComponent}
13-
<BlockComponent />
14-
{/await}
8+
<div class={cn("bg-background")}>
9+
<data.component />
1510
</div>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { error } from "@sveltejs/kit";
2+
import type { EntryGenerator } from "./$types.js";
3+
import { getAllBlockIds } from "$lib/blocks.js";
4+
5+
export const prerender = true;
6+
7+
export const entries: EntryGenerator = async () => {
8+
console.info("Prerendering /view/[name]");
9+
const blockIds = getAllBlockIds();
10+
11+
return blockIds.map((name) => ({ name }));
12+
};
13+
14+
export async function load({ params }) {
15+
const modules = import.meta.glob("/src/lib/registry/blocks/**/+page.svelte");
16+
const blockName = params.name;
17+
18+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
19+
let match: { path?: string; resolver?: () => Promise<any> } = {};
20+
21+
for (const [path, resolver] of Object.entries(modules)) {
22+
if (path.includes(blockName)) {
23+
match = { path, resolver };
24+
break;
25+
}
26+
}
27+
28+
const comp = await match?.resolver?.();
29+
30+
if (!comp) error(404, "Block not found");
31+
32+
return {
33+
component: comp.default,
34+
};
35+
}

0 commit comments

Comments
 (0)