File size: 2,226 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import {
  BlockQuote,
  BulletList,
  CodeBlock,
  DotImage,
  Heading,
  ListItem,
  OrderedList,
  Paragraph,
  TextNode,
} from "./blocks";

/*
  dotCMS Block Editor is a new rich content editor that allows you to create your content as building blocks.

  More info: https://dotcms.com/docs/latest/block-editor
*/

export const ContentBlocks = ({ content }) => {
  return (
    <>
      {content?.map((data, index) => {
        switch (data.type) {
          case "paragraph":
            return (
              <Paragraph key={index}>
                <ContentBlocks content={data.content} />
              </Paragraph>
            );
          case "heading":
            return (
              <Heading key={index} level={data.attrs.level}>
                <ContentBlocks content={data.content} />
              </Heading>
            );

          case "bulletList":
            return (
              <BulletList key={index}>
                <ContentBlocks content={data.content} />
              </BulletList>
            );

          case "orderedList":
            return (
              <OrderedList key={index}>
                <ContentBlocks content={data.content} />
              </OrderedList>
            );

          case "dotImage":
            return <DotImage key={index} {...data} />;

          case "horizontalRule":
            return <hr key={index} />;

          case "blockquote":
            return (
              <BlockQuote key={index}>
                <ContentBlocks content={data.content} />
              </BlockQuote>
            );

          case "codeBlock":
            return (
              <CodeBlock language={data.attrs.language} key={index}>
                <ContentBlocks content={data.content} />
              </CodeBlock>
            );

          case "hardBreak":
            return <br key={index} />;

          case "text":
            return <TextNode key={index} {...data} />;

          case "listItem":
            return (
              <ListItem key={index}>
                <ContentBlocks content={data.content} />
              </ListItem>
            );

          default:
            return <p>Block not supported</p>;
        }
      })}
    </>
  );
};