Git Product home page Git Product logo

gatsby-intermediate's Introduction

Intermediate/Advanced Gatsby

A Frontend Masters workshop.

Setup

Clone this repo locally:

git clone [email protected]:jlengstorf/gatsby-intermediate.git

Make sure you’re on the start branch:

git checkout start

Part I: Create a Docs Theme

  • Set up Yarn workspaces
  • Create a site for theme dev
  • Create the packages/gatsby-theme-docs folder
    • yarn init
    • Create index.js (// boop)
  • Install the docs theme
    • yarn workspace negronis add "gatsby-theme-docs@*" (quotes for Windows)
    • Add default config to gatsby-config.js
  • Make sure the content directory exists (onPreBootstrap)
    • yarn add mkdirp
    • Validate that this works by starting the theme-dev site in develop mode
  • Define the docs data type (createSchemaCustomization)
    • Show this data type in GraphiQL
    • Run a query to show it returning an empty array
  • Create docs nodes from MDX files (onCreateNode)
    • Only get the docs, not all MDX files
  • Define a custom resolver to get the MDX body content (createResolvers)
    • Write a passthrough resolver (hat tip to @christopherbiscardi for the original work to figure out how these work)
  • Create the required React components to display a docs page
    • Create a Layout component (src/components/layout.js)
    • Create a DocsPage component (src/components/docs-page.js)
      • Set up MDXRenderer
    • Create a DocsPageTemplate component (src/templates/docs-page-template.js)
      • Write the GraphQL query in GraphiQL first
      • Use the Code Exporter to get started
  • Create pages from the docs nodes (createPages)
    • Write a GraphQL query in GraphiQL first
  • Add Theme UI
    • yarn workspace gatsby-theme-docs add theme-ui gatsby-plugin-theme-ui @emotion/core @mdx-js/react
    • Update gatsby-config.js
    • Add a theme file (src/gatsby-plugin-theme-ui/index.js)
    • Update Layout to use Theme UI
    • Update DocsPage to use Theme UI
  • Create a TableOfContents component (src/components/table-of-contents.js)
    • Write a useDocs hook (src/hooks/use-docs.js)
  • Add support for syntax highlighted code
    • yarn workspace gatsby-theme-docs add mdx-utils prism-react-renderer
    • Create a Code component (src/components/code.js)
    • Shadow the MDX components in Theme UI to use Code (src/gatsby-plugin-theme-ui/components.js)
    • Insert a fenced code block (use src/components/docs-page.js) into docs/index.mdx
  • Add support for live editing code blocks
    • yarn workspace gatsby-theme-docs add react-live
    • Add a scope file for easy shadowing
    • Update Code to use react-live

Part II: Honkify

  • Install the docs theme
    • yarn workspace negronis add "gatsby-theme-docs@*" (quotes for Windows)
    • Update gatsby-config.js with custom basePath and disable theme MDX
    • The existing theme from the Honkify site will automatically override the docs Theme UI config
    • Shadow the Layout component
  • Create a Button component (src/components/button.js)
    • Shadow the scope.js file to add Button
    • Add the Button component in a live-editable code block in the docs
    • Show it interacting with Honkify

Part III: Build a Negroni Fan Site

  • Add Theme UI
    • yarn workspace negronis add theme-ui gatsby-plugin-theme-ui @emotion/core @mdx-js/react
    • Add a preset (yarn workspace negronis add @theme-ui/presets)
    • Create a theme file (src/gatsby-plugin-theme-ui/index.js)
  • Create a Layout component (src/components/layout.js)
    • Update src/pages/index.js to use the Layout
    • Update src/pages/history.js to use the Layout
    • Add styles for a hollow button
  • Add image support
    • yarn workspace negronis add gatsby-source-filesystem gatsby-transformer-cloudinary gatsby-image
    • Get credentials from Cloudinary
    • Add env vars to .env.development
    • Load env vars in gatsby-config.js
    • Add plugin config to gatsby-config.js
    • Query for images
      • Show this in GraphiQL first
    • Update src/pages/index.js to display an image
      • Quick aside to show transformations with Cloudinary because they’re dope
    • Update src/pages/history.js to display an image
  • Install the docs theme
    • Recipes are a kind of documentation! :)
    • yarn workspace negronis add "gatsby-theme-docs@*" (quotes for Windows)
    • Add modified config to gatsby-config.js
      • basePath: '/recipes'
      • contentPath: 'content/recipes'
  • Update src/pages/index.js to link to /recipes
    • Add styles for a primary button
  • Shadow the Layout component in the docs theme
  • Shadow the TableOfContents component in the docs theme
  • Install the events theme
    • yarn workspace negronis add @jlengstorf/gatsby-theme-events
    • This was built as part of this free course on authoring Gatsby themes: https://egghead.io/courses/gatsby-theme-authoring
    • Update gatsby-config.js with a custom basePath and contentPath
    • Shadow the Layout component in the events theme

Part IV: Rick & Morty Lookup App

  • Add support for client-side GraphQL queries
    • yarn workspace lookup add gatsby-plugin-apollo @apollo/react-common @apollo/react-hooks graphql-tag
    • Update gatsby-config.js to use gatsby-plugin-apollo
    • Point Apollo at the Rick & Morty API (https://rickandmortyapi.com/graphql/)
  • Create pages
    • src/pages/index.js
    • src/pages/search.js
  • Add support for client-only routes
    • gatsby-node.js (onCreatePage/matchPath)
    • Add a redirect netlify.toml
    • Test using netlify dev
  • Create a search form
    • React hooks
    • Programmatic navigation
    • Add a submit handler
  • Create a results component
    • Query based on the current search string
  • Figure out the search string from state or URL
    • location

gatsby-intermediate's People

Contributors

1marc avatar jlengstorf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gatsby-intermediate's Issues

Theme UI and MDX Rendering

So, another issue I found out today and here I will leave my dependencies:

  "dependencies": {
    "@emotion/core": "^10.0.27",
    "@mdx-js/mdx": "^1.5.5",
    "@mdx-js/react": "^1.5.5",
    "gatsby-plugin-mdx": "^1.0.73",
    "gatsby-plugin-theme-ui": "^0.3.0",
    "gatsby-source-filesystem": "^2.1.48",
    "mdx-utils": "^0.2.0",
    "mkdirp": "^1.0.3",
    "prism-react-renderer": "^1.0.2",
    "react-live": "^2.2.2",
    "theme-ui": "^0.3.1"
  }

The dependencies used by you:

"dependencies": {
    "@emotion/core": "^10.0.21",
    "@mdx-js/mdx": "^1.5.1",
    "@mdx-js/react": "^1.5.1",
    "gatsby-plugin-mdx": "^1.0.52",
    "gatsby-plugin-theme-ui": "^0.2.43",
    "gatsby-source-filesystem": "^2.1.33",
    "mdx-utils": "^0.2.0",
    "mkdirp": "^0.5.1",
    "prism-react-renderer": "^1.0.2",
    "react-live": "^2.2.1",
    "theme-ui": "^0.2.44"
  }

There is one of these that breaks, or maybe the combination, been trying without success to actually pinpoint what it is, but at some point, theme and components stop being overriden, so my main issue was being able to use the Code component on mdx.

I guess for now I need to downgrade my dependencies to what you are using

Creating MDX Page shows error

After setting up templates to create mdx page, I get 404 error onhomepage. I have cloned the repo as well and switched to create pages from nodes commit and I still get the same error.

Homepage state
https://imgur.com/W59kGUm

It shows it has created a page but the url is invalid i.e. '/'
https://imgur.com/VGc9rOg

In graphql playground if I query for docs page the path is shown as \ not
https://imgur.com/6Gyd6oC

Repo is giving that error. I have no idea how to move forward?

Gatsby Version is mismatched

Issue

When going through initial project setup, running yarn workspace theme-dev add gatsby react react-dom installs version 2.24.49 of gatsby, the version in the honkify package.json is 2.15.28. This is causing a mismatch in the versions of graphql.

When attempting to run yarn workspace theme-dev develop it results in an error

Duplicate "graphql" modules cannot be used at the same time since different versions may have different capabilities and behavior. The data from one version used in the function from another could produce confusing and spurious results.

I rolled back the version of gatsby installed in theme-dev to 2.15.28 which allowed both graphql packages to match with version 14.5.8.

I am assuming that each site is supposed to have its own node_modules.

Querying With Apollo Client - error message

Hi Jason,

Getting an error message when trying to run the look up site once we add results component:-

`Generating SSR bundle failed

Can't resolve '@apollo/client' in ...node_modules/gatsby-plugin-apollo'`

Has there been some changes to apollo? What package versions were you using?

`"dependencies": {

"@apollo/react-common": "^3.1.4",
"@apollo/react-hooks": "^3.1.5",
"gatsby": "^2.21.0",
"gatsby-plugin-apollo": "^3.0.1",
"graphql-tag": "^2.10.3",
"react": "^16.13.1",
"react-dom": "^16.13.1"

}`

Cannot convert to InputType the following value: undefined'

Hi @jlengstorf ,
I followed each lesson till "layout-component" but I got stuck trying to generate mdx nodes with yarn workspace theme-dev develop.

I got the following error:

Missing onError handler for invocation 'building-schema', error was 'Error: TypeError[.excerpt]: TypeError[.excerpt.truncate]: Cannot convert to InputType the following value: undefined'. 
Stacktrace was 'Error: TypeError[.excerpt]: TypeError[.excerpt.truncate]: Cannot convert to InputType the following value: undefined

You can find a the affected code in the forked repo in the branch "layout-component" in this commit.
Thanks in advance for your time and support. ☺️

Breaking when upgrading react version

I was going along the project and everything worked fine until (I believe) the schema customization commit, there I started getting a hooks error whenever I started the project, I compared the code on the repo with mine and the only difference was in the versions, so my first attempt was to downgrade the react and react-dom versions on the theme-dev site and it started working again, so, on the course versions 16.10.2 were used, when I installed react I got versions 16.2.0, guess something breaks at that point?

Starting gatsby develop results in error

In the beginning of Part I when I run yarn workspace theme-dev develop to check that everything is OK, I get the following error:

yarn workspace v1.19.1
yarn run v1.19.1
$ gatsby develop
The above error occurred in the <StoreStateProvider> component:
    in StoreStateProvider
    in App

React will try to recreate this component tree from scratch using the error boundary you provided, App.
Warning: App: Error boundaries should implement getDerivedStateFromError(). In that method, return a state update to display an error message or fallback UI.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: /Users/tlaukka/.nvm/versions/node/v10.16.0/bin/node
Arguments: /usr/local/Cellar/yarn/1.19.1/libexec/lib/cli.js develop
Directory: /Users/tlaukka/Work/gatsby-intermediate/sites/theme-dev
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.