Last active
June 3, 2019 14:39
-
-
Save onefriendaday/ac9446fcc50b2fb61979ef7b529e61f5 to your computer and use it in GitHub Desktop.
Get storyblok links in gatsby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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