@@ -16,16 +16,14 @@ export interface BaseSeo {
1616
1717export interface Seo {
1818 /**
19- * The <title> HTML element defines the document's title that is shown in a
20- * browser's title bar or a page's tab. It only contains text; tags within the
21- * element are ignored.
19+ * The <title> HTML element defines the document's title that is shown in a browser's title bar or a page's tab. It
20+ * only contains text; tags within the element are ignored.
2221 *
2322 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title
2423 */
2524 title : Maybe < string > | undefined ;
2625 /**
27- * Generate the title from a template that includes a `%s` placeholder for the
28- * title.
26+ * Generate the title from a template that includes a `%s` placeholder for the title.
2927 *
3028 * @example
3129 * ```js
@@ -37,13 +35,11 @@ export interface Seo {
3735 */
3836 titleTemplate : Maybe < string > | undefined | null ;
3937 /**
40- * The media associated with the given page (images, videos, etc). If you pass
41- * a string, it will be used as the `og:image` meta tag. If you pass an object
42- * or an array of objects, that will be used to generate `og:<type of media>`
43- * meta tags. The `url` property should be the URL of the media. The `height`
44- * and `width` properties are optional and should be the height and width of
45- * the media. The `alt` property is optional and should be a description of
46- * the media.
38+ * The media associated with the given page (images, videos, etc). If you pass a string, it will be used as the
39+ * `og:image` meta tag. If you pass an object or an array of objects, that will be used to generate
40+ * `og:<type of media>` meta tags. The `url` property should be the URL of the media. The `height` and `width`
41+ * properties are optional and should be the height and width of the media. The `altText` property is optional and
42+ * should be a description of the media.
4743 *
4844 * @example
4945 * ```js
@@ -63,24 +59,23 @@ export interface Seo {
6359 */
6460 media : Maybe < string > | undefined | SeoMedia | SeoMedia [ ] ;
6561 /**
66- * The description of the page. This is used in the `name="description"` meta
67- * tag as well as the `og:description` meta tag .
62+ * The description of the page. This is used in the `name="description"` meta tag as well as the `og:description` meta
63+ * tag.
6864 *
6965 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
7066 */
7167 description : Maybe < string > | undefined ;
7268 /**
73- * The canonical URL of the page. This is used to tell search engines which
74- * URL is the canonical version of a page. This is useful when you have
75- * multiple URLs that point to the same page. The value here will be used in
76- * the `rel="canonical"` link tag as well as the `og:url` meta tag.
69+ * The canonical URL of the page. This is used to tell search engines which URL is the canonical version of a page.
70+ * This is useful when you have multiple URLs that point to the same page. The value here will be used in the
71+ * `rel="canonical"` link tag as well as the `og:url` meta tag.
7772 *
7873 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
7974 */
8075 url : Maybe < string > | undefined ;
8176 /**
82- * The handle is used to generate the `twitter:site` and `twitter:creator`
83- * meta tags. Include the `@` symbol in the handle.
77+ * The handle is used to generate the `twitter:site` and `twitter:creator` meta tags. Include the `@` symbol in the
78+ * handle.
8479 *
8580 * @example
8681 * ```js
@@ -91,11 +86,9 @@ export interface Seo {
9186 */
9287 handle : Maybe < string > | undefined ;
9388 /**
94- * The `ldJson` property is used to generate the `application/ld+json` script
95- * tag. This is used to provide structured data to search engines. The value
96- * should be an object that conforms to the schema.org spec. The `type`
97- * property should be the type of schema you are using. The `type` property is
98- * required and should be one of the following:
89+ * The `ldJson` property is used to generate the `application/ld+json` script tag. This is used to provide structured
90+ * data to search engines. The value should be an object that conforms to the schema.org spec. The `type` property
91+ * should be the type of schema you are using. The `type` property is required and should be one of the following:
9992 *
10093 * - `Product`
10194 * - `ItemList`
@@ -180,8 +173,8 @@ export interface Seo {
180173export interface LanguageAlternate {
181174 // Language code for the alternate page. This is used to generate the hreflang meta tag property.
182175 language : string ;
183- // Whether or not the alternate page is the default page. This will add the `x-default`
184- // attribution to the language code.
176+ // Whether or not the alternate page is the default page. This will add the `x-default` attribution to the language
177+ // code.
185178 default ?: boolean ;
186179 // The url of the alternate page. This is used to generate the hreflang meta tag property.
187180 url : string ;
@@ -197,17 +190,13 @@ export interface MobileAlternate {
197190export type SeoMedia = {
198191 // Used to generate og:<type of media> meta tag
199192 type : 'image' | 'video' | 'audio' ;
200- // The url value populates both url and secure_url and is used to infer the
201- // og:<type of media>:type meta tag.
193+ // The url value populates both url and secure_url and is used to infer the og:<type of media>:type meta tag.
202194 url : Maybe < string > | undefined ;
203- // The height in pixels of the media. This is used to generate the og:<type of
204- // media>:height meta tag.
195+ // The height in pixels of the media. This is used to generate the og:<type of media>:height meta tag.
205196 height : Maybe < number > | undefined ;
206- // The width in pixels of the media. This is used to generate the og:<type of
207- // media>:width meta tag/
197+ // The width in pixels of the media. This is used to generate the og:<type of media>:width meta tag/
208198 width : Maybe < number > | undefined ;
209- // The alt text for the media. This is used to generate the og:<type of
210- // media>:alt meta tag.
199+ // The alt text for the media. This is used to generate the og:<type of media>:alt meta tag.
211200 altText : Maybe < string > | undefined ;
212201} ;
213202
@@ -229,6 +218,11 @@ export type SchemaType =
229218 | 'BlogPosting'
230219 | 'Thing' ;
231220
221+ /**
222+ * The `generateSeoTags` function generates the SEO title, meta, link and script (JSON Linking Data) tags for a page. It
223+ * pairs well with the SEO component in `@shopify/hydrogen` when building a Hydrogen Remix app, but can be used on its
224+ * own if you want to generate the tags yourself.
225+ */
232226export function generateSeoTags < T extends BaseSeo = Seo > ( input : T ) {
233227 const output : HeadTag [ ] = [ ] ;
234228 let ldJson : WithContext < any > = {
@@ -313,8 +307,7 @@ export function generateSeoTags<T extends BaseSeo = Seo>(input: T) {
313307 if ( media && typeof media === 'object' ) {
314308 const type = media . type || 'image' ;
315309
316- // Order matters here when adding multiple media tags
317- // @see https://ogp.me/#array
310+ // Order matters here when adding multiple media tags @see https://ogp.me/#array
318311 const normalizedMedia = media
319312 ? {
320313 url : media ?. url ,
@@ -453,8 +446,8 @@ function generateKey(tag: HeadTag, group?: string) {
453446 }
454447
455448 if ( tagName === 'meta' ) {
456- // leading 0 moves meta to the top when sorting
457- // exclude secure_url from the logic because the content is the same as url
449+ // leading 0 moves meta to the top when sorting exclude secure_url from the logic because the content is the same as
450+ // url
458451 const priority =
459452 props . content === group && ! props . property . endsWith ( 'secure_url' ) && '0' ;
460453 const groupName = [ group , priority ] ;
0 commit comments