Gatsby Plugin Next SEO 是一个插件,可在 Gatsby 项目中更轻松地管理 SEO。
Gatsby Plugin Next SEO 是一个插件,可在 Gatsby 项目中更轻松地管理 SEO。
Gatsby Plugin SEO makes managing SEO easier in your Gatsby JS project. It fully supports server-side rendering (SSR) with site wide configuration available via the gatsby-config.js plugin options. SEO options can also be tweaked at any moment by importing the main GatsbySeo component and passing in the desired props.
This codebase was initially forked from the brilliant next-seo project and is now maintained separately.
GatsbySeo can be imported anywhere in your gatsby project. Once included you pass the configuration props with the page's SEO properties. A sitewide / default configuration can also be set via the plugin options in your gatsby-config.js file.
First, install the plugin and it's peer dependencies:
npm install --save gatsby-plugin-next-seo react-helmet-asyncor
yarn add gatsby-plugin-next-seo react-helmet-asyncreact-helmet-async is an required external dependency since it relies on the React.Context API which can cause problems when different versions of the same library interact.
Add the following configuration to your gatsby-config.js file.
module.exports {
// ...
plugins: [
// ...
'gatsby-plugin-next-seo'
],
}The plugin allows documented GatsbySeoPluginOptions to be set. See an example below.
Then you need to import GatsbySeo and add the desired properties. This component render the tags in the `` for SEO on a per page basis. As a bare minimum, you should add a title and description.
Example with just title and description:
import React from 'react';
import { GatsbySeo } from 'gatsby-plugin-next-seo';
export default () => (
<>
Simple Usage
);But GatsbySeo gives you many more options that you can add. See below for a typical example for any given gatsby layout.
Typical page example:
import React, { FC } from 'react';
import { GatsbySeo } from 'gatsby-plugin-next-seo';
const Layout: FC = ({ children }) => (
<>
);
export default Layout;Twitter will read the og:title, og:image and og:description tags for their card. gatsby-plugin-next-seo omits twitter:title, twitter:image and twitter:description to avoid duplication.
Some tools may report this an error. See Issue #14
GatsbySeo enables you to set the default SEO properties that will appear on all pages without needing to do include anything on them. You can also override these on a page by page basis if needed.
To achieve this, you will need to add the properties to your gatsby-config.js file when setting up the plugin.
Here is a typical example:
// gatsby-config.js
module.exports {
plugins: [
{
resolve: 'gatsby-plugin-next-seo',
options: {
openGraph: {
type: 'website',
locale: 'en_IE',
url: 'https://www.url.ie/',
site_name: 'SiteName',
},
twitter: {
handle: '@handle',
site: '@site',
cardType: 'summary_large_image',
},
},
},
],
}From now on all of your gatsby pages will have the defaults above applied.
| Property | Type | Description |
|---|---|---|
titleTemplate |
string | Allows you to set default title template that will be added to your title More Info. |
title |
string | Set the meta title of the page. |
language |
string | Set the language of the current page. This is added to the html tag and can prevent this warning. |
noindex |
boolean (default false) | Sets whether page should be indexed or not More Info. |
nofollow |
boolean (default false) | Sets whether page should be followed or not More Info. |
description |
string | Set the page meta description. |
canonical |
string | Set the page canonical url. |
mobileAlternate.media |
string | Set what screen size the mobile website should be served from. |
mobileAlternate.href |
string | Set the mobile page alternate url. |
languageAlternates |
array | Set the language of the alternate urls. The shape of the object should be: { hrefLang: string, href: string }. |
metaTags |
array | Allows you to add a meta tag that is not documented here. More Info. |
twitter.cardType |
string | The card type, which will be one of summary, summary_large_image, app, or player. |
twitter.site |
string | @username for the website used in the card footer. |
twitter.handle |
string | @username for the content creator / author (outputs as twitter:creator). |
facebook.appId |
string | Used for Facebook Insights, you must add a facebook app ID to your page to for it More Info. |
openGraph.url |
string | The canonical URL of your object that will be used as its permanent ID in the graph. |
openGraph.type |
string | The type of your object. Depending on the type you specify, other properties may also be required More Info |
openGraph.title |
string | The open graph title, this can be different than your meta title. |
openGraph.description |
string | The open graph description, this can be different than your meta description. |
openGraph.images |
array | An array of images (object) to be used by social media platforms, slack etc as a preview. If multiple supplied you can choose one when sharing. See Examples |
openGraph.videos |
array | An array of videos (object). |
openGraph.locale |
string | The locale the open graph tags are marked up in. Of the format language_TERRITORY. Default is en_US. |
openGraph.site_name |
string | If your object is part of a larger web site, the name which should be displayed for the overall site. |
openGraph.profile.firstName |
string |
暂无开放 Issues,或尚未同步最近议题。