|
1 | 1 | import type { |
2 | 2 | ISbStoriesParams, |
3 | 3 | StoryblokClient, |
4 | | - StoryblokRichTextNode, |
5 | 4 | } from '@storyblok/react/rsc'; |
6 | | -import { MarkTypes, StoryblokRichText, StoryblokStory, |
| 5 | +import { StoryblokStory, |
7 | 6 | } from '@storyblok/react/rsc'; |
8 | 7 | import { getStoryblokApi } from '@/lib/storyblok'; |
9 | | -import Link from 'next/link'; |
10 | | -import type { ReactElement } from 'react'; |
| 8 | +// import Link from 'next/link'; |
11 | 9 |
|
12 | 10 | export default async function Home() { |
13 | 11 | const { data } = await fetchData(); |
14 | 12 |
|
15 | | - const doc = { |
16 | | - type: 'doc', |
17 | | - content: [ |
18 | | - { |
19 | | - type: 'paragraph', |
20 | | - content: [ |
21 | | - { |
22 | | - type: 'text', |
23 | | - text: 'This is a test of the StoryblokRichText component.', |
24 | | - }, |
25 | | - ], |
26 | | - }, |
27 | | - { |
28 | | - type: 'paragraph', |
29 | | - content: [ |
30 | | - { |
31 | | - text: 'Internal Link', |
32 | | - type: 'text', |
33 | | - marks: [ |
34 | | - { |
35 | | - type: 'link', |
36 | | - attrs: { |
37 | | - href: '/', |
38 | | - uuid: '8489bed8-d86f-4fde-965c-e3d748e12147', |
39 | | - anchor: null, |
40 | | - target: '_self', |
41 | | - linktype: 'story', |
42 | | - }, |
43 | | - }, |
44 | | - ], |
45 | | - }, |
46 | | - ], |
47 | | - }, |
48 | | - { |
49 | | - type: 'paragraph', |
50 | | - content: [ |
51 | | - { |
52 | | - text: 'External link', |
53 | | - type: 'text', |
54 | | - marks: [ |
55 | | - { |
56 | | - type: 'link', |
57 | | - attrs: { |
58 | | - href: 'https://alvarosaburido.dev', |
59 | | - uuid: null, |
60 | | - anchor: null, |
61 | | - target: '_blank', |
62 | | - linktype: 'url', |
63 | | - }, |
64 | | - }, |
65 | | - ], |
66 | | - }, |
67 | | - ], |
68 | | - }, |
69 | | - ], |
70 | | - }; |
71 | | - const resolvers = { |
72 | | - // custom resolvers |
73 | | - [MarkTypes.LINK]: (node: StoryblokRichTextNode<ReactElement>) => { |
74 | | - return node.attrs?.linktype === 'story' |
75 | | - ? ( |
76 | | - <Link |
77 | | - href={node.attrs?.href} |
78 | | - target={node.attrs?.target} |
79 | | - > |
80 | | - {node.text} |
81 | | - </Link> |
82 | | - ) |
83 | | - : ( |
84 | | - <a |
85 | | - href={node.attrs?.href} |
86 | | - target={node.attrs?.target} |
87 | | - > |
88 | | - {node.text} |
89 | | - </a> |
90 | | - ); |
91 | | - }, |
92 | | - }; |
93 | | - |
94 | 13 | return ( |
95 | | - <div> |
96 | | - <h1> |
97 | | - Story: |
98 | | - {data.story.id} |
99 | | - </h1> |
100 | | - <StoryblokStory story={data.story} /> |
101 | | - <StoryblokRichText doc={doc} resolvers={resolvers} /> |
102 | | - </div> |
| 14 | + <main className="container mx-auto px-4 py-8"> |
| 15 | + <div className="max-w-4xl mx-auto clas prose"> |
| 16 | + <h1 className="text-4xl font-bold mb-8 dark:text-white"> |
| 17 | + Storyblok Next.js 15 Example |
| 18 | + </h1> |
| 19 | + |
| 20 | + { // TODO: Enable for https://github.com/storyblok/monoblok/issues/35 |
| 21 | + /* <nav className="space-y-4"> |
| 22 | + <Link |
| 23 | + href="/richtext" |
| 24 | + className="block p-4 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors" |
| 25 | + > |
| 26 | + Go to Rich Text Example |
| 27 | + </Link> |
| 28 | + </nav> */} |
| 29 | + |
| 30 | + {data.story && ( |
| 31 | + <div> |
| 32 | + <StoryblokStory story={data.story} /> |
| 33 | + </div> |
| 34 | + )} |
| 35 | + </div> |
| 36 | + </main> |
103 | 37 | ); |
104 | 38 | } |
105 | 39 |
|
106 | 40 | export async function fetchData() { |
107 | 41 | const sbParams: ISbStoriesParams = { version: 'draft' }; |
108 | 42 |
|
109 | 43 | const storyblokApi: StoryblokClient = getStoryblokApi(); |
110 | | - return storyblokApi.get(`cdn/stories/home`, sbParams); |
| 44 | + return storyblokApi.get(`cdn/stories/react`, sbParams); |
111 | 45 | } |
0 commit comments