Skip to content

Instantly share code, notes, and snippets.

@onefriendaday
Last active June 3, 2019 14:39
Show Gist options
  • Save onefriendaday/ac9446fcc50b2fb61979ef7b529e61f5 to your computer and use it in GitHub Desktop.
Save onefriendaday/ac9446fcc50b2fb61979ef7b529e61f5 to your computer and use it in GitHub Desktop.
Get storyblok links in gatsby
import React from 'react'
import Components from './components.js';
import { StaticQuery, graphql } from "gatsby"
class Navi extends React.Component {
constructor(props) {
super(props)
const nest = (items, id = 0) => items
.filter(item => item.parent_id === id)
.map(item => ({ ...item, children: nest(items, item.id) }))
let tree = nest(props.data.links.edges)
this.state = {navi: tree}
}
render() {
return (<div></div>)
}
}
export default props => (
<StaticQuery
query={graphql`{
links: allStoryblokLink {
edges {
node {
id
slug
name
is_folder
parent_id
published
position
uuid
is_startpage
}
}
}
}`}
render={data => <Navi data={data} {...props} />}
/>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment