@bradgarropy/gatsby-plugin-seo
Version:
š gatsby-plugin-seo
167 lines (135 loc) ⢠7.78 kB
Markdown
[![version][version-badge]][npm]
[![downloads][downloads-badge]][npm]
[![size][size-badge]][bundlephobia]
[![github actions][github-actions-badge]][github-actions]
[![coverage][codecov-badge]][codecov]
[![typescript][typescript-badge]][typescript]
[![contributing][contributing-badge]][contributing]
[![contributors][contributors-badge]][contributors]
[![discord][discord-badge]][discord]
_SEO plugin for [Gastby][gatsby]. Supports [Facebook][facebook], [Twitter][twitter], [Open Graph][og], and `meta` tags._
This package is installable from [npm][npm].
```shell
npm install @bradgarropy/gatsby-plugin-seo
```
To add a base set of SEO tags, create a [custom `<Layout/>` component][layout] and add the `<SEO/>` component there. The SEO tags will render for every route in your site.
```jsx
// .src/components/Layout.js
import SEO from "@bradgarropy/next-seo"
const Layout = ({children}) => {
return (
<>
<SEO title="My website" description="A blog and portfolio" />
{children}
</>
)
}
export default Layout
```
If you want to override SEO tags on individual pages, use the `<SEO/>` component and only include the props that you want to update. For example, if you added `<SEO/>` in the `Layout.js` file as shown above, and then included `<SEO/>` in the `about.js` file as shown below, the `description` would be overwritten to be `Learn more about me`.
```jsx
// .src/pages/about.js
import SEO from "@bradgarropy/next-seo"
import Layout from "../components/layout"
const AboutPage = () => {
return (
<Layout>
<SEO description="Learn more about me" />
<h1>about</h1>
</Layout>
)
}
export default AboutPage
```
With this capability, you can create a default set of SEO tags, and then tailor certain properties on specific pages.
| Name | Required | Example | Description |
| :--------------- | :------: | :--------------------------------- | :--------------------------------------------------------- |
| `title` | `false` | `"My website"` | Page title. |
| `description` | `false` | `"A blog and portfolio"` | Description of the page. |
| `keywords` | `false` | `["website", "blog", "portfolio"]` | Array of keywords. |
| `icon` | `false` | `"/favicon.ico"` | Tab icon url. |
| `themeColor` | `false` | `"#000000"` | Browser theme color. |
| `colorScheme` | `false` | `"light"` | Preferred color scheme. |
| `facebook.image` | `false` | `"/facebook.png"` | Facebook share image. |
| `facebook.url` | `false` | `"https://website.com"` | Page URL. |
| `facebook.type` | `false` | `"website"` | Type of resource. See all types [here][types]. |
| `twitter.image` | `false` | `"/twitter.png"` | Twitter share image. |
| `twitter.site` | `false` | `"@bradgarropy"` | Twitter handle of publishing site. |
| `twitter.card` | `false` | `"summary"` | Format of Twitter share card. See all types [here][cards]. |
All of the `SEO` props are optional. If a prop is not provided, the associated meta tag will not be rendered.
```jsx
// renders no seo tags
<SEO/>
// renders all seo tags
<SEO
title="My website"
description="A blog and portfolio"
keywords={["website", "blog", "portfolio"]}
icon="/favicon.ico"
themeColor="#000000"
colorScheme="light"
facebook={{
image: "/facebook.png",
url: "https://website.com",
type: "website",
}}
twitter={{
image: "/twitter.png",
site: "@bradgarropy",
card: "summary",
}}
/>
// renders some seo tags
<SEO
title="My blog"
description="Posts about technology"
keywords={["website", "blog", "technology"]}
/>
```
š report bugs by filing [issues][issues]
š¢ provide feedback with [issues][issues] or on [twitter][twitter]
šš¼āāļø use my [ama][ama] or [twitter][twitter] to ask any other questions
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://bradgarropy.com"><img src="https://avatars.githubusercontent.com/u/11336745?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Brad Garropy</b></sub></a><br /><a href="https://github.com/bradgarropy/gatsby-plugin-seo/commits?author=bradgarropy" title="Code">š»</a> <a href="https://github.com/bradgarropy/gatsby-plugin-seo/commits?author=bradgarropy" title="Documentation">š</a> <a href="https://github.com/bradgarropy/gatsby-plugin-seo/commits?author=bradgarropy" title="Tests">ā ļø</a> <a href="#infra-bradgarropy" title="Infrastructure (Hosting, Build-Tools, etc)">š</a></td>
<td align="center"><a href="https://www.webdevgem.com"><img src="https://avatars.githubusercontent.com/u/51011468?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gem Kosan</b></sub></a><br /><a href="https://github.com/bradgarropy/gatsby-plugin-seo/commits?author=GemKosan" title="Code">š»</a></td>
</tr>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
[]: https://gatsbyjs.org
[]: https://www.facebook.com/profile.php?id=7933107
[]: https://twitter.com/bradgarropy
[]: https://ogp.me
[]: https://www.npmjs.com/package/@bradgarropy/gatsby-plugin-seo
[]: https://github.com/bradgarropy/gatsby-plugin-seo/issues
[]: https://twitter.com/bradgarropy
[]: https://bradgarropy.com/ama
[]: https://img.shields.io/npm/v/@bradgarropy/http.svg?style=flat-square
[]: https://img.shields.io/npm/dt/@bradgarropy/http?style=flat-square
[]: https://bundlephobia.com/result?p=@bradgarropy/gatsby-plugin-seo
[]: https://img.shields.io/bundlephobia/minzip/@bradgarropy/http?style=flat-square
[]: https://github.com/bradgarropy/gatsby-plugin-seo/actions
[]: https://img.shields.io/github/workflow/status/bradgarropy/gatsby-plugin-seo/%F0%9F%9A%80%20release?style=flat-square
[]: https://app.codecov.io/gh/bradgarropy/gatsby-plugin-seo
[]: https://img.shields.io/codecov/c/github/bradgarropy/gatsby-plugin-seo?style=flat-square
[]: https://www.typescriptlang.org/dt/search?search=%40bradgarropy%2Fgatsby-plugin-seo
[]: https://img.shields.io/npm/types/@bradgarropy/gatsby-plugin-seo?style=flat-square
[]: https://github.com/bradgarropy/gatsby-plugin-seo/blob/master/contributing.md
[]: https://img.shields.io/badge/PRs-welcome-success?style=flat-square
[]:
[]: https://img.shields.io/github/all-contributors/bradgarropy/gatsby-plugin-seo?style=flat-square
[]: https://bradgarropy.com/discord
[]: https://img.shields.io/discord/748196643140010015?style=flat-square
[]: https://www.gatsbyjs.com/docs/recipes/pages-layouts#creating-a-layout-component