@storyblok/astro 4.1.1 → 5.0.0
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.
package/README.md
CHANGED
|
@@ -28,9 +28,11 @@
|
|
|
28
28
|
</p>
|
|
29
29
|
|
|
30
30
|
## Kickstart a new project
|
|
31
|
+
|
|
31
32
|
Are you eager to dive into coding? **[Follow these steps to kickstart a new project with Storyblok and Astro](https://www.storyblok.com/technologies#astro?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro)**, and get started in just a few minutes!
|
|
32
33
|
|
|
33
34
|
## Ultimate Tutorial
|
|
35
|
+
|
|
34
36
|
Are you looking for a hands-on, step-by-step tutorial? The **[Astro Ultimate Tutorial](https://www.storyblok.com/tp/the-storyblok-astro-ultimate-tutorial?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro)** has you covered! It provides comprehensive instructions on building a complete, multilingual website using Storyblok and Astro from start to finish.
|
|
35
37
|
|
|
36
38
|
## Installation
|
|
@@ -43,7 +45,7 @@ npm install @storyblok/astro
|
|
|
43
45
|
# See below for pnpm
|
|
44
46
|
```
|
|
45
47
|
|
|
46
|
-
>
|
|
48
|
+
> [!NOTE]
|
|
47
49
|
> With pnpm, hoist Storyblok dependencies publicly with `.npmrc`. For more information, check pnpm documentation on [here](https://pnpm.io/npmrc).
|
|
48
50
|
|
|
49
51
|
Add the following code to `astro.config.mjs` and replace the `accessToken` with the preview API token of your Storyblok space.
|
|
@@ -61,7 +63,7 @@ export default defineConfig({
|
|
|
61
63
|
});
|
|
62
64
|
```
|
|
63
65
|
|
|
64
|
-
>
|
|
66
|
+
> [!WARNING]
|
|
65
67
|
> This SDK uses the Fetch API under the hood. If your environment doesn't support it, you need to install a polyfill like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch). More info on [storyblok-js-client docs](https://github.com/storyblok/storyblok-js-client#fetch-use-polyfill-if-needed---version-5).
|
|
66
68
|
|
|
67
69
|
### Options
|
|
@@ -82,7 +84,7 @@ storyblok({
|
|
|
82
84
|
});
|
|
83
85
|
```
|
|
84
86
|
|
|
85
|
-
>
|
|
87
|
+
> [!NOTE]
|
|
86
88
|
> By default, the `apiPlugin` from `@storyblok/js` is loaded. If you want to use your own method to fetch data from Storyblok, you can disable this behavior by setting `useCustomApi` to `true`, resulting in an optimized final bundle.
|
|
87
89
|
|
|
88
90
|
#### Region parameter
|
|
@@ -106,7 +108,7 @@ storyblok({
|
|
|
106
108
|
});
|
|
107
109
|
```
|
|
108
110
|
|
|
109
|
-
>
|
|
111
|
+
> [!WARNING]
|
|
110
112
|
> For spaces created in the United States or China, the `region` parameter **must** be specified.
|
|
111
113
|
|
|
112
114
|
## Getting started
|
|
@@ -126,7 +128,7 @@ components: {
|
|
|
126
128
|
},
|
|
127
129
|
```
|
|
128
130
|
|
|
129
|
-
>
|
|
131
|
+
> [!NOTE]
|
|
130
132
|
> The `src` folder is automatically added to the beginning of the path, so in this example your Astro components should be located here:
|
|
131
133
|
>
|
|
132
134
|
> - `src/storyblok/Page.astro`
|
|
@@ -136,7 +138,7 @@ components: {
|
|
|
136
138
|
>
|
|
137
139
|
> You can choose any other folder in the `src` directory for your Astro components.
|
|
138
140
|
|
|
139
|
-
>
|
|
141
|
+
> [!NOTE]
|
|
140
142
|
> If you prefer to use a different folder than `src`, you can specify one using the `componentsDir` option:
|
|
141
143
|
>
|
|
142
144
|
> ```js
|
|
@@ -176,7 +178,7 @@ const { blok } = Astro.props
|
|
|
176
178
|
</main>
|
|
177
179
|
```
|
|
178
180
|
|
|
179
|
-
>
|
|
181
|
+
> [!NOTE]
|
|
180
182
|
> The `blok` is the actual blok data coming from [Storblok's Content Delivery API](https://www.storyblok.com/docs/api/content-delivery/v2?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro).
|
|
181
183
|
|
|
182
184
|
#### Using fallback components
|
|
@@ -215,7 +217,7 @@ const story = data.story;
|
|
|
215
217
|
<StoryblokComponent blok="{story.content}" />
|
|
216
218
|
```
|
|
217
219
|
|
|
218
|
-
>
|
|
220
|
+
> [!NOTE]
|
|
219
221
|
> The available methods are described in the [storyblok-js-client] repository(https://github.com/storyblok/storyblok-js-client#method-storyblokget)
|
|
220
222
|
|
|
221
223
|
#### Dynamic Routing
|
|
@@ -261,7 +263,7 @@ const story = data.story;
|
|
|
261
263
|
|
|
262
264
|
The Storyblok Bridge is enabled by default. If you would like to disable it or enable it conditionally (e.g. depending on the environment) you can set the `bridge` parameter to `true` or `false` in `astro.config.mjs`:
|
|
263
265
|
|
|
264
|
-
>
|
|
266
|
+
> [!NOTE]
|
|
265
267
|
> Since Astro is not a reactive JavaScript framework and renders everything as HTML, the Storyblok Bridge will not provide real-time editing as you may know it from other frameworks. However, it automatically refreshes the site for you whenever you save or publish a story.
|
|
266
268
|
|
|
267
269
|
You can also provide a `StoryblokBridgeConfigV2` configuration object to the `bridge` parameter.
|
|
@@ -280,7 +282,7 @@ bridge: {
|
|
|
280
282
|
- `resolveRelations` may be needed to resolve the same relations that are already resolved in the API requests via the `resolve_relations` parameter.
|
|
281
283
|
- `resolveLinks` may be needed to resolve link fields.
|
|
282
284
|
|
|
283
|
-
>
|
|
285
|
+
> [!NOTE]
|
|
284
286
|
> `resolveRelations` and `resolveLinks` will not have any effect in Astro, since the Storyblok Bridge is configured to reload the page. Thus, all the requests needed will be performed after the reload.
|
|
285
287
|
|
|
286
288
|
The provided options will be used when initializing the Storyblok Bridge. You can find more information about the Storyblok Bridge and its configuration options on the [In Depth Storyblok Bridge guide](https://www.storyblok.com/docs/guide/in-depth/storyblok-latest-js-v2?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro).
|
|
@@ -289,10 +291,10 @@ If you want to deploy a dedicated preview environment with the Bridge enabled, a
|
|
|
289
291
|
|
|
290
292
|
### Rendering Rich Text
|
|
291
293
|
|
|
292
|
-
>
|
|
294
|
+
> [!NOTE]
|
|
293
295
|
> While @storyblok/astro provides basic richtext rendering capabilities, for advanced use cases, it is highly recommended to use [storyblok-rich-text-astro-renderer](https://github.com/NordSecurity/storyblok-rich-text-astro-renderer).
|
|
294
296
|
|
|
295
|
-
You can easily render rich text by using either the `renderRichText` function
|
|
297
|
+
You can easily render rich text by using either the `renderRichText` function included in `@storyblok/astro`.
|
|
296
298
|
Use `renderRichText`, which only supports parsing and returning native HTML tags, if you are not embedding `bloks` in your rich text. Then you can use the [`set:html` directive](https://docs.astro.build/en/reference/directives-reference/#sethtml):
|
|
297
299
|
|
|
298
300
|
```jsx
|
|
@@ -307,8 +309,6 @@ const renderedRichText = renderRichText(blok.text)
|
|
|
307
309
|
<div set:html="{renderedRichText}"></div>
|
|
308
310
|
```
|
|
309
311
|
|
|
310
|
-
Use the `<RichTextRenderer />` component if you are embedding `bloks` in your rich text:
|
|
311
|
-
|
|
312
312
|
```jsx
|
|
313
313
|
---
|
|
314
314
|
import RichTextRenderer from "@storyblok/astro/RichTextRenderer.astro";
|
|
@@ -345,41 +345,12 @@ const renderedRichText = renderRichText(blok.text, {
|
|
|
345
345
|
});
|
|
346
346
|
```
|
|
347
347
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
```jsx
|
|
351
|
-
---
|
|
352
|
-
import { RichTextSchema } from "@storyblok/astro";
|
|
353
|
-
import RichTextRenderer from "@storyblok/astro/RichTextRenderer.astro";
|
|
354
|
-
|
|
355
|
-
import cloneDeep from "clone-deep";
|
|
356
|
-
|
|
357
|
-
const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
|
|
358
|
-
// ... and edit the nodes and marks, or add your own.
|
|
359
|
-
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/v4/source/schema.js
|
|
360
|
-
|
|
361
|
-
const { blok } = Astro.props;
|
|
348
|
+
### RichTextRenderer `deprecated`
|
|
362
349
|
|
|
363
|
-
|
|
364
|
-
schema: mySchema,
|
|
365
|
-
resolver: (component, blok) => {
|
|
366
|
-
switch (component) {
|
|
367
|
-
case "my-custom-component":
|
|
368
|
-
return `<div class="my-component-class">${blok.text}</div>`;
|
|
369
|
-
break;
|
|
370
|
-
default:
|
|
371
|
-
return `Component ${component} not found`;
|
|
372
|
-
}
|
|
373
|
-
},
|
|
374
|
-
};
|
|
375
|
-
---
|
|
376
|
-
|
|
377
|
-
<RichTextRenderer richTextData={blok.richtext} richTextOptions={options} />
|
|
378
|
-
|
|
379
|
-
```
|
|
350
|
+
~~Use the `<RichTextRenderer />` component if you are embedding `bloks` in your rich text:~~
|
|
380
351
|
|
|
381
|
-
>
|
|
382
|
-
>
|
|
352
|
+
> [!IMPORTANT]
|
|
353
|
+
> As of `@storyblok/astro` v5, the `<RichTextRenderer />` component has been removed. Use the `renderRichText` function instead.
|
|
383
354
|
|
|
384
355
|
## API
|
|
385
356
|
|
|
@@ -389,12 +360,12 @@ Returns the instance of the `storyblok-js-client`.
|
|
|
389
360
|
|
|
390
361
|
## Enabling Live Preview for Storyblok's Visual Editor
|
|
391
362
|
|
|
392
|
-
>
|
|
363
|
+
> [!WARNING]
|
|
393
364
|
> This feature is currently experimental and optional. You may encounters bugs or performance issues.
|
|
394
365
|
|
|
395
366
|
The Astro SDK now provides a live preview feature, designed to offer real-time editing capabilities for an enhanced user experience in Storyblok's Visual Editor.
|
|
396
367
|
|
|
397
|
-
>
|
|
368
|
+
> [!NOTE]
|
|
398
369
|
> To utilize the Astro Storyblok Live feature, Astro must be configured to run in SSR mode.
|
|
399
370
|
|
|
400
371
|
To activate the experimental live preview feature, follow these steps:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
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",
|
|
@@ -27,11 +27,6 @@
|
|
|
27
27
|
"import": "./components/FallbackComponent.ts",
|
|
28
28
|
"require": "./components/FallbackComponent.ts"
|
|
29
29
|
},
|
|
30
|
-
"./RichTextRenderer.astro": {
|
|
31
|
-
"types": "./components/RichTextRenderer.ts",
|
|
32
|
-
"import": "./components/RichTextRenderer.ts",
|
|
33
|
-
"require": "./components/RichTextRenderer.ts"
|
|
34
|
-
},
|
|
35
30
|
"./toolbarApp.ts": {
|
|
36
31
|
"types": "./dev-toolbar/toolbarApp.ts",
|
|
37
32
|
"import": "./dev-toolbar/toolbarApp.ts",
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|