https://www.gatsbyjs.com/starters/gatsbyjs/gatsby-starter-hello-world
- You can pass multiple properties to a component by just using the spread operator like {...project}
- You can conditionally pass classes like this -> className={isOpen ? "social-links sidebar-links" : null}
- src
- assets
- scss
- images
- components
- constants
- templates
- pages
- assets
- npm install bootstrap
- create src/assets/scss/main.scss
- create src/assets/scss/vendors/_bootstrap.scss
- https://getbootstrap.com/docs/5.1/customize/sass/ use this site to copy and paste the template. You can replace "../node_modules/" with "~" as it means the same thing
- Import your other partials into this file that effect bootstrap
- Import bootstrap into "gatsby-browser.js"
- pages should be lowercased to match slug
- components should be sentence cased.
- In the components folder create a "Layout.js" This file accepts children prop.
- Create a Header.js and Footer.js to wrap site and import it into Layout.js
- Another approach to this is simpler in the long run because it programmatically wraps all the pages called gatsby browser api.
- Create folder "src/assets/images"
- Install gatsby-plugin-image
- Use StaticImage if images are used exactly the same and don't change. If the image is dynamic or being imported through props use GatsbyImage
- To apply classes to image itself use "imgClassName" prop
- Static images you pass "src" prop
- Gatsby image pass "image" prop
- Static images when you pass the src prop you can't pass it in a dynamic value with curlys you need to just type out the path to where the image is located.
- Sometimes it doesnt make sense to use StaticImage bc if you're using an svg its already small file size and importing it the normal react way is easier.
- use activeClassName prop and pass it a class value
All the wrapper elements on the page, html, wrapper etc need to be display flex with 100% height. The footer element can then user margin top auto to have it float to the bottom
https://www.gatsbyjs.com/plugins/gatsby-source-contentful
- .env.development
- .env.production
https://www.gatsbyjs.com/docs/creating-and-modifying-pages/
Either option for creating pages isnt necesarrily better than one another its good to know both.
Notes: Faster, less control
- Create a file within the pages folder and it must be named the same name that is in graphql but remove the word "all" from the name. This file will be used as the template to create new pages dynamically. Then you can choose which field you want gatsby to base the slug off of. For instance if you choose the title, gatsby will run a query behind the scenes for recipes and create pages for all recipes and base the slug off title.
- When creating the file you need to wrap the file name in curlies like so: {ContentfulRecipe.title}.js
- In order to do a nested structure you need to create folders inside the pages folder. For instance "/pages/projects/{ContentfulRecipe.title}.js"
- Remember to import graphql from gatsby!
- Aside from getting data back from query variables. You automatically get back title of page from PageContext property on the props. I'm not sure yet if I need to use this.
Notes: More complicated, more control
- Create a template folder in src
- Create a file called gatsby-node.js and place it at root of site.
- Everytime you do something in gatsby node you have to restart server
- When you create a query you need to wrap it in parenthesis.
- First thing we do is execute a query and store the data we get back into a variable.
- Then we access the data and drill down to the specific property we want to iterate over.
- We perform a for each loop and the use the createPage action and pass it properties of path, component, and context. This will then generate pages for each of these items.
- We need to be able to access component path using
- const path = require("path")
- Make sure pages are set to have unique values
- Consider if the site values will be constantly changing sometimes its better to not put every little thing into the headless CMS and instead manage it locally within the project instead.
Query variables allow you to pass in variables dynamically into your queries. We need this for create dynamic templates because when you make a query in your page for the data we need to pass in the title as a query variable to perform our second query. This is what brings in the rest of the page data.
Query accepts in different variables into the query. You must specify the type that the variable is. For instance "String". Then you need to set up a filter that filters for that items that equal that specific variable.
export const query = graphql`
query getProject($title: String) {
strapiProject(title: { eq: $title }) {
title
description
}
}
`
{
"title": "PHP"
}
- Use Formspree
- Install Gatsby plugin react helmet
- Create a component called SEO and pass it the appropriate prop values
Imagine youre in a scenario where you make a content update in your headless cms. The build process wont trigger automatically, you will have to go into either netlify or your local app and redeploy with new content.
- Go to build hooks in settings netlify, copy the value it gives you
- Go to contentful and paste in the url into the webhooks section
- Now when any changes are made a post request is sent to netlify to rebuild the app.
- Place in static folder
In order to wrap your entire site with layout component programmatically
- Create gatsby-browser.js
- https://www.gatsbyjs.com/docs/reference/config-files/gatsby-browser/ follows steps for wrapPageElement.
- Create a gatsby-ssr.js file and place the same content from gatsby browser in it.
- You can create constants for instance an array of objects to build out navbar and then just import that file into other parts of your application.
- You can also place components inside of an object when you loop through something. For instance i could have an array of objects. On each item in the array i have a components that is a property on there.
Control the height of the image using its width in css. If you explicitly set a height then you might face clipping issues.
If a value is not available within a component. For instance passing a title you can inside the return just do {title || "Default title"}
-
Make sure to get latest of strapi otherwise it wont work
-
Strapi works differently from contentful in that the server runs on your local machine and then you have to connect your gatsby application to that local server.
-
Strapi has 3 different data structure types (Collection types, Single type, component)
- Collection type: You would use this for creating multiple entries of the same data structure for instance all of your recipes.
- Single type: You would use this if the data structure was only used once. Maybe you have a very specific page, such as the home page.
- Component type: This is a reusable data structure that can be imported into either a collection type or a single type. For lets say I have a banner component I know i will always need for different collection types. Instead of me rewriting those fields over and over again i can just import the component data structure so that it is reusable.
-
Anytime you create a new content type you need to go into settings > roles (user permissions) > public > set content type to find, find one
-
GatsbyImage needs to be passed image={getImage(image.localFile)}
-
Collection types / Single Types within the gatsby-config need to be updated to match the API:id found inside of strapi.
{ resolve:
gatsby-source-strapi
, options: { apiURL:http://localhost:1337
, queryLimit: 1000, // Defaults to 100 collectionTypes: [job
,project
], singleTypes: [about
] }, }, -
For SVG images in strapi use
image { id localFile { publicURL } }
- Create a state and set the value to 0
- iterate over the items in the array and when the tab is clicked it updates the state to the value associated within the array and shows the content.
- In order to do dynamic classes use the curlies on the class and check the value of the state and if it matches then render the correct classes like so: className={index === value ? "active-btn job-btn" : "job-btn"}