Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEO and Social sharing cards tutorial - Unused variable and wrong propTypes #22425

Closed
soobing opened this issue Mar 20, 2020 · 0 comments · Fixed by #22426
Closed

SEO and Social sharing cards tutorial - Unused variable and wrong propTypes #22425

soobing opened this issue Mar 20, 2020 · 0 comments · Fixed by #22426
Labels
type: documentation An issue or pull request for improving or updating Gatsby's documentation

Comments

@soobing
Copy link
Contributor

soobing commented Mar 20, 2020

Summary

I am trying to apply seo and social sharing cards tutorial to my project.

While developing this tutorial to my project, I found unused variable even declared and wrong propTypes.

Some recommended topics to cover:

  • const { previous, next } = this.props.pageContext should be erased.
import React from "react"
import { Link, graphql } from "gatsby"

import Bio from "../components/bio"
import Layout from "../components/layout"
import SEO from "../components/seo"
import { rhythm, scale } from "../utils/typography"

class BlogPostTemplate extends React.Component {
  render() {
    const post = this.props.data.markdownRemark
    const siteTitle = this.props.data.site.siteMetadata.title
    const { previous, next } = this.props.pageContext
    const image = post.frontmatter.image
      ? post.frontmatter.image.childImageSharp.resize
      : null

    return (
      <Layout location={this.props.location} title={siteTitle}>
        <SEO
          title={post.frontmatter.title}
          description={post.frontmatter.description || post.excerpt}
          image={image}
          pathname={this.props.location.pathname}
        />
        <h1>{post.frontmatter.title}</h1>
        <div dangerouslySetInnerHTML={{ __html: post.html }} />
      </Layout>
    )
  }
}

export default BlogPostTemplate

export const pageQuery = graphql`
  query BlogPostBySlug($slug: String!) {
    site {
      siteMetadata {
        title
        author
      }
    }
    markdownRemark(fields: { slug: { eq: $slug } }) {
      id
      excerpt(pruneLength: 160)
      html
      frontmatter {
        title
        description
        image: featured {
          childImageSharp {
            resize(width: 1200) {
              src
              height
              width
            }
          }
        }
      }
    }
  }
`
  • Typeof image width, height should be number
    src: PropTypes.string.isRequired,
    height: PropTypes.string.isRequired,
    width: PropTypes.string.isRequired,
  })

Motivation

  • Unused variable makes lint warning. and absolutely clear not to declare.
  • wrong propTypes makes error like below

error

Steps to resolve this issue

Draft the doc

Open a pull request

  • [ ✔️] Open a pull request with your work including the words "closes #[this issue's number]" in the pull request description : PR#22426
@soobing soobing added the type: documentation An issue or pull request for improving or updating Gatsby's documentation label Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant