Skip to content

Commit

Permalink
Merge pull request #167 from nr2f1/publications-metadata
Browse files Browse the repository at this point in the history
feat: add schema.org metadata to publications page
  • Loading branch information
pataruco authored Jan 22, 2025
2 parents 55dd8d7 + e3bf993 commit 8e73027
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
27 changes: 22 additions & 5 deletions website/src/app/[lang]/publications/page-body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
patientResearchContentId,
} from '@models/paragraphs';
import { createHashLink } from '@shared/utils/hash-links';
import type { ScholarlyArticle, WithContext } from 'schema-dts';

interface RegisterPageBodyProps {
lang: AvailableLocale;
Expand Down Expand Up @@ -95,11 +96,27 @@ const PublicationsByYear: React.FC<PublicationsByYearProps> = ({
<div className={styles['publications__by-year']} key={crypto.randomUUID()}>
<h3>{year}</h3>
<ul>
{publications.map(({ title, link }) => (
<li key={crypto.randomUUID()}>
<a href={link}>{title}</a>
</li>
))}
{publications.map(({ title, link }) => {
const scholaryArticle: WithContext<ScholarlyArticle> = {
'@context': 'https://schema.org',
'@type': 'ScholarlyArticle',
name: title,
url: link,
};

return (
<li key={crypto.randomUUID()}>
<script
type="application/ld+json"
// biome-ignore lint/security/noDangerouslySetInnerHtml: this is a safe usage
dangerouslySetInnerHTML={{
__html: JSON.stringify(scholaryArticle),
}}
/>
<a href={link}>{title}</a>
</li>
);
})}
</ul>
</div>
));
Expand Down
28 changes: 7 additions & 21 deletions website/src/app/[lang]/publications/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
GetMetadataDocument,
type GetMetadataQuery,
} from '@graphql/queries/metadata/index.generated';
import { registerPatientPageMetadataId } from '@models/metadata';
import { publicationsPageMetadataId } from '@models/metadata';
import type { PagePropsWithLocale } from '@shared/types/page-with-locale-params';
import type { Metadata, NextPage } from 'next';
import type { Graph, MedicalStudy, WebPage, WithContext } from 'schema-dts';
import type { Graph, WebPage, WithContext } from 'schema-dts';
import RegisterPageBody from './page-body';
import PublicationsPageHeader from './page-header';

Expand All @@ -26,36 +26,22 @@ const Page: NextPage<PagePropsWithLocale> = async ({ params }) => {
query: GetMetadataDocument,
variables: {
locale: lang,
id: registerPatientPageMetadataId,
id: publicationsPageMetadataId,
},
});

const medicalStudy: WithContext<MedicalStudy> = {
'@context': 'https://schema.org',
'@type': 'MedicalStudy',
name: title,
description,
potentialAction: [
{
'@type': 'RegisterAction',
target: `https://nr2f1.org/${lang}/register-patient`,
name: title,
},
],
};

// TODO: Change schema
const webPage: WithContext<WebPage> = {
'@context': 'https://schema.org',
'@type': 'WebPage',
url: `https://nr2f1.org/${lang}/register-a-patient`,
url: `https://nr2f1.org/${lang}/publications`,
name: title,
description,
inLanguage: lang,
};

const jsonLd: Graph = {
'@context': 'https://schema.org',
'@graph': [medicalStudy, webPage],
'@graph': [webPage],
};

return (
Expand Down Expand Up @@ -90,7 +76,7 @@ export async function generateMetadata({
query: GetMetadataDocument,
variables: {
locale: lang,
id: registerPatientPageMetadataId,
id: publicationsPageMetadataId,
},
});

Expand Down
1 change: 1 addition & 0 deletions website/src/app/[lang]/register-a-patient/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const Page: NextPage<PagePropsWithLocale> = async ({ params }) => {
'@type': 'WebPage',
url: `https://nr2f1.org/${lang}/register-a-patient`,
name: title,
description,
inLanguage: lang,
};

Expand Down
1 change: 1 addition & 0 deletions website/src/models/metadata/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const homepageMetadataId = '4CqS9EKVc0euRhzQasESTR';
export const registerPatientPageMetadataId = 'EolZvaSlFMYGxwOjeHC0u';
export const publicationsPageMetadataId = '5sw3wnid1UWXJcg7SprVK8';

0 comments on commit 8e73027

Please sign in to comment.