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

[1.0] SSR API changes #1085

Merged
merged 14 commits into from
Jun 2, 2017
Merged

[1.0] SSR API changes #1085

merged 14 commits into from
Jun 2, 2017

Conversation

KyleAMathews
Copy link
Contributor

Made the SSR APIs more "redux-y" or consistent with the rest of the API. Which also had the nice side effect of eliminating two APIs #winning

So now you do something like the following to add components to the head/body (this is taken from a new plugin I just added while working on this for auto-integration with react-helmet):

import helmet from "react-helmet"

exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => {
  setHeadComponents([
    helmet.title.toComponent(),
    helmet.meta.toComponent(),
    helmet.link.toComponent(),
  ])
}

@KyleAMathews
Copy link
Contributor Author

Deploy preview failed.

Built with commit 8e1ee87

https://app.netlify.com/sites/image-processing/deploys/5930bbda6f4c5060d157d82d

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Jun 2, 2017

Deploy preview ready!

Built with commit 589120f

https://deploy-preview-1085--gatsbyjs.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jun 2, 2017

Deploy preview ready!

Built with commit 589120f

https://deploy-preview-1085--using-drupal.netlify.com

@KyleAMathews
Copy link
Contributor Author

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Jun 2, 2017

Deploy preview ready!

Built with commit 589120f

https://deploy-preview-1085--gatsbygram.netlify.com

@akadop
Copy link
Contributor

akadop commented Jun 2, 2017

Could you add helmet.script.toComponent(), as well? It works really well when you want to pull in front matter data for schema.org script data.

example: I have successfully used this when I was working on a gatsby project -->

<Helmet 
...
script={[
            {
              type: 'application/json',
              innerHTML: `{
                "@context": "http://schema.org",
                "@type": "Webpage",
                "breadcrumb": "${post.frontmatter.exam} > ${post.frontmatter.category} > ${post.frontmatter.title}",
                "name": "${post.frontmatter.title}",
                "publisher": {
                  "@type": "Organization",
                  "name": "exampaths",
                  "logo": {
                    "@type": "ImageObject",
                    "url": "https://exampaths.com/wp-content/uploads/epicon.png",
                    "width": 600,
                    "height": 60
                  }
                },
                "mainEntityOfPage": {
                  "@type": "Review",
                  "author": {
                    "@type": "Person",
                    "name": "${post.frontmatter.author}"
                  },
                  "@id": "${post.frontmatter.slug}",
                  "url": "${post.frontmatter.url}",
                  "itemReviewed": {
                    "@type": "Thing",
                    "name": "${post.frontmatter.item}"
                  },
                  "inLanguage": "en",
                  "datePublished": "${post.frontmatter.date}",
                  "description": "${post.frontmatter.seoDescription}",
                  "reviewRating": {
                    "@type": "Rating",
                    "bestRating": 5,
                    "ratingValue": "${post.frontmatter.rating}",
                    "worstRating": 1
                  },
                  "publisher": {
                    "@type": "Organization",
                    "name": "exampaths",
                    "sameAs": "https://exampaths.com",
                    "logo": {
                      "@type": "ImageObject",
                      "url": "https://exampaths.com/wp-content/uploads/epicon.png",
                      "width": 600,
                      "height": 60
                    }
                  },
                  "review": {
                    "@type": "Review",
                    "url": "${post.frontmatter.url}",
                    "itemReviewed": {
                      "@type": "Thing",
                      "name": "${post.frontmatter.item}"
                    },
                    "author": {
                      "@type": "Person",
                      "name": "${post.frontmatter.author}"
                    },
                    "inLanguage": "en",
                    "datePublished": "${post.frontmatter.published}",
                    "description": "${post.frontmatter.seoDescription}",
                    "reviewRating": {
                      "@type": "Rating",
                      "bestRating": 5,
                      "ratingValue": "${post.frontmatter.rating}",
                      "worstRating": 1
                    },
                    "publisher": {
                      "@type": "Organization",
                      "name": "exampaths",
                      "sameAs": "https://exampaths.com",
                      "logo": {
                        "@type": "ImageObject",
                        "url": "https://exampaths.com/wp-content/uploads/epicon.png",
                        "width": 600,
                        "height": 60
                      }
                    }
                  }
                }
              }
             }`,
            },
          ]}
        />

@KyleAMathews
Copy link
Contributor Author

@akadop ooo nice example! I didn't realize React Helmet supported that :-) I looked at the docs and am now outputting its other types as components as well d67253f

@KyleAMathews KyleAMathews mentioned this pull request Jun 2, 2017
@KyleAMathews KyleAMathews merged commit 52bc4fe into 1.0 Jun 2, 2017
@KyleAMathews KyleAMathews deleted the ssr-on-body-render branch June 2, 2017 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants