gatsby-plugin-wpgraphql-seo
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -32,3 +32,3 @@ 'use strict'; | ||
var SEO = function SEO(_ref) { | ||
var _global$schema; | ||
var _seo$schema, _global$schema; | ||
@@ -41,4 +41,6 @@ var _ref$post = _ref.post, | ||
postSchema = _ref.postSchema; | ||
var seo = post.seo; | ||
var seo = post.seo; // If manually passed or try get from post data | ||
var fullSchema = postSchema || JSON.parse(seo == null ? void 0 : (_seo$schema = seo.schema) == null ? void 0 : _seo$schema.raw); | ||
var _useContext = React.useContext(SEOContext), | ||
@@ -134,3 +136,3 @@ global = _useContext.global; | ||
type: "application/ld+json" | ||
}, JSON.stringify(_extends({}, postSchema), null, 2))); | ||
}, JSON.stringify(_extends({}, fullSchema), null, 2))); | ||
}; | ||
@@ -137,0 +139,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,i=require("react-helmet");function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}var r=t.createContext({}),a=function(e){var a,l=e.post,c=e.meta,p=void 0===c?[]:c,s=e.title,u=e.postSchema,d=(void 0===l?{}:l).seo,m=t.useContext(r).global,v=null==m||null==(a=m.schema)?void 0:a.inLanguage,y=null==m?void 0:m.schema,f=null==m?void 0:m.webmaster,g=null==m?void 0:m.social,h=[];(null==f?void 0:f.baiduVerify)&&h.push({name:"baidu-site-verification",content:f.baiduVerify}),(null==f?void 0:f.googleVerify)&&h.push({name:"google-site-verification",content:f.googleVerify}),(null==f?void 0:f.msVerify)&&h.push({name:"msvalidate.01",content:f.msVerify}),(null==f?void 0:f.yandexVerify)&&h.push({name:"yandex-verification",content:f.yandexVerify}),(null==g?void 0:g.pinterest)&&g.pinterest.metaTag&&h.push({name:"p:domain_verify",content:g.pinterest.metaTag});var w=s||d.title,x=(null==d?void 0:d.metaDesc)?d.metaDesc:"";return n.createElement(i.Helmet,{htmlAttributes:{lang:v},title:w,meta:[{name:"robots",content:"max-snippet:-1, max-image-preview:large, max-video-preview:-1"},{name:"description",content:x},{property:"og:site_name",content:null==y?void 0:y.companyName},{property:"og:title",content:(null==d?void 0:d.opengraphTitle)||w},{property:"og:description",content:null==d?void 0:d.opengraphDescription},{property:"og:locale",content:"en_GB"},{property:"og:type",content:"website"},{name:"twitter:card",content:null==g?void 0:g.twitter.cardType},{name:"twitter:creator",content:null==g?void 0:g.twitter.username},{name:"twitter:title",content:(null==d?void 0:d.twitterTitle)||w},{name:"twitter:description",content:(null==d?void 0:d.twitterDescription)||x}].filter((function(e){return!!e.content})).concat(p,h),encodeSpecialCharacters:!1},u&&n.createElement("script",{type:"application/ld+json"},JSON.stringify(o({},u),null,2)))};exports.SEOContext=r,exports.Seo=a,exports.default=a; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,i=require("react-helmet");function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}var r=t.createContext({}),a=function(e){var a,l,c=e.post,p=e.meta,s=void 0===p?[]:p,u=e.title,d=e.postSchema,m=(void 0===c?{}:c).seo,v=d||JSON.parse(null==m||null==(a=m.schema)?void 0:a.raw),y=t.useContext(r).global,f=null==y||null==(l=y.schema)?void 0:l.inLanguage,g=null==y?void 0:y.schema,h=null==y?void 0:y.webmaster,w=null==y?void 0:y.social,x=[];(null==h?void 0:h.baiduVerify)&&x.push({name:"baidu-site-verification",content:h.baiduVerify}),(null==h?void 0:h.googleVerify)&&x.push({name:"google-site-verification",content:h.googleVerify}),(null==h?void 0:h.msVerify)&&x.push({name:"msvalidate.01",content:h.msVerify}),(null==h?void 0:h.yandexVerify)&&x.push({name:"yandex-verification",content:h.yandexVerify}),(null==w?void 0:w.pinterest)&&w.pinterest.metaTag&&x.push({name:"p:domain_verify",content:w.pinterest.metaTag});var b=u||m.title,V=(null==m?void 0:m.metaDesc)?m.metaDesc:"";return n.createElement(i.Helmet,{htmlAttributes:{lang:f},title:b,meta:[{name:"robots",content:"max-snippet:-1, max-image-preview:large, max-video-preview:-1"},{name:"description",content:V},{property:"og:site_name",content:null==g?void 0:g.companyName},{property:"og:title",content:(null==m?void 0:m.opengraphTitle)||b},{property:"og:description",content:null==m?void 0:m.opengraphDescription},{property:"og:locale",content:"en_GB"},{property:"og:type",content:"website"},{name:"twitter:card",content:null==w?void 0:w.twitter.cardType},{name:"twitter:creator",content:null==w?void 0:w.twitter.username},{name:"twitter:title",content:(null==m?void 0:m.twitterTitle)||b},{name:"twitter:description",content:(null==m?void 0:m.twitterDescription)||V}].filter((function(e){return!!e.content})).concat(s,x),encodeSpecialCharacters:!1},d&&n.createElement("script",{type:"application/ld+json"},JSON.stringify(o({},v),null,2)))};exports.SEOContext=r,exports.Seo=a,exports.default=a; | ||
//# sourceMappingURL=gatsby-plugin-wpgraphql-seo.cjs.production.min.js.map |
@@ -25,3 +25,3 @@ import React, { createContext, useContext } from 'react'; | ||
var SEO = function SEO(_ref) { | ||
var _global$schema; | ||
var _seo$schema, _global$schema; | ||
@@ -34,4 +34,6 @@ var _ref$post = _ref.post, | ||
postSchema = _ref.postSchema; | ||
var seo = post.seo; | ||
var seo = post.seo; // If manually passed or try get from post data | ||
var fullSchema = postSchema || JSON.parse(seo == null ? void 0 : (_seo$schema = seo.schema) == null ? void 0 : _seo$schema.raw); | ||
var _useContext = useContext(SEOContext), | ||
@@ -127,3 +129,3 @@ global = _useContext.global; | ||
type: "application/ld+json" | ||
}, JSON.stringify(_extends({}, postSchema), null, 2))); | ||
}, JSON.stringify(_extends({}, fullSchema), null, 2))); | ||
}; | ||
@@ -130,0 +132,0 @@ |
{ | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"license": "MIT", | ||
@@ -14,6 +14,6 @@ "main": "dist/index.js", | ||
"start": "tsdx watch", | ||
"build": "tsdx build", | ||
"test": "tsdx test --passWithNoTests", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"build": "./node_modules/.bin/tsdx build", | ||
"test": "./node_modules/.bin/tsdx test --passWithNoTests", | ||
"lint": "./node_modules/.bin/tsdx lint", | ||
"prepare": "./node_modules/.bin/tsdx build", | ||
"size": "size-limit", | ||
@@ -20,0 +20,0 @@ "analyze": "size-limit --why" |
180
README.md
# Gatsby SEO For WpGraphQL and Yoast | ||
> Details coming soon... | ||
Takes data from [WpGraphQL](https://www.wpgraphql.com/) and [WPGraphQl Yoast SEO](https://github.com/ashhitch/wp-graphql-yoast-seo) and provided you with Meta Tags and JSON+LD Schema in Gatsby. | ||
Works with: | ||
(https://github.com/ashhitch/wp-graphql-yoast-seo) | ||
## Basic Setup | ||
### Install package | ||
Yarn or NPM install | ||
> yarn add gatsby-plugin-wpgraphql-seo | ||
or | ||
> npm install gatsby-plugin-wpgraphql-seo | ||
### Setup Gatsby | ||
In your sites layout setup the context provider to pass the component your general site settings. | ||
```jsx | ||
import React, { useState } from 'react'; | ||
import { useStaticQuery, graphql } from 'gatsby'; | ||
import { SEOContext } from 'gatsby-plugin-wpgraphql-seo'; | ||
export const Layout = () => { | ||
const { | ||
wp: { seo }, | ||
} = useStaticQuery(graphql` | ||
query SiteInfoQuery { | ||
wp { | ||
seo { | ||
contentTypes { | ||
post { | ||
title | ||
schemaType | ||
metaRobotsNoindex | ||
metaDesc | ||
} | ||
page { | ||
metaDesc | ||
metaRobotsNoindex | ||
schemaType | ||
title | ||
} | ||
} | ||
webmaster { | ||
googleVerify | ||
yandexVerify | ||
msVerify | ||
baiduVerify | ||
} | ||
schema { | ||
companyName | ||
personName | ||
companyOrPerson | ||
wordpressSiteName | ||
siteUrl | ||
siteName | ||
inLanguage | ||
logo { | ||
sourceUrl | ||
mediaItemUrl | ||
altText | ||
} | ||
} | ||
social { | ||
facebook { | ||
url | ||
defaultImage { | ||
sourceUrl | ||
mediaItemUrl | ||
} | ||
} | ||
instagram { | ||
url | ||
} | ||
linkedIn { | ||
url | ||
} | ||
mySpace { | ||
url | ||
} | ||
pinterest { | ||
url | ||
metaTag | ||
} | ||
twitter { | ||
username | ||
} | ||
wikipedia { | ||
url | ||
} | ||
youTube { | ||
url | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
return ( | ||
<SEOContext.Provider value={{ global: seo }}> | ||
<p>... your layout</p> | ||
</SEOContext.Provider> | ||
); | ||
}; | ||
``` | ||
For each page or template you then need to add the SEO Component | ||
```jsx | ||
import React from 'react'; | ||
import { graphql } from 'gatsby'; | ||
import Seo from 'gatsby-plugin-wpgraphql-seo'; | ||
const Page = ({ data: { wpPage } }) => { | ||
return ( | ||
<> | ||
<Seo post={wpPage} /> | ||
<p>Rest of page</p> | ||
</> | ||
); | ||
}; | ||
export default Page; | ||
export const pageQuery = graphql` | ||
query GET_PAGE($id: String!) { | ||
wpPage(id: { eq: $id }) { | ||
nodeType | ||
title | ||
uri | ||
seo { | ||
title | ||
metaDesc | ||
focuskw | ||
metaKeywords | ||
metaRobotsNoindex | ||
metaRobotsNofollow | ||
opengraphTitle | ||
opengraphDescription | ||
opengraphImage { | ||
altText | ||
sourceUrl | ||
srcSet | ||
} | ||
twitterTitle | ||
twitterDescription | ||
twitterImage { | ||
altText | ||
sourceUrl | ||
srcSet | ||
} | ||
canonical | ||
cornerstone | ||
schema { | ||
articleType | ||
pageType | ||
raw | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
``` | ||
Additional props are provided for overrides and simpler pages: | ||
``` | ||
title: String to override Title | ||
meta: Array of key value objects for meta tags (e.g property, content) | ||
post: WpGrahpQL post object | ||
postSchema: JSON object to replace complete JSON+LD schema; | ||
``` | ||
... More docs coming soon |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48714
358
181