Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
luciobenini committed May 20, 2020
0 parents commit 3a3ca4f
Show file tree
Hide file tree
Showing 13 changed files with 597 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
101 changes: 101 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
12 changes: 12 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
logs
*.log
node_modules
*.un~
yarn.lock
package-lock.json
flow-typed
coverage
decls
examples
.gitattributes
gatsby-plugin-seo.code-workspace
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Pittica S.r.l.s.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# pittica/gatsby-plugin-seo

![License](https://img.shields.io/github/license/pittica/gatsby-plugin-seo)
![Version](https://img.shields.io/github/package-json/v/pittica/gatsby-plugin-seo)
![Release](https://img.shields.io/github/v/release/pittica/gatsby-plugin-seo)
![GitHub package.json dependency version (dev dep on branch)](https://img.shields.io/github/package-json/dependency-version/pittica/gatsby-plugin-seo/dev/gatsby)
![GitHub package.json dependency version (dev dep on branch)](https://img.shields.io/github/package-json/dependency-version/pittica/gatsby-plugin-seo/dev/react)

## Description

SEO plugin for [GatsbyJS](https://www.gatsbyjs.org/).

## Install

[![npm](https://img.shields.io/npm/v/@pittica/gatsby-plugin-seo)](https://www.npmjs.com/package/@pittica/gatsby-plugin-seo)

```shell
npm install @pittica/gatsby-plugin-seo
```

## Usage

The plugin provides SEO optimization.

## Configuration

Edit your **gatsby-config.js**.

```javascript
module.exports = {
plugins: [
{
resolve: `@pittica/gatsby-plugin-seo`,
options: {
image: `/DEFAULT_SHARING_IMAGE.jpg`,
socials: {
instagram: {
username: `INSTAGRAM_USERNAME`
},
github: {
username: `GITHUB_USERNAME`
},
facebook: {
page: `FACEBOOK_PAGE_USERNAME`,
app: `FACEBOOK_APP_ID`
},
twitter: {
username: `TWITTER_USERNAME`,
site: `TWITTER_SITE_USERNAME`
}
}
},
],
}
```
## Copyright
(c) 2020, Pittaca S.r.l.s.
33 changes: 33 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const loadsh = require(`lodash`)

exports.onCreateNode = ({ node, actions }, options) => {
const { createNodeField } = actions

if (node.id === `SiteBuildMetadata`) {
const socials = loadsh.merge({
instagram: {
username: ``
},
github: {
username: ``
},
facebook: {
page: ``,
app: ``
},
twitter: {
username: ``,
site: ``
}
}, options.socials || {})

createNodeField({
name: `seo`,
node,
value: {
image: options.image,
socials
}
})
}
}
8 changes: 8 additions & 0 deletions gatsby-plugin-seo.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import OpenGraph from "./src/open-graph"
import TwitterCard from "./src/twitter-card"
import SchemaOrg from "./src/schema-org"
import SEO from "./src/seo"

export { SEO, SchemaOrg, OpenGraph, TwitterCard }
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@pittica/gatsby-plugin-seo",
"private": false,
"description": "SEO optimization plugin for GatsbyJS.",
"version": "1.0.0",
"author": {
"name": "Lucio Benini",
"email": "info@pittica.com",
"url": "https://pittica.com"
},
"bugs": {
"url": "https://github.com/pittica/gatsby-plugin-seo/issues"
},
"deprecated": false,
"homepage": "https://github.com/pittica/gatsby-plugin-seo",
"keywords": [
"gatsby",
"gatsby-plugin",
"seo",
"social-networks"
],
"dependencies": {
"prop-types": "^15.7.2",
"gatsby-plugin-react-helmet": "^3.3.1"
},
"devDependencies": {
"gatsby": "^2.21.22",
"react": "^16.13.1",
"react-helmet": "^6.0.0",
"react-dom": "^16.13.1",
"lodash": "^4.17.15"
},
"license": "MIT",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/pittica/gatsby-plugin-seo.git"
}
}
80 changes: 80 additions & 0 deletions src/open-graph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from "react"
import { Helmet } from "react-helmet"
import { useStaticQuery, graphql } from "gatsby"
import PropTypes from "prop-types"

const OpenGraph = ({ url, title, article, description, image }) => {
const data = useStaticQuery(
graphql`
query {
site {
siteMetadata {
locale {
language
culture
}
}
}
siteBuildMetadata {
fields {
seo {
socials {
facebook {
page
app
}
}
}
}
}
}
`
)
const facebook = data.siteBuildMetadata.fields.seo.socials.facebook

return (
<Helmet>
<meta property="og:url" content={url} />
{article ? <meta property="og:type" content="article" /> : null}
<meta property="og:title" content={title} />
<meta
property="og:locale"
content={[
data.site.siteMetadata.locale.language.toLowerCase(),
data.site.siteMetadata.locale.culture.toUpperCase()
].join("_")}
/>
<meta property="og:description" content={description} />
{image ? (
<meta property="og:image" content={image} />
) : null}
{facebook.app ? (
<meta property="fb:app_id" content={facebook.app} />
) : null}
{article && facebook.page ? (
<meta
property="article:publisher"
content={"https://www.facebook.com/" + facebook.page}
/>
) : null}
</Helmet>
)
}

OpenGraph.propTypes = {
url: PropTypes.string,
article: PropTypes.bool,
image: PropTypes.string,
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired
}

OpenGraph.defaultProps = {
url: null,
article: false,
image: null,
title: null,
description: null
}

export default OpenGraph
Loading

0 comments on commit 3a3ca4f

Please sign in to comment.