From a1888f4ef7c3d31052c4123d1415b918a4ff00f3 Mon Sep 17 00:00:00 2001 From: Arisa Fukuzaki <25793187+schabibi1@users.noreply.github.com> Date: Wed, 2 Feb 2022 19:08:22 +0100 Subject: [PATCH] fix: remove Fragments and switch statement from File System Route API approach on README --- README.md | 69 +++++++++++++++---------------------------------------- 1 file changed, 19 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index acf395adc..8abd93642 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ import React from 'react' import { graphql } from 'gatsby' export default function StoryblokEntry ({ data }) { - const story = data.storyblokEntry + let story = data.storyblokEntry return (
{story.name}
@@ -152,14 +152,14 @@ import React from 'react' import { graphql } from 'gatsby' export default function StoryblokEntry({ data }) { - const story = data.storyblokEntry + let story = data.storyblokEntry return
{story.name}
} export const query = graphql` - query ($slug: String!) { - storyblokEntry(slug: { eq: $slug }) { + query ($full_slug: String!) { + storyblokEntry(full_slug: { eq: $full_slug }) { id name full_slug @@ -170,63 +170,33 @@ export const query = graphql` ## Rendering Storyblok content -To source Storyblok's content add `content` to your GraphQL query. By using a switch statement you can make decisions about how to render each of the bloks. +To source Storyblok's content add `content` to your GraphQL query. By importing `DynamicComponent`, you can render components dynamically. `sbEditable` function lets you to make your components editable in [storyblok.com](https://www.storyblok.com/) + +For more info regarding `sbEditable` function see the @storyblok/storyblok-editable README: [@storyblok/storyblok-editable](https://github.com/storyblok/storyblok-editable) ```js -import React, { Fragment } from 'react' +import React from 'react' import { graphql } from 'gatsby' - -const getBlok = (blok) => { - const { component } = blok - - switch (component) { - case 'teaser': - return ( - -

{blok.headline}

-
{JSON.stringify(blok, null, 2)}
-
- ) - - case 'grid': - return ( - - {blok.columns.map((column, index) => { - return
{JSON.stringify(column, null, 2)}
- })} -
- ) - - case 'feature': - return ( - -

{blok.name}

-
{JSON.stringify(blok, null, 2)}
-
- ) - - default: - return null - } -} +import { sbEditable } from "@storyblok/storyblok-editable" +import DynamicComponent from "../components/dynamicComponent" export default function StoryblokEntry({ data }) { - const story = data.storyblokEntry - const { title, body } = JSON.parse(story.content) + let story = data.storyblokEntry + + const components = story.content.body.map(blok => { + return () + }) return ( -
-

{title}

- {body.map((blok, index) => { - return {getBlok(blok)} - })} +
+ {components}
) } export const query = graphql` - query ($slug: String!) { - storyblokEntry(slug: { eq: $slug }) { + query ($full_slug: String!) { + storyblokEntry(full_slug: { eq: $full_slug }) { id name full_slug @@ -236,7 +206,6 @@ export const query = graphql` ` ``` - ## The options object in details ```js