@storyblok/astro 6.0.0-next.1 → 6.0.0-next.2

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.
Files changed (2) hide show
  1. package/README.md +26 -26
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -52,7 +52,7 @@ Add the following code to `astro.config.mjs` and replace the `accessToken` with
52
52
 
53
53
  ```js
54
54
  import { defineConfig } from "astro/config";
55
- import storyblok from "@storyblok/astro";
55
+ import { storyblok } from "@storyblok/astro";
56
56
 
57
57
  export default defineConfig({
58
58
  integrations: [
@@ -75,6 +75,7 @@ When you initialize the integration, you can pass all [_@storyblok/js_ options](
75
75
  storyblok({
76
76
  accessToken: "<your-access-token>",
77
77
  bridge: true,
78
+ livePreview: false,
78
79
  apiOptions: {}, // storyblok-js-client options
79
80
  components: {},
80
81
  componentsDir: "src",
@@ -174,7 +175,7 @@ const { blok } = Astro.props
174
175
  ---
175
176
 
176
177
  <main {...storyblokEditable(blok)}>
177
- {blok.body?.map(blok => {return <StoryblokComponent blok="{blok}" />})}
178
+ {blok.body?.map(blok => {return <StoryblokComponent blok={blok} />})}
178
179
  </main>
179
180
  ```
180
181
 
@@ -214,7 +215,7 @@ const { data } = await storyblokApi.get("cdn/stories/home", {
214
215
  const story = data.story;
215
216
  ---
216
217
 
217
- <StoryblokComponent blok="{story.content}" />
218
+ <StoryblokComponent blok={story.content} />
218
219
  ```
219
220
 
220
221
  > [!NOTE]
@@ -256,16 +257,13 @@ const { data } = await storyblokApi.get(`cdn/stories/${slug}`, {
256
257
  const story = data.story;
257
258
  ---
258
259
 
259
- <StoryblokComponent blok="{story.content}" />
260
+ <StoryblokComponent blok={story.content} />
260
261
  ```
261
262
 
262
263
  ### Using the Storyblok Bridge
263
264
 
264
265
  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`:
265
266
 
266
- > [!NOTE]
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.
268
-
269
267
  You can also provide a `StoryblokBridgeConfigV2` configuration object to the `bridge` parameter.
270
268
 
271
269
  ```ts
@@ -306,7 +304,7 @@ const { blok } = Astro.props
306
304
  const renderedRichText = renderRichText(blok.text)
307
305
  ---
308
306
 
309
- <div set:html="{renderedRichText}"></div>
307
+ <div set:html={renderedRichText}></div>
310
308
  ```
311
309
 
312
310
  You can also set a **custom Schema and component resolver** by passing the options as the second parameter of the `renderRichText` function:
@@ -350,9 +348,6 @@ Returns the instance of the `storyblok-js-client`.
350
348
 
351
349
  ## Enabling Live Preview for Storyblok's Visual Editor
352
350
 
353
- > [!WARNING]
354
- > This feature is currently experimental and optional. You may encounters bugs or performance issues.
355
-
356
351
  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.
357
352
 
358
353
  > [!NOTE]
@@ -375,28 +370,33 @@ export default defineConfig({
375
370
  });
376
371
  ```
377
372
 
378
- 2. Additionally, please use `useStoryblok` on your Astro pages for story fetching. This replaces the previously used `useStoryblokApi` method.
373
+ 2. Additionally, please use `getLiveStory` on your Astro pages for live story fetching.
379
374
 
380
375
  ```jsx
381
376
  //pages/[...slug].astro
382
377
  ---
383
- import { useStoryblok } from "@storyblok/astro";
378
+ import {
379
+ getLiveStory,
380
+ useStoryblokApi,
381
+ type ISbStoryData,
382
+ } from '@storyblok/astro';
384
383
  import StoryblokComponent from "@storyblok/astro/StoryblokComponent.astro";
385
384
 
386
385
  const { slug } = Astro.params;
387
-
388
- const story = await useStoryblok(
389
- // The slug to fetch
390
- `cdn/stories/${slug === undefined ? "home" : slug}`,
391
- // The API options
392
- {
393
- version: "draft",
394
- },
395
- // The Bridge options (optional, if an empty object, null, or false are set, the API options will be considered automatically as far as applicable)
396
- {},
397
- // The Astro object (essential for the live preview functionality)
398
- Astro
399
- );
386
+ let story: ISbStoryData | null = null;
387
+
388
+ const liveStory = await getLiveStory(Astro);
389
+ if (liveStory) {
390
+ story = liveStory;
391
+ } else {
392
+ const sbApi = useStoryblokApi();
393
+ const { data } = await sbApi.get(`cdn/stories/${slug || 'home'}`, {
394
+ version: 'draft',
395
+ resolve_relations: ['featured-articles.posts'],
396
+ });
397
+ story = data?.story;
398
+ }
399
+ // If you are using `resolve_relations` or `resolve_links`, you must also pass them to the Bridge configuration in `astro.config.mjs`.
400
400
  ---
401
401
 
402
402
  <StoryblokComponent blok={story.content} />
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
3
  "type": "module",
4
- "version": "6.0.0-next.1",
4
+ "version": "6.0.0-next.2",
5
5
  "private": false,
6
6
  "packageManager": "pnpm@9.13.2",
7
7
  "description": "Official Astro integration for the Storyblok Headless CMS",