百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

gatsby-plugin-next-seo

> 编程语言
开源

Gatsby Plugin Next SEO 是一个插件,可在 Gatsby 项目中更轻松地管理 SEO。

197 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Gatsby Plugin Next SEO 是一个插件,可在 Gatsby 项目中更轻松地管理 SEO。

gatsby-plugin-next-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.

Table of Contents

  • gatsby-plugin-next-seo
    • Table of Contents
    • Usage
      • Setup
      • Add Plugin to Gatsby Config
      • Add SEO to Page
        • A note on Twitter Tags
      • Default SEO Configuration in Gatsby Config
      • GatsbySeo Options
        • Title Template
        • No Index
        • dangerouslySetAllPagesToNoIndex
        • No Follow
        • dangerouslySetAllPagesToNoFollow
        • Twitter
        • facebook
        • Canonical URL
        • Alternate
        • HTML Attributes
        • Meta Tags
    • Open Graph
      • Open Graph Examples
        • Basic Example
        • Video Example
        • Article Example
        • Book Example
        • Profile Example
    • JSON-LD
      • Override
      • Article
      • News Article
      • Blog Post
      • Breadcrumb
      • Blog
      • Book
      • Speakable
      • FAQ
        • Question Interface
      • Course
      • Corporate Contact (Deprecated)
      • Local Business
      • Logo
      • Product
      • Social Profile (Deprecated)
      • JsonLd
      • Sitelinks Search Box
    • API Docs
    • FAQ
      • Why did you choose gatsby-plugin-next-seo as the project name?
    • Contributors

Usage

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.

Setup

First, install the plugin and it's peer dependencies:

bash
npm install --save gatsby-plugin-next-seo react-helmet-async

or

bash
yarn add gatsby-plugin-next-seo react-helmet-async

react-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 Plugin to Gatsby Config

Add the following configuration to your gatsby-config.js file.

javascript
module.exports {
  // ...
  plugins: [
    // ...
    'gatsby-plugin-next-seo'
  ],
}

The plugin allows documented GatsbySeoPluginOptions to be set. See an example below.

Add SEO to Page

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:

typescript
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:

typescript
import React, { FC } from 'react';
import { GatsbySeo } from 'gatsby-plugin-next-seo';

const Layout: FC = ({ children }) => (
  <>
    
    

  
);

export default Layout;

A note on Twitter Tags

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

Default SEO Configuration in Gatsby Config

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:

javascript
// 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.

GatsbySeo Options

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· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言