@storyblok/astro 3.0.1-next.2 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ ---
2
+ import type { SbBlokData } from "./dist/types";
3
+
4
+ interface Props {
5
+ blok: SbBlokData;
6
+ }
7
+
8
+ const { blok } = Astro.props;
9
+ ---
10
+
11
+ <section>
12
+ <div>
13
+ <p>
14
+ Component could not be found for blok <span class="component"
15
+ >{blok.component}</span
16
+ >! Is it configured correctly?
17
+ </p>
18
+ </div>
19
+ </section>
20
+
21
+ <style scoped>
22
+ section {
23
+ display: flex;
24
+ justify-content: center;
25
+ padding: 60px 0;
26
+ }
27
+ div {
28
+ display: inline-flex;
29
+ background-color: #eff1f3;
30
+ text-align: center;
31
+ padding: 15px 30px;
32
+ border-radius: 5px;
33
+ }
34
+ span.component {
35
+ color: #00b3b0;
36
+ font-weight: bold;
37
+ }
38
+ </style>
@@ -0,0 +1,2 @@
1
+ import FallbackComponent from "./FallbackComponent.astro";
2
+ export default FallbackComponent;
@@ -0,0 +1,32 @@
1
+ ---
2
+ import { renderRichText } from "../";
3
+ import type { ISbRichtext, SbBlokData, SbRichTextOptions } from "../dist/types";
4
+
5
+ import StoryblokComponent from "./StoryblokComponent.astro";
6
+
7
+ export interface Props {
8
+ richTextData?: ISbRichtext;
9
+ richTextOptions?: SbRichTextOptions;
10
+ }
11
+
12
+ const { richTextData, richTextOptions } = Astro.props;
13
+ ---
14
+
15
+ {
16
+ richTextData?.content?.map((richTextNode: ISbRichtext) => {
17
+ if (richTextNode.type === "blok") {
18
+ return richTextNode.attrs.body.map((blok: SbBlokData) => (
19
+ <StoryblokComponent blok={blok} />
20
+ ));
21
+ } else {
22
+ return (
23
+ <Fragment
24
+ set:html={renderRichText(
25
+ { type: richTextNode.type, content: [richTextNode] },
26
+ richTextOptions
27
+ )}
28
+ />
29
+ );
30
+ }
31
+ })
32
+ }
@@ -0,0 +1,2 @@
1
+ import RichTextRenderer from "./RichTextRenderer.astro";
2
+ export default RichTextRenderer;
@@ -0,0 +1,43 @@
1
+ ---
2
+ import components from "virtual:storyblok-components";
3
+ import options from "virtual:storyblok-options";
4
+ import camelcase from "camelcase";
5
+ import type { SbBlokData } from "./dist/types";
6
+ import type { AstroComponentFactory } from "astro/dist/runtime/server";
7
+
8
+ interface Props {
9
+ blok: SbBlokData;
10
+ [prop: string]: unknown;
11
+ }
12
+
13
+ const { blok, ...props } = Astro.props;
14
+
15
+ if (!blok) {
16
+ throw new Error(
17
+ "Cannot render StoryblokComponent. 'blok' prop is undefined."
18
+ );
19
+ }
20
+
21
+ /**
22
+ * convert blok components to camel case to match vite-plugin-storyblok-components
23
+ */
24
+ let key = camelcase(blok.component);
25
+
26
+ const componentFound: boolean = key in components;
27
+
28
+ let Component: AstroComponentFactory;
29
+
30
+ if (!componentFound) {
31
+ if (!options.enableFallbackComponent)
32
+ throw new Error(
33
+ `Component could not be found for blok "${blok.component}"! Is it defined in astro.config.mjs?`
34
+ );
35
+ else {
36
+ Component = components["FallbackComponent"];
37
+ }
38
+ } else {
39
+ Component = components[key];
40
+ }
41
+ ---
42
+
43
+ <Component blok={blok} {...props} />
@@ -0,0 +1,2 @@
1
+ import StoryblokComponent from "./StoryblokComponent.astro";
2
+ export default StoryblokComponent;
package/package.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
- "version": "3.0.1-next.2",
3
+ "version": "3.0.1",
4
4
  "description": "Official Astro integration for the Storyblok Headless CMS",
5
5
  "main": "./dist/storyblok-astro.js",
6
6
  "module": "./dist/storyblok-astro.mjs",
7
7
  "files": [
8
8
  "dist",
9
- "StoryblokComponent.astro",
10
- "FallbackComponent.astro",
11
- "RichTextRenderer.astro"
9
+ "components"
12
10
  ],
13
11
  "exports": {
14
12
  ".": {