Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding organization structured data json #2623

Merged
merged 18 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 102 additions & 2 deletions packages/core/cms/faststore/content-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"title": {
"title": "Default page title",
"description": "Display this title when no other tile is available",
"description": "Display this title when no other tile is available.",
"type": "string",
"default": "FastStore Starter"
},
Expand Down Expand Up @@ -98,8 +98,108 @@
},
"publisherId": {
"title": "Publisher ID",
"description": "Uses to identifier to reference the publisher. E.g.: #website",
"description": "A unique identifier used to reference the publisher. This can be a descriptive value (e.g., `#organization`) or a full URL (e.g., `https://example.com/publisher`).",
"type": "string"
},
"organization": {
"title": "Organization",
"type": "object",
"required": ["name", "url"],
"properties": {
"name": {
"title": "Organization name",
"type": "string",
"default": "VTEX"
},
"legalName": {
"title": "Organization legal name",
"type": "string",
"default": "VTEX Commerce"
},
"id": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: what is this id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The id serves as a reference key, allowing us to use it elsewhere in our structured data. Our client has listed it as a required attribute, as they seem to rely on it frequently.

Maybe I should update this description 🙇

There is this link for reference.

"title": "Organization ID",
"description": "A unique reference for the organization. This can be a descriptive value (e.g., #organization) or a full URL (e.g.,https://example.com/organization).",
"type": "string"
},
"url": {
"title": "Organization URL",
"type": "string",
"default": "https://vtex.com"
},
"sameAs": {
"title": "Organization URLs",
"type": "array",
"description": "The URL of a page on another website with additional information about your organization. For example, a URL to your organization's profile page on a social media or review site.",
"items": {
"type": "string"
}
},
"logo": {
"title": "Organization logo URL",
"description": "A logo that is representative of your organization. Image guidelines: https://developers.google.com/search/docs/appearance/structured-data/organization",
"type": "string"
},
"image": {
"title": "Organization image/logo object",
"description": "An image that is representative of your organization. Image guidelines: https://developers.google.com/search/docs/appearance/structured-data/organization",
"required": ["url"],
"type": "object",
"properties": {
"url": {
"title": "Organization image URL",
"description": "The URL of the image. Make sure the url is crawlable and indexable.",
"type": "string"
},
"caption": {
"title": "Organization image caption",
"description": "A short description of the image.",
"type": "string"
},
"id": {
"title": "Organization image ID",
"description": "A unique reference for the image. This can be a descriptive value (e.g., #logo) or a full URL (e.g.,https://example.com/logo).",
"type": "string"
}
}
},
"email": {
"title": "Organization email",
"description": "The email address to contact your business",
"type": "string"
},
"telephone": {
"title": "Organization phone",
"description": "A business phone number. Be sure to include the country code and area code in the phone number.",
"type": "string"
},
"address": {
"title": "Organization address",
"description": "The address (physical or mailing) of your organization, if applicable.",
"type": "object",
"properties": {
"streetAddress": {
"title": "Street Address",
"description": "The full street address of your postal address.",
"type": "string"
},
"addressLocality": {
"title": "City",
"description": "The city of your postal address.",
"type": "string"
},
"addressCountry": {
"title": "Country",
"description": "The country of your postal address. Recommended to be in 2-letter ISO 3166-1 alpha-2 format, for example 'BR','US'.",
"type": "string"
},
"postalCode": {
"title": "Postal Code",
"description": "The postal code of your postal address.",
"type": "string"
}
}
}
}
}
}
}
Expand Down
55 changes: 54 additions & 1 deletion packages/core/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Locator } from '@vtex/client-cms'
import type { GetStaticProps } from 'next'
import { NextSeo, SiteLinksSearchBoxJsonLd } from 'next-seo'
import { NextSeo, OrganizationJsonLd, SiteLinksSearchBoxJsonLd } from 'next-seo'

import RenderSections from 'src/components/cms/RenderSections'
import type { PageContentType } from 'src/server/cms'
Expand Down Expand Up @@ -31,6 +31,14 @@ function Page({
}

const publisherId = settings?.seo?.publisherId ?? storeConfig.seo.publisherId
const orgAddress = settings?.seo?.organization?.address

const address =
orgAddress && Boolean(Object.values(orgAddress).find(Boolean))
? Object.fromEntries(
Object.entries(orgAddress).filter(([, value]) => Boolean(value))
)
: null

return (
<>
Expand Down Expand Up @@ -61,6 +69,51 @@ function Page({
{...(publisherId && { publisher: { '@id': publisherId } })}
/>

{settings?.seo?.organization && (
<OrganizationJsonLd
type="Organization"
{...(settings?.seo?.organization?.id && {
id: settings.seo.organization.id,
})}
{...(settings?.seo?.organization?.url && {
url: settings.seo.organization.url,
})}
{...(settings?.seo?.organization?.sameAs?.length && {
sameAs: settings.seo.organization.sameAs,
})}
{...(settings?.seo?.organization?.logo && {
logo: settings.seo.organization.logo,
})}
{...(settings?.seo?.organization?.name && {
name: settings.seo.organization.name,
})}
{...(settings?.seo?.organization?.legalName && {
legalName: settings.seo.organization.legalName,
})}
{...(settings?.seo?.organization?.email && {
email: settings.seo.organization.email,
})}
{...(settings?.seo?.organization?.telephone && {
telephone: settings.seo.organization.telephone,
})}
{...(settings?.seo?.organization?.image && {
image: {
type: 'ImageObject',
...(settings.seo.organization.image.url && {
url: settings.seo.organization.image.url,
}),
...(settings.seo.organization.image.caption && {
caption: settings.seo.organization.image.caption,
}),
...(settings.seo.organization.image.id && {
id: settings.seo.organization.image.id,
}),
},
})}
{...(address && { address })}
/>
)}

{/*
WARNING: Do not import or render components from any
other folder than '../components/sections' in here.
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/server/cms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ export type PageContentType = ContentData & {
canonical?: string
name?: string
publisherId?: string
organization: {
id?: string
url?: string
sameAs?: string[]
logo?: string
image?: {
url: string
caption: string
id: string
}
name: string
legalName?: string
email?: string
telephone?: string
address?: {
streetAddress?: string
addressLocality?: string
postalCode?: string
addressCountry?: string
}
}
}
}
}
Expand Down
Loading