File tree Expand file tree Collapse file tree 3 files changed +37
-37
lines changed
v4/src/routes/(view)/view/[name] Expand file tree Collapse file tree 3 files changed +37
-37
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
<script lang =" ts" >
2
2
import { cn } from " $lib/utils.js" ;
3
- import { Blocks } from " $lib/../__registry__/blocks.js" ;
4
3
import type { PageProps } from " ./$types.js" ;
5
4
6
5
let { data }: PageProps = $props ();
7
-
8
- const block = $derived (Blocks [data .block .name ]);
9
6
</script >
10
7
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 />
15
10
</div >
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments