-
-
Notifications
You must be signed in to change notification settings - Fork 650
Add structured data to Organization pages #1940
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
Changes from 5 commits
0135455
c036d07
68378a3
09729b5
bb569f7
35a9f18
13ca8aa
54b410b
2a0c1e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| import { Metadata } from 'next' | ||
| import Script from 'next/script' | ||
| import React from 'react' | ||
| import { apolloClient } from 'server/apolloClient' | ||
| import { GET_ORGANIZATION_METADATA } from 'server/queries/organizationQueries' | ||
| import { | ||
| GET_ORGANIZATION_METADATA, | ||
| GET_ORGANIZATION_DATA, | ||
| } from 'server/queries/organizationQueries' | ||
| import { generateSeoMetadata } from 'utils/metaconfig' | ||
|
|
||
| export async function generateMetadata({ | ||
|
|
@@ -28,6 +32,98 @@ export async function generateMetadata({ | |
| : null | ||
| } | ||
|
|
||
| export default function OrganizationDetailsLayout({ children }: { children: React.ReactNode }) { | ||
| return children | ||
| async function generateOrganizationStructuredData(organizationKey: string) { | ||
| // https://developers.google.com/search/docs/appearance/structured-data/organization | ||
| // https://schema.org/Organization | ||
|
|
||
| try { | ||
| const { data } = await apolloClient.query({ | ||
| query: GET_ORGANIZATION_DATA, | ||
| variables: { | ||
| login: organizationKey, | ||
| }, | ||
| }) | ||
|
|
||
| const organization = data?.organization | ||
| if (!organization) return null | ||
|
|
||
| const structuredData = { | ||
| '@context': 'https://schema.org' as const, | ||
| '@type': 'Organization' as const, | ||
| name: organization.name || organization.login, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you order the attributes alphabetically?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
| description: organization.description, | ||
| url: `https://nest.owasp.org/organizations/${organizationKey}`, | ||
| logo: organization.avatarUrl | ||
| ? { | ||
| '@type': 'ImageObject' as const, | ||
| url: organization.avatarUrl, | ||
| } | ||
| : undefined, | ||
| foundingDate: organization.createdAt, | ||
| location: organization.location | ||
| ? { | ||
| '@type': 'Place' as const, | ||
| name: organization.location, | ||
| } | ||
| : undefined, | ||
| contactPoint: organization.email | ||
| ? { | ||
| '@type': 'ContactPoint' as const, | ||
| email: organization.email, | ||
| contactType: 'general inquiry', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this recommended somewhere?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not exactly,
|
||
| } | ||
| : undefined, | ||
| sameAs: [organization.url], | ||
| memberOf: { | ||
| '@type': 'Organization' as const, | ||
| name: 'OWASP Foundation', | ||
| url: 'https://nest.owasp.org', | ||
| }, | ||
| keywords: [ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this part of a broader schema?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, its part of |
||
| organization.name, | ||
| organization.login, | ||
| 'cybersecurity', | ||
| 'application security', | ||
| 'open source', | ||
| 'OWASP', | ||
| ] | ||
| .filter(Boolean) | ||
| .join(', '), | ||
| } | ||
|
|
||
| // Remove undefined properties | ||
| Object.keys(structuredData).forEach( | ||
| (key) => structuredData[key] === undefined && delete structuredData[key] | ||
| ) | ||
|
|
||
| return structuredData | ||
| } catch { | ||
| return null | ||
| } | ||
|
arkid15r marked this conversation as resolved.
|
||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| export default async function OrganizationDetailsLayout({ | ||
| children, | ||
| params, | ||
| }: Readonly<{ | ||
| children: Readonly<React.ReactNode> | ||
| params: Promise<{ organizationKey: string }> | ||
| }>) { | ||
| const { organizationKey } = await params | ||
| const structuredData = await generateOrganizationStructuredData(organizationKey) | ||
|
|
||
| return ( | ||
| <> | ||
| {structuredData && ( | ||
| <Script | ||
| id="organization-structured-data" | ||
| type="application/ld+json" | ||
| dangerouslySetInnerHTML={{ | ||
| __html: JSON.stringify(structuredData, null, 2), | ||
| }} | ||
| /> | ||
| )} | ||
| {children} | ||
| </> | ||
| ) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add
emailas a top level field?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes