You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: docs/docs/add-seo-component.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
---
2
-
title: "Adding an SEO Component"
2
+
title: "SEO コンポーネントを追加する"
3
3
---
4
4
5
-
Every site on the web has basic _meta-tags_ like the title, favicon or description of the page in their `<head>`element. This information gets displayed in the browser and is used when someone shares your website, e.g. on Twitter. You can give your users and these websites additional data to embed your website with more data — and that's where this guide for a SEO component comes in. At the end you'll have a component you can place in your layout file and have rich previews for other clients, smartphone users, and search engines.
5
+
Web 上の全てのサイトは、ページのタイトル、説明文、ファビコンなどの基本的なメタタグを `<head>`要素に持たせています。これらの情報はブラウザや Twitter などのサイトでシェアした際に表示されます。サイトの開発者はユーザーや他のサイトにより多くの情報を提供できます。そこで参考にしていただきたいのがこのガイドです。このガイドでは、スマートフォンユや検索エンジンでリッチなプレビューを表示するコンポーネントをレイアウトファイルに追加します。
6
6
7
-
_Note: This component will use StaticQuery. If you're unfamiliar with that, have a look at the [StaticQuery documentation](/docs/static-query/). You also have to have `react-helmet`installed for which you can have a look at [this document](/docs/add-page-metadata)._
Gatsby makes all data put into the `siteMetadata` section of your `gatsby-config`file automatically available in GraphQL and therefore it's a good idea to place your information for the component there.
Create a new component with this initial boilerplate:
29
+
この雛形をもとに新しいコンポーネントを作成してください。
30
30
31
31
```jsx:title=src/components/SEO.js
32
32
importReactfrom"react"
@@ -55,11 +55,11 @@ SEO.defaultProps = {
55
55
}
56
56
```
57
57
58
-
**Note:**`propTypes`are included in this example to help you ensure you’re getting all the data you need in the component, and to help serve as a guide while destructuring / using those props.
As the SEO component should also be usable in other files, e.g. a template file, the component also accepts properties for which you set sensible defaults in the `SEO.defaultProps`section. This way the information you put into `siteMetadata`gets used every time unless you define the property explicitly.
Now define the query and place it in the StaticQuery (you can also save the query in a constant). You can also alias query items, so `title`gets renamed to `defaultTitle`.
The next step is to destructure the data from the query and to create an object that checks if the props were used — if not the default values are utilized. The name aliasing comes in handy here: It avoids name collisions.
The last step is to return this data with the help of `Helmet`. Your complete SEO component should look like:
120
+
最後に `Helmet` を使ってこの情報を返します。完成した SEO コンポーネントはこのようになっているはずです。
121
121
122
122
```jsx:title=src/components/SEO.js
123
123
importReactfrom"react"
@@ -213,9 +213,9 @@ const query = graphql`
213
213
214
214
## Examples
215
215
216
-
You could also put the Facebook and Twitter meta-tags into their own components, add custom favicons you placed in your `static`folder, and add [schema.org](https://schema.org/) data (Google will use that for their [Structured Data](https://developers.google.com/search/docs/guides/intro-structured-data)). To see how that works you can have a look at these two examples:
As mentioned at the beginning you are also able to use the component in templates, like in [this example](https://github.com/jlengstorf/marisamorby.com/blob/6e86f845185f9650ff95316d3475bb8ac86b15bf/src/templates/post.js#L12-L18).
0 commit comments