19
loading...
This website collects cookies to deliver better user experience
Storyblok is the only Headless Content Management System with a Visual Editor. It provides developers with all the flexibility they need to build reliable and fast websites, while giving content creators with no coding skills the ability to edit content independently of the developer.
One of the greatest feature that i love in NextJS routers that makes the navigation seamless.
Node, yarn (or npm) and npx installed.
An account on Storyblok to manage content, if you don't have one already sign up here sign up for a free account here 🚀.
A new Storyblok space, a space in storyblok is a content repository, a place to keep all the content related to one project.
>>> npx create-next-app final
>>> yarn create next-app final
>>> cd final
>>> npm install storyblok-js-client @storyblok/storyblok-editable axios
>>> yarn add storyblok-js-client @storyblok/storyblok-editable axios
>>> npm run dev
>>> yarn dev
import DynamicComponent from 'src/components/DynamicComponent'
import Storyblok from 'src/lib/storyblok'
Remember to add the correct preview token key, observer white spaces and letters casing.
import Head from "next/head"
import styles from "../styles/Home.module.css"
// The Storyblok Client
import Storyblok from "../lib/storyblok"
export default function Home(props) {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<header>
<h1>
{ props.story ? props.story.name : 'My Site' }
</h1>
</header>
<main>
</main>
</div>
)
}
export async function getStaticProps({ preview = false }) {
// home is the default slug for the homepage in Storyblok
let slug = "home";
// load the published content outside of the preview mode
let sbParams = {
version: "draft", // or 'published'
};
if (preview) {
// load the draft version inside of the preview mode
sbParams.version = "draft";
sbParams.cv = Date.now();
}
let { data } = await Storyblok.get(`cdn/stories/${slug}`, sbParams);
return {
props: {
story: data ? data.story : null,
preview,
},
revalidate: 3600, // revalidate every hour
};
}
import Teaser from "./Teaser";
import Grid from "./Grid";
import Feature from "./Feature";
import Page from "./Page";
// resolve Storyblok components to Next.js components
const Components = {
teaser: Teaser,
grid: Grid,
feature: Feature,
page: Page,
};
const DynamicComponent = ({ blok }) => {
// check if component is defined above
if (typeof Components[blok.component] !== "undefined") {
const Component = Components[blok.component];
return <Component blok={blok} key={blok._uid} />;
}
// fallback if the component doesn't exist
return (
<p>
The component <strong>{blok.component}</strong> has not been created yet.
</p>
);
};
export default DynamicComponent;
import Head from "next/head"
import styles from "../styles/Home.module.css"
// The Storyblok Client
import Storyblok from "../lib/storyblok"
import DynamicComponent from '../components/DynamicComponent'
export default function Home(props) {
const story = props.story
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<header>
<h1>
{ story ? story.name : 'My Site' }
</h1>
</header>
<DynamicComponent blok={story.content} />
</div>
)
}
export async function getStaticProps({ preview = false }) {
// home is the default slug for the homepage in Storyblok
let slug = "home";
// load the published content outside of the preview mode
let sbParams = {
version: "published", // or 'draft'
};
if (preview) {
// load the draft version inside of the preview mode
sbParams.version = "draft";
sbParams.cv = Date.now();
}
let { data } = await Storyblok.get(`cdn/stories/${slug}`, sbParams);
return {
props: {
story: data ? data.story : null,
preview,
},
revalidate: 3600, // revalidate every hour
};
}
A headless CMS is a content management system that provides a way to author content, but instead of having your content coupled to a particular output (like web page rendering), it provides your content as data over an API.
Next.js is a React framework that provides a lot of useful features out of the box. One of these powerful features is API routes, which allows you to make an API/backend entirely within your Next.js application.
Storyblok is an api-based/headless CMS, with a Visual Editor. It provides developers with all the flexibility they need to build reliable and fast websites, while giving content creators with no coding skills the ability to edit content independently of the developer