• Stars
    star
    256
  • Rank 159,219 (Top 4 %)
  • Language
    TypeScript
  • Created almost 7 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Storyblok Nuxt module
Storyblok Logo

@storyblok/nuxt

Nuxt 3 module for the Storyblok, Headless CMS.


Storyblok JS Client npm

Follow @Storyblok
Follow @Storyblok

Live Demo

If you are in a hurry, check out our official live demo on Stackblitz.

🚀 Usage

Note: This module is for Nuxt 3. Check out @storyblok/nuxt-2 for Nuxt 2.

If you are first-time user of the Storyblok, read the Getting Started guide to get a project ready in less than 5 minutes.

Installation

Install @storyblok/nuxt:

npm install @storyblok/nuxt
# yarn add @storyblok/nuxt

Add following code to modules section of nuxt.config.js and replace the accessToken with API token from Storyblok space.

import { defineNuxtConfig } from "nuxt";

export default defineNuxtConfig({
  modules: [
    ["@storyblok/nuxt", { accessToken: "<your-access-token>" }]
    // ...
  ]
});

You can also use the storyblok config if you prefer:

import { defineNuxtConfig } from "nuxt";

export default defineNuxtConfig({
  modules: ["@storyblok/nuxt"],
  storyblok: {
    accessToken: "<your-access-token>"
  }
});

⚠️ 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. More info on storyblok-js-client docs.

Options

When you initialize the module, you can pass all @storyblok/vue options plus a bridge option explained in our JS SDK Storyblok bridge section and a enableSudoMode option to define your own plugin (see below).

If you want to use Storyblok inside nuxt-devtools you can use the option devtools, if enabled, make sure to have installed the @nuxt/devtools module and enable it on your nuxt config.

// Defaults
["@storyblok/nuxt", {
  {
    accessToken: "<your-access-token>",
    bridge: true,
    devtools: true,
    apiOptions: {}, // storyblok-js-client options
  }
}]

Define your own plugin

While the recommended approach covers most cases, there are specific instances where you may need to use the enableSudoMode option and disable our plugin, allowing you to incorporate your own.

// nuxt.config.ts
modules: [
  [
    "@storyblok/nuxt",
    {
      accessToken: "<your-access-token>",
      enableSudoMode: true
    }
  ]
];

To include additional functionalities in the SDK's apiOptions, such as custom cache methods, you can implement the following solution inside the plugins folder (autoimported):

// plugins/storyblok.js
import { StoryblokVue, apiPlugin } from "@storyblok/vue";

export default defineNuxtPlugin(({ vueApp }) => {
  vueApp.use(StoryblokVue, {
    accessToken: "<your-access-token>",
    apiOptions: {
      cache: {
        type: "custom",
        custom: {
          flush() {
            console.log("all right");
          }
        }
      }
    },
    use: [apiPlugin]
  });
});

Region parameter

Possible values:

  • eu (default): For spaces created in the EU
  • us: For spaces created in the US
  • cn: For spaces created in China

Full example for a space created in the US:

["@storyblok/nuxt", {
  {
    accessToken: "<your-access-token>",
    apiOptions: {
      region: "us"
    }
  }
}]

Note: For spaces created in the United States or China, the region parameter must be specified.

Getting started

1. Creating and linking your components to Storyblok Visual Editor

To link your Vue components to the equivalent one in your Storyblok space:

  • First, you need to load them globally adding them to the ~/storyblok directory. It's important to name them with Pascal case in your code ExampleComponent.vue and with a hyphen inside your Storyblok space example-component, so they will be imported automatically.

    Otherwise, you can set another directory and load them manually (for example, by using a Nuxt plugin).

    Take into account that if you name a component inside the storyblok folder the same as another in the components folder, it won't work properly. Tip: Keep the components in your Nuxt project with different names.

  • For each components, use the v-editable directive on its root element, passing the blok property that they receive:

<div v-editable="blok" / >
  • Finally, use <StoryblokComponent> which is available globally in the Nuxt app:
<StoryblokComponent :blok="blok" />

The blok is the actual blok data coming from Storblok's Content Delivery API.

2. Getting Storyblok Stories and listen to Visual Editor events

Composition API

The simplest way is by using the useAsyncStoryblok one-liner composable (it's autoimported) and passing as a first parameter a name of your content page from Storyblok (in this case, our content page name is vue, by default you get a content page named home):

If you want to know more about versioning { version: "draft" /* or "publish" */ } then go to the section Working with preview and/or production environments

<script setup>
  const story = await useAsyncStoryblok("vue", { version: "draft" });
</script>

<template>
  <StoryblokComponent v-if="story" :blok="story.content" />
</template>

Which is the short-hand equivalent to using useStoryblokApi inside useAsyncData and useStoryblokBridge functions separately:

<script setup>
  const story = ref(null);
  const storyblokApi = useStoryblokApi();
  const { data } = await useAsyncData(
    'vue',
    async () => await storyblokApi.get(`cdn/stories/vue`, {
    version: "draft"
  })
  );
  story.value = data.value.data.story;

  onMounted(() => {
    useStoryblokBridge(story.value.id, (evStory) => (story.value = evStory));
  });
</script>

<template>
  <StoryblokComponent v-if="story" :blok="story.content" />
</template>

Using useAsyncData SSR and SSG capabilities are enabled.

Rendering Rich Text

You can easily render rich text by using the renderRichText function that comes with @storyblok/nuxt and a Vue computed property:

<template>
  <div v-html="articleContent"></div>
</template>

<script setup>
  const props = defineProps({ blok: Object });
  const articleContent = computed(() =>
    renderRichText(props.blok.articleContent)
  );
</script>

You can also set a custom Schema and component resolver by passing the options as the second parameter of the renderRichText function:

<script setup>
  import cloneDeep from "clone-deep";

  const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
  // ... and edit the nodes and marks, or add your own.
  // Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/v4/source/schema.js

  const props = defineProps({ blok: Object });

  const articleContent = computed(() =>
    renderRichText(props.blok.articleContent, {
      schema: mySchema,
      resolver: (component, blok) => {
        switch (component) {
          case "my-custom-component":
            return `<div class="my-component-class">${blok.text}</div>`;
          default:
            return "Resolver not defined";
        }
      }
    })
  );
</script>

3. Working with preview and/or production environments

Remember that the bridge only works using version: 'draft' and the Preview Access Token.

For the production site, NOT used as a preview for content editors, version: 'published' and Public Access Token should be used.

If you're using production as a preview for marketeers and your public site, you will need a plugin to handle different .env variables, or versions using the Preview Access Token, checking if you are inside Storyblok or not. For example, something like if (window.location.search.includes(_storyblok_tk[token]=<YOUR_TOKEN>).

Check the official docs on how to access different content versions.

API

useAsyncStoryblok(slug, apiOptions, bridgeOptions)

(Recommended Option) Use useAsyncData and useState under the hood for generating SSR or SSG applications.

Check the available apiOptions (passed to storyblok-js-client) and bridgeOptions (passed to the Storyblok Bridge).

useStoryblok(slug, apiOptions, bridgeOptions)

It could be helpful to use useStoryblok instead of useAsyncStoryblok when we need to make client-side requests, for example, getting personalized data for a logged user.

Check the available apiOptions (passed to storyblok-js-client) and bridgeOptions (passed to the Storyblok Bridge).

useStoryblokApi()

Returns the instance of the storyblok-js-client.

useStoryblokBridge(storyId, callback, bridgeOptions)

Use this one-line function to cover the most common use case: updating the story when any kind of change happens on Storyblok Visual Editor.

The Storyblok JavaScript SDK Ecosystem

A visual representation of the Storyblok JavaScript SDK Ecosystem

🔗 Related Links

ℹ️ More Resources

Support

Contributing

Please see our contributing guidelines and our code of conduct. This project use semantic-release for generate new versions by using commit messages and we use the Angular Convention to naming the commits. Check this question about it in semantic-release FAQ.

More Repositories

1

storyblok

Info about Storyblok
309
star
2

nextjs-multilanguage-website

Nextjs Multilanguage Website
JavaScript
144
star
3

nuxtjs-multilanguage-website

Nuxtjs Multilanguage Website
Vue
137
star
4

storyblok-js-client

Universal JavaScript client for Storyblok's API
TypeScript
125
star
5

storyblok-astro

Astro SDK for Storyblok CMS
TypeScript
120
star
6

storyblok-react

React SDK for Storyblok CMS
TypeScript
108
star
7

nuxtdoc

A setup to build beautiful documentation with Nuxt and Storyblok deployed on Netlify for everyone
Vue
104
star
8

awesome-storyblok

A curated list of awesome things related to Storyblok CMS. 😏
101
star
9

storyblok-design-system

Design System for the Storyblok UI.
TypeScript
86
star
10

storyblok-svelte

Svelte SDK for Storyblok CMS
Svelte
83
star
11

storyblok-vue

Vue.js SDK for Storyblok CMS
TypeScript
82
star
12

react-next-boilerplate

Nextjs Storyblok boilerplate
JavaScript
61
star
13

vue-nuxt-boilerplate

Nuxt.js Storyblok boilerplate
Vue
52
star
14

storyblok-docs

A Nuxt.js setup to generate an intuitive, readable and collaborative API documentation with copy and paste able examples
Vue
52
star
15

gatsby-source-storyblok

Gatsby source plugin for building websites using the Storyblok headless CMS as a data source.
JavaScript
43
star
16

bootstrap-nuxt-demo

Storyblok Demo Website using Nuxt
Vue
39
star
17

gatsby-storyblok-boilerplate

Gatsby starter template with Storyblok's headless cms and true preview
JavaScript
37
star
18

storyblok-php-client

Storyblok - PHP Client
PHP
31
star
19

storyblok-js

JavaScript SDK to connect Storyblok with your favourite framework that we don't have an official SDK for.
TypeScript
29
star
20

nuxtwebsite

A simple Nuxt.js setup to create websites with blog feature using Storyblok as CMS and Netlify to deploy it.
Vue
28
star
21

storyblok-demo-default

Vue
26
star
22

storyblok-cli

The repo for our Storyblok CLI
JavaScript
25
star
23

field-plugin

Create and deploy Storyblok Field Plugin
TypeScript
25
star
24

nuxt-ultimate-tutorial

Vue
25
star
25

storyblok-ruby-client

Storyblok ruby client for easy access of the content delivery api
Ruby
24
star
26

gridsome-source-storyblok

Official Storyblok source plugin for Gridsome
JavaScript
23
star
27

vuejs-boilerplate

Storyblok - JavaScript - VueJS Boilerplate
JavaScript
22
star
28

talk-from-zero-to-nextjs-hero

JavaScript
22
star
29

field-type-examples

A collection of field-types by the community
TypeScript
21
star
30

sveltekit-ultimate-tutorial

Ultimate Tutorial Series for Integrating Storyblok with SvelteKit projects
Svelte
19
star
31

getting-started

An example hello world project build with Nuxt.js / Next.js for the Storyblok.
JavaScript
18
star
32

tool-examples

A collection of tools to use with Storyblok by the community
JavaScript
18
star
33

next.js-13-boilerplate

JavaScript
17
star
34

wordpress-importer

A simple script for migrating content from WordPress to Storyblok.
JavaScript
17
star
35

storyblok-vuestorefront

Demo project for integration of Vue Storefront with Storyblok
Vue
16
star
36

storyblok-svelte-boilerplate

Code of the tutorial: Add a headless CMS with live preview to Svelte and Sapper in 5 minutes
JavaScript
16
star
37

gatsbyjs-multilanguage-website

Multilanguage website built with GatsbyJS and Storyblok
JavaScript
15
star
38

nextjs-bigcommerce-starter

TypeScript
15
star
39

nuxtjs

A NuxtJS Website with Storyblok as content source.
Vue
13
star
40

storyblok-gridsome-boilerplate-moon

Storyblok's Gridsome Boilerplate (Moon-Theme)
Vue
13
star
41

nuxt-storyblok-snipcart

Nuxt.js Storyblok Boilerplate with Snipcart integration
Vue
13
star
42

storyblok-markdown-richtext

A html/markdown to Storyblok richtext converter
JavaScript
13
star
43

storyblok-translations

Repository to contribute translations for app.storyblok.com
13
star
44

jekyll

Add a headless CMS to Jekyll
Ruby
12
star
45

storyblok-fieldtype

Tool for creating custom fieldtypes for Storyblok with babel, browserify and hotreload
Vue
12
star
46

storyblok-express-boilerplate

Node.js Express boilerplate
CSS
11
star
47

storyblok-workflow-app

Example Storyblok app
Vue
11
star
48

storyblok-angular-example

TypeScript
10
star
49

next.js-ultimate-tutorial

JavaScript
10
star
50

rails-boilerplate

Ruby on Rails Storyblok Starter Boilerplate
Ruby
10
star
51

big-commerce-nuxt-starter

A starter shop template for Big Commerce with Storyblok
Vue
9
star
52

storyblok-integration-field-starter

Custom integration field type starter kit for Storyblok
Vue
9
star
53

storyblok-python-client

Storyblok API library client for python
Python
9
star
54

storyblok-create-demo

Set up a modern framework app with Storyblok by running one command.
TypeScript
9
star
55

storyblok-nextjs-multilanguage-isr-ssg-ssr

JavaScript
8
star
56

nuxt-auth

Storyblok authentification module for the Nuxt.js
JavaScript
8
star
57

talk-blazingly-fast-nuxtjs

Vue
8
star
58

storyblok-react-native-starter

A Starter Kit for Storyblok with React Native (Expo)
JavaScript
8
star
59

silex-boilerplate

Storyblok - PHP - Silex Boilerplate
PHP
8
star
60

space-tool-plugins

TypeScript
8
star
61

storyblok-nuxt-beta

JavaScript
8
star
62

storyblok-gridsome-boilerplate

Storyblok starter boilerplate for Gridsome
Vue
8
star
63

default-datasources

Storyblok - Default Datasources for Single Choice's
7
star
64

remix-ultimate-tutorial

JavaScript
7
star
65

storyblok-react-example

Example of the integration of Storyblok in React
JavaScript
7
star
66

storyblok.github.io

Client Side Integration of the headless Storyblok CMS directly in a github page.
HTML
6
star
67

storyblok-nuxt-2

JavaScript
6
star
68

storyblok-ruby-richtext-renderer

This is Storyblok's rendering service to render html from the data of the richtext field type.
Ruby
6
star
69

storyblok-php-richtext-renderer

Storyblok PHP Richtext Renderer converts the RichText field into HTML
PHP
6
star
70

nodejs-boilerplate

Storyblok - NodeJS - Boilerplate
JavaScript
5
star
71

nextjs-persisted-query-graphql-example

Example of Next.js + Apollo + Storyblok GraphQL api with persisted queries
JavaScript
5
star
72

mui

TypeScript
5
star
73

django-boilerplate

Storyblok - Python - Django Boilerplate
Python
5
star
74

lambda-form-submission

Serverless Form Submission via AWS Lambda and Storyblok as Storage
HTML
5
star
75

storyblok-csv-import-example

An example on how to read a local CSV file and push it into Storyblok using the Management API.
JavaScript
5
star
76

lambda-crawler

Lambda Crawler which extracts content from websites and saves it to Amazon DynamoDB
JavaScript
4
star
77

storyblok-commerce

Commerce Interface and Modules
Vue
4
star
78

lambda-crawler-aws-elasticsearch

Lambda Crawler which extracts content from websites and saves it to AWS Elasticsearch
JavaScript
4
star
79

storyblok-vue-starter

Vue
4
star
80

astro-ultimate-tutorial

Astro
4
star
81

starter-template

DEPRECATED - Storyblok - Start Template
CSS
4
star
82

quickstart

🚀 Quickstart for Rendering Service
Liquid
4
star
83

cloudflare-next-example

A Next.js template application on how to use cloudflare pages for hosting applications built on Storyblok
JavaScript
4
star
84

sinatra-boilerplate

Ruby/Sinatra Example of a Storyblok Integration
CSS
4
star
85

storyblok-graphql-react-apollo

Demo project showcasing Storyblok's GraphQL api
JavaScript
4
star
86

storyblok-tool-example

Example of a Storyblok toolbar app
Vue
4
star
87

city-theme

City Theme for Storyblok
CSS
4
star
88

serverless-custom-app-starter

A starter repository with Nuxt.js to create a custom application in Storyblok
JavaScript
3
star
89

tutorial-websites-scraper

JavaScript
3
star
90

storyblok-react-starter

JavaScript
3
star
91

storyblok-vuejs-website

A demo website using Storyblok with Vuejs
CSS
3
star
92

example-scripts

Collection of example node.js or scripts for imports, exports or other kind of tasks one would like to perform with Storyblok.
JavaScript
3
star
93

gulp-blok

Storyblok - Gulp Plugin
JavaScript
3
star
94

storyblok-sync-script

JavaScript
2
star
95

quickstart-templates

JavaScript
2
star
96

storyblok-fieldtype-react

Storyblok fieldtype plugin with React thanks to Vuera
HTML
2
star
97

nextjs-personalization-demo

nextjs-personalization-demo
JavaScript
2
star
98

gatsby-storyblok-boilerplate-v2

Gatsby (v2) starter template with Storyblok's headless cms and true preview
CSS
2
star
99

grunt-blok

Storyblok - Grunt Plugin
JavaScript
2
star
100

storyblok-app-example

JavaScript
2
star