Commit e900786 1 parent 006e4ad commit e900786 Copy full SHA for e900786
File tree 13 files changed +869
-729
lines changed
app/(frontend)/komponenter/[slug]
13 files changed +869
-729
lines changed Original file line number Diff line number Diff line change 20
20
"@mdx-js/react" : " ^2.3.0" ,
21
21
"@next/mdx" : " ^15.1.6" ,
22
22
"@portabletext/react" : " ^3.2.1" ,
23
+ "@portabletext/types" : " ^2.0.13" ,
23
24
"@sanity/client" : " ^6.28.1" ,
24
25
"@sanity/image-url" : " ^1.1.0" ,
25
26
"@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" ;
6
7
7
- type Props = { component : string } ;
8
+ type PropsDocumentationSchema = {
9
+ component_folder : string ;
10
+ } ;
8
11
9
- export async function PropDocumentation ( { component } : Props ) {
12
+ export const PropsDocumentation : FC <
13
+ PortableTextTypeComponentProps < PropsDocumentationSchema >
14
+ > = async ( { value } ) => {
10
15
const exampleFilePath = resolve (
11
16
process . cwd ( ) ,
12
17
".." ,
13
18
"packages" ,
14
19
"jokul" ,
15
20
"src" ,
16
21
"components" ,
17
- component ,
22
+ value . component_folder ,
18
23
"types.ts" ,
19
24
) ;
20
25
21
26
try {
22
27
const file = await readFile ( exampleFilePath ) ;
23
28
24
- return (
25
- < Props
26
- props = {
27
- file . toString ( )
28
- // .split(EOL)
29
- // .filter((line) => !line.startsWith("import"))
30
- // .join(EOL)
31
- }
32
- />
33
- ) ;
29
+ return < Props props = { file . toString ( ) } /> ;
34
30
} catch ( e ) {
35
31
return < MissingTypesMessage /> ;
36
32
}
37
- }
33
+ } ;
File renamed without changes.
You can’t perform that action at this time.
0 commit comments