GithubHelp home page GithubHelp logo

gatsby-ewebdesigns's Introduction

Playing around with Gatsby

View demo

Adding gatsby-source-filesystem (plugin)

Gives graphQL an addition 2 new queries

  1. file()
  2. allFile())
npm install --save gatsby-source-filesystem

Adding file path for a query (file path for images folder)

   {
       resolve: 'gatsby-source-filesystem',
      options: {
        path: `${__dirname}/src/images`,
        name: `images`,
   },
query {
  allFile(filter: { sourceInstanceName: {eq: "images"} }) {
    edges {
      node {
        relativePath
      }
    }
  }
}

import { useStaticQuery, graphql } from 'gatsby'

import Img from 'gatsby-image'

const data = useStaticQuery(graphql`
  {
    pexels: file(relativePath: { eq: "index/pexels.jpeg" }) {
      childImageSharp {
        fluid(maxWidth: 1980) {
          ...GatsbyImageSharpFluid
        }
      }
    }
  }
`)
console.log(data)
const image = data.pexels
// use image
<Img fluid={image.childImageSharp.fluid} />

Parser for MD files

npm install --save gatsby-transformer-remark

Gives graphQL an addition 2 new queries

  1. markdownRemark() - fetch individual post
  2. allMarkdownRemark() fetching list of posts

Adding images

npm install --save gatsby-remark-images gatsby-plugin-sharp

Contentful CMS

graphQL query

query {
  allContentfulBlogPost (
    sort:{
      fields: publishedDate,
      order: DESC
    }
  ) {
    edges {
      node {
        title
        slug
        publishedDate(formatString: "MMMM Do, YYYY")
        body {
          json
        }
      }
    }
  }
}

Parse the json from contentful

npm i @contentful/rich-text-react-renderer

add import to component

import { documentToReactComponents } from '@contentful/rich-text-react-renderer'

SEO

SSR data added to components, e.g. title, meta attributes, etc.

npm install --save gatsby-plugin-react-helmet react-helmet

gatsby-ewebdesigns's People

Contributors

alvics avatar

Watchers

James Cloos avatar

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.