Kick off your project with this starter kit, jam-packed with useful utils, templates and libraries to help get you going, faster π«
If you run into any issues, questions, or have a suggestion, hit up Josh Cawthorne on Slack.
Don't work at Lucky Duck? That's fine! Email josh instead.
- Designed to quickly create a project with Storyblok CMS integration
- Helpful templates and demo components to quickly understand the basics
- Includes some of our favourite libraries pre-installed
- Also includes some helpful utils that we've created while working on Gatsby/Storyblok sites
- Uses
styled-components
out of the box. - Supports quick clone and deploying with Netlify (see quick deploy section)
- Node (Recommended v8.2.0 or higher)
- Gatsby CLI
Clone with and host Netlify
Use the button below to quickly create a clone of this starter kit and host it on Netlify:
-
Create a Gatsby site.
Use the Gatsby CLI to create a new site, specifying the ld gatsby storyblok starter.
gatsby new my-site-name https://github.com/lucky-duck/ld-starter-gatsby-storyblok
-
Start developing.
Navigate into your new siteβs directory and start it up.
cd my-site-name/
gatsby develop
-
Open the source code and start editing
Your site is now running at
http://localhost:8000
.
A quick look at the top-level files and directories you'll see in a Gatsby project.
.
βββ node_modules
βββ src
βββββ assets
βββββββ fonts
βββββββ images
βββββββ svg
βββββββ videos
βββββ components
βββββββ storyblok
βββββββββ adapters
βββββ hooks
βββββ pages
βββββ templates
βββββ utils
βββ static
βββ .gitignore
βββ .prettierrc
βββ gatsby-config.js
βββ gatsby-node.js
βββ LICENSE
βββ package-lock.json
βββ package.json
βββ README.md
-
/node_modules
: This directory contains all of the modules of code that your project depends on (npm packages) are automatically installed. -
/src
: This directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser) such as your site header or a page template.src
is a convention for βsource codeβ. -
src/assets
: This directory will contain all of the static assets used on the site (anything not supplied by Storyblok), such as fonts, images and SVGs. -
src/components
: This directory will contain all your sites components, along with Storyblok adapters to connect your component up to Storyblok. -
src/hooks
: This directory will contain all of the custom hooks for your site. Included is a template file for creating Storyblok GraphQL queries. -
src/pages
: This directory will contain any static pages for your site, such as the 404 page, or the Storyblok editor page (included in project). -
src/templates
: This directory will contain any Storyblok page templates your site requires. It comes with a page template out of the box. -
src/utils
: This directory will contain any utils you need for the site. It comes with a host of helpful utils out of the box. -
.gitignore
: This file tells git which files it should not track / not maintain a version history for. -
.prettierrc
: This is a configuration file for Prettier. Prettier is a tool to help keep the formatting of your code consistent. -
gatsby-config.js
: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins youβd like to include, etc. (Check out the config docs for more detail). -
gatsby-node.js
: This file is where Gatsby expects to find any usage of the Gatsby Node APIs (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process. -
LICENSE
: This Gatsby starter is licensed under the 0BSD license. This means that you can see this file as a placeholder and replace it with your own license. -
package-lock.json
(Seepackage.json
below, first). This is an automatically generated file based on the exact versions of your npm dependencies that were installed for your project. (You wonβt change this file directly). -
package.json
: A manifest file for Node.js projects, which includes things like metadata (the projectβs name, author, etc). This manifest is how npm knows which packages to install for your project. -
README.md
: A text file containing useful reference information about your project.
Wrap your components, pages or Storyblok adapters with this to ensure they only render on the client-side. Useful for libraries that don't support SSR.
import React from "react";
import ClientOnly from "../utils/clientOnly";
function MyCoolComponent() {
return (
<ClientOnly>
<div>I'll only render on the client side. Neat, huh?</div>
</ClientOnly>
);
}
export default MyCoolComponent;
The clue's in the name, this holds constants for you.
Stands for Media Queries
. Incredibly useful component that allows you to quickly create uniform responsive designs with styled-components
. Note: Breakpoints are controlled in contstants.js
.
import React from "react";
import styled, {css} from "styled-components"
import mq from "../utils/mq";
const ComponentContainer = styled.div`
height: 400px;
width: 400px;
font-size: 18px;
${mq.desktopSmall(css`
height: 350px;
width: 350px;
font-size: 16px;
`)};
${mq.tablet(css`
height: 300px;
width: 300px;
font-size: 14px;
`)};
${mq.mobile(css`
height: 200px;
width: 200px;
font-size: 12px;
`)};
${mq.mobileSmall(css`
height: 100px;
width: 100px;
font-size: 10px;
`)};
`;
function MyCoolComponent() {
return (
<ComponentContainer>
Check out Mr. Responsive
</ComponentContainer>
);
}
export default MyCoolComponent;
Used to parse between the different types of links Storyblok return.
import React from "react";
import parseStoryblokLink from "../utils/parse-storyblok-link";
function MyCoolComponent({link}) {
return (
<a href={parseStoryblokLink(link)}>Link here!</a>
);
}
export default MyCoolComponent;
Used to lock the page in place. Intended for use with pop-up overlays or full-screen menus.
import React, {useState} from "react";
import { scrollLocker } from "../utils/scrollLocker";
function MyCoolComponent() {
const [locked, setLocked] = useState(false)
function toggleLock() {
if(locked) {
scrollLocker.unlock();
setLocked(false)
} else {
scrollLocker.lock();
setLocked(true)
}
}
}
return (
<button onClick={() => toggleLock()}>Toggle Lock</button>
);
}
export default MyCoolComponent;
Used to provide the component with information on its location on the site. Supports SSR.
import React from "react";
import withLocation from "../utils/withLocation";
function MyCoolComponent({location}) {
return (
<div>My Cool Component here, checking in from {location.pathname}!</div>
);
}
export default withLocation(MyCoolComponent);
Used to convert Storyblok image repsonses into a gatsby-image
compatible format. Can be used for either a fixed image or a fluid image. Works well with the included lazyImage.js
component.
Note: This is a forked version of Bejama's gatsby-storyblok-image. It's forked as we've found the version available on NPM doesn't currently work properly.
import React from "react";
import LazyImage from "../components/lazyImage";
import { getFixedGatsbyImage } from "../utils/gatsby-storyblok-image";
function MyCoolComponent({ image }) {
const fixedImage = getFixedGatsbyImage(image, {
width: 900
})
return (
<div>
<LazyImage fixed={fixedProps} alt={"A fixed image, woo!"}/>
</div>
)
}
export default MyCoolComponent
import React from "react";
import LazyImage from "../components/lazyImage";
import { getFluidGatsbyImage } from "../utils/gatsby-storyblok-image";
function MyCoolComponent({ image }) {
return (
<div>
<LazyImage fluid={getFluidGatsbyImage(image)} alt={"A fluid image, woo!"}/>
</div>
)
}
export default MyCoolComponent
Some of our favourite libraries and plugins come installed out of the box with the starter kit. See below for some brief info on each library and some tailor-made examples of usage.
Provides a simple way to format date and times.
import React from "react";
import { format } from 'date-fns'
function MyCoolComponent({publishDate}) {
return (
<div>Article published: {format(new Date(publishDate), "do LLLL yyyy")}</div>
)
}
export default MyCoolComponent
An awesome animation library that works perfectly with styled-components
to create 60fps animations.
import React, {useState} from "react";
import styled from "styled-components"
import { motion } from 'framer-motion'
const AnimatedTitle = styled(motion.div)`
font-size: 18px;
color: red;
`;
const TitleAnim = {
hidden: { opacity: 0, y: 10 },
show: {
opacity: 1,
y: 0,
transition: {
delay: 0.3,
transition: 0.5,
ease: "easeOut"
}
},
};
function MyCoolComponent() {
const [doAnimate, setDoAnimate] = useState(false);
return (
<div>
<Title
variants={TitleAnim}
initial="hidden"
animate={doAnimate ? "show" : "hidden"}
>
Animated magic!
</Title>
<button onClick={() => setDoAnimate(!doAnimate)}>Toggle animation</button>
</div>
)
}
export default MyCoolComponent
A useful library that detects if a component is in view.
import React, {useState} from "react";
import useInView from "react-cool-inview";
function MyCoolComponent() {
const { ref, inView } = useInView();
return (
<div ref={ref}>
I'm {inView ? "In view!" : "Not in view"}
</div>
)
}
export default MyCoolComponent
A useful library that detects when a user clicks outside of a component. Useful for tooptips, popups and overlays.
import React, {useState} from "react";
import styled from "styled-components"
import useOnclickOutside from "react-cool-onclickoutside";
const OuterContainer = styled.div`
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
position: relative;
`;
const PopupContainer = styled.div`
height: 500px;
width: 500px;
background-color: blue;
z-index: 2;
position: absolute;
top: 0;
left: 0;
`;
function MyCoolComponent() {
const [active, setActive] = useState(false);
const ref = useOnclickOutside(() => {
setActive(false);
});
return (
<OuterContainer ref={ref}>
{active && (
<PopupContainer>
Popup!
</PopupContainer>
)}
<button onClick={() => setActive(true)}>Display popup</button>
</OuterContainer>
)
}
export default MyCoolComponent
- Gatsby Image
- Gatsby Plugin Catch Links
- Gatsby Plugin Google Fonts
- Gatsby Plugin Manifest
- Gatsby Plugin React Helmet
- Gatsby Plugin React SVG
- Gatsby Plugin SASS
- Gatsby Plugin Sharp
- Gatsby Plugin Sitemap
- Gatsby Plygin Styled Components
- Gatsby Source Filesystem
- Gatsby Source Storyblok
- Gatsby Transformer Sharp