Commit 083a9a5 1 parent 3e19034 commit 083a9a5 Copy full SHA for 083a9a5
File tree 13 files changed +913
-772
lines changed
app/(frontend)/komponenter/[slug]
13 files changed +913
-772
lines changed Original file line number Diff line number Diff line change 27
27
"@payloadcms/richtext-lexical" : " latest" ,
28
28
"@payloadcms/ui" : " latest" ,
29
29
"@portabletext/react" : " ^3.2.1" ,
30
+ "@portabletext/types" : " ^2.0.13" ,
30
31
"@sanity/client" : " ^6.28.1" ,
31
32
"@sanity/image-url" : " ^1.1.0" ,
32
33
"@sanity/ui" : " ^2.14.3" ,
Original file line number Diff line number Diff line change 1
- import PortableTextRenderer from "@/components/portable-text" ;
2
- import { PropDocumentation } from "@/components/prop-documentation/PropDocumentation" ;
1
+ import { PortableText } from "@/components/portable-text/PortableText" ;
3
2
import { client } from "@/sanity/client" ;
4
3
import { componentPageBySlugQuery } from "@/sanity/queries/componentPage" ;
5
4
@@ -16,13 +15,9 @@ export default async function Page({
16
15
< >
17
16
< div > Hei jeg er { data ?. title || "ikke i databasen" } </ div >
18
17
19
- { data ?. lede && < PortableTextRenderer value = { data . lede } /> }
18
+ { data ?. lede && < PortableText blocks = { data . lede } /> }
20
19
21
- { data ?. content && < PortableTextRenderer value = { data . content } /> }
22
-
23
- { data ?. component_folder && (
24
- < PropDocumentation component = { data . component_folder } />
25
- ) }
20
+ { data ?. content && < PortableText blocks = { data . content } /> }
26
21
</ >
27
22
) ;
28
23
}
Original file line number Diff line number Diff line change
1
+ import type {
2
+ PortableTextComponentProps ,
3
+ PortableTextReactComponents ,
4
+ } from "@portabletext/react" ;
5
+ import { PortableText as PortableTextReact } from "@portabletext/react" ;
6
+ import type { TypedObject } from "@portabletext/types" ;
7
+ import type { FC } from "react" ;
8
+ import { PropsDocumentation } from "./props-documentation/PropsDocumentation" ;
9
+
10
+ interface Props {
11
+ blocks : TypedObject [ ] | null ;
12
+ }
13
+
14
+ const portableTextComponents : Record <
15
+ string ,
16
+ FC < PortableTextComponentProps < any > >
17
+ > = {
18
+ "jokul_component-props" : PropsDocumentation ,
19
+ } ;
20
+
21
+ export const baseComponentDefinition : Partial < PortableTextReactComponents > = {
22
+ types : portableTextComponents ,
23
+ } ;
24
+
25
+ export const PortableText : FC < Props > = ( props ) => {
26
+ const components = {
27
+ ...baseComponentDefinition ,
28
+ types : {
29
+ ...baseComponentDefinition . types ,
30
+ } ,
31
+ } ;
32
+
33
+ if ( props . blocks === null ) {
34
+ return null ;
35
+ }
36
+
37
+ return < PortableTextReact value = { props . blocks } components = { components } /> ;
38
+ } ;
Load Diff This file was deleted.
File renamed without changes.
Original file line number Diff line number Diff line change 1
1
import { readFile } from "node:fs/promises" ;
2
- import { EOL } from "node:os" ;
3
2
import { resolve } from "node:path" ;
3
+ import { PortableTextTypeComponentProps } from "next-sanity" ;
4
+ import { FC } from "react" ;
4
5
import MissingTypesMessage from "./missing-types.mdx" ;
5
6
import { Props } from "./Props" ;
7
+ import type { PropsDocumentation as PropsDocumentationSchema } from "@/models/portable-text/propsDocumentationModel" ;
6
8
7
- type Props = { component : string } ;
8
-
9
- export async function PropDocumentation ( { component } : Props ) {
9
+ export const PropsDocumentation : FC <
10
+ PortableTextTypeComponentProps < PropsDocumentationSchema >
11
+ > = async ( { value } ) => {
10
12
const exampleFilePath = resolve (
11
13
process . cwd ( ) ,
12
14
".." ,
13
15
"packages" ,
14
16
"jokul" ,
15
17
"src" ,
16
18
"components" ,
17
- component ,
19
+ value . component_folder ,
18
20
"types.ts" ,
19
21
) ;
20
22
21
23
try {
22
24
const file = await readFile ( exampleFilePath ) ;
23
25
24
- return (
25
- < Props
26
- props = {
27
- file . toString ( )
28
- // .split(EOL)
29
- // .filter((line) => !line.startsWith("import"))
30
- // .join(EOL)
31
- }
32
- />
33
- ) ;
26
+ return < Props props = { file . toString ( ) } /> ;
34
27
} catch ( e ) {
35
28
return < MissingTypesMessage /> ;
36
29
}
37
- }
30
+ } ;
File renamed without changes.
You can’t perform that action at this time.
0 commit comments