Skip to content

Commit

Permalink
Simplified metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Nov 6, 2024
1 parent d564628 commit 4bd3cda
Show file tree
Hide file tree
Showing 11 changed files with 435 additions and 551 deletions.
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@mui/base": "5.0.0-beta.61",
"@next/third-parties": "15.0.2",
"@tailwindcss/container-queries": "^0.1.1",
"@types/node": "22.8.6",
"@types/node": "22.9.0",
"@types/react": "18.3.12",
"@types/react-dom": "19.0.0-rc.1",
"algoliasearch": "^5.12.0",
Expand All @@ -27,7 +27,7 @@
"decanter": "^7.3.0",
"drupal-jsonapi-params": "^2.3.2",
"graphql": "^16.9.0",
"graphql-request": "^7.1.1",
"graphql-request": "^7.1.2",
"graphql-tag": "^2.12.6",
"html-entities": "^2.5.2",
"html-react-parser": "^5.1.18",
Expand All @@ -38,8 +38,8 @@
"react": "19.0.0-rc-fb9a90fa48-20240614",
"react-dom": "19.0.0-rc-fb9a90fa48-20240614",
"react-focus-lock": "^2.13.2",
"react-instantsearch": "^7.13.6",
"react-instantsearch-nextjs": "^0.3.16",
"react-instantsearch": "^7.13.7",
"react-instantsearch-nextjs": "^0.3.17",
"react-slick": "^0.30.2",
"react-super-responsive-table": "^6.0.0",
"react-tiny-oembed": "^1.1.0",
Expand All @@ -51,36 +51,36 @@
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.13.0",
"@eslint/js": "^9.14.0",
"@graphql-codegen/add": "^5.0.3",
"@graphql-codegen/cli": "^5.0.3",
"@graphql-codegen/import-types-preset": "^3.0.0",
"@graphql-codegen/typescript-graphql-request": "^6.2.0",
"@graphql-codegen/typescript-operations": "^4.3.1",
"@next/bundle-analyzer": "15.0.2",
"@storybook/addon-essentials": "^8.4.1",
"@storybook/addon-interactions": "^8.4.1",
"@storybook/addon-links": "^8.4.1",
"@storybook/addon-essentials": "^8.4.2",
"@storybook/addon-interactions": "^8.4.2",
"@storybook/addon-links": "^8.4.2",
"@storybook/addon-styling": "^1.3.7",
"@storybook/blocks": "^8.4.1",
"@storybook/nextjs": "^8.4.1",
"@storybook/react": "^8.4.1",
"@storybook/blocks": "^8.4.2",
"@storybook/nextjs": "^8.4.2",
"@storybook/react": "^8.4.2",
"@storybook/testing-library": "^0.2.2",
"@types/react-slick": "^0.23.13",
"concurrently": "^9.0.1",
"concurrently": "^9.1.0",
"encoding": "^0.1.13",
"eslint": "^9.13.0",
"eslint": "^9.14.0",
"eslint-config-next": "15.0.2",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-storybook": "^0.10.2",
"eslint-plugin-storybook": "^0.11.0",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.8",
"react-docgen": "^7.1.0",
"storybook": "^8.4.1",
"storybook": "^8.4.2",
"storybook-addon-module-mock": "^1.3.4",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript-eslint": "^8.12.2"
"typescript-eslint": "^8.13.0"
},
"packageManager": "[email protected]",
"resolutions": {
Expand Down
65 changes: 65 additions & 0 deletions src/components/nodes/pages/node-page-metadata.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {getConfigPageField} from "@lib/gql/gql-queries"
import {Image, StanfordBasicSiteSetting} from "@lib/gql/__generated__/drupal.d"
import {JSX} from "react"
import {OpenGraphType} from "next/dist/lib/metadata/types/opengraph-types"

type Props = {
pageTitle?: string
description?: string
image?: false | Image
children?: JSX.Element | JSX.Element[]
ogType?: OpenGraphType
twitterCard?: "summary" | "summary_large_image" | "app" | "player"
}

const NodePageMetadata = async ({
pageTitle,
description,
image,
ogType = "website",
twitterCard = "summary_large_image",
children,
}: Props) => {
const siteName =
(await getConfigPageField<StanfordBasicSiteSetting, StanfordBasicSiteSetting["suSiteName"]>(
"StanfordBasicSiteSetting",
"suSiteName"
)) || "Stanford University"

const title = pageTitle ? `${pageTitle} | ${siteName}` : siteName

return (
<>
<title>{title}</title>
<meta property="og:title" content={title} />
<meta property="og:type" content={ogType} />
<meta name="twitter:card" content={twitterCard} />
<meta name="twitter:title" content={title} />

{description && (
<>
<meta name="description" content={description} />
<meta property="og:description" content={description} />
<meta name="twitter:description" content={description} />
</>
)}

{image && (
<>
<meta property="og:image" content={image.url} />
<meta property="og:image:width" content={image.width.toString()} />
<meta property="og:image:height" content={image.height.toString()} />
{image.alt && <meta property="og:image:alt" content={image.alt} />}

<meta name="twitter:image" content={image.url} />
<meta name="twitter:image:width" content={image.width.toString()} />
<meta name="twitter:image:height" content={image.height.toString()} />
{image.alt && <meta name="twitter:image:alt" content={image.alt} />}
</>
)}

{children}
</>
)
}
export default NodePageMetadata
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
import {NodeStanfordCourse, StanfordBasicSiteSetting} from "@lib/gql/__generated__/drupal.d"
import {getConfigPageField} from "@lib/gql/gql-queries"
import {NodeStanfordCourse} from "@lib/gql/__generated__/drupal.d"
import {getCleanDescription} from "@lib/utils/text-tools"
import NodePageMetadata from "@components/nodes/pages/node-page-metadata"

type Props = {
node: NodeStanfordCourse
}
const StanfordCourseMetadata = async ({node}: Props) => {
const siteName =
(await getConfigPageField<StanfordBasicSiteSetting, StanfordBasicSiteSetting["suSiteName"]>(
"StanfordBasicSiteSetting",
"suSiteName"
)) || "Stanford University"

const pageTitle = `${node.title} | ${siteName}`
const StanfordCourseMetadata = ({node}: Props) => {
const description = getCleanDescription(node.body?.processed)

return (
<>
<title>{pageTitle}</title>
<meta name="description" content={description} />
<meta property="og:title" content={pageTitle} />
<meta property="og:description" content={description} />

<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={pageTitle} />
<meta name="twitter:description" content={description} />
</>
)
return <NodePageMetadata pageTitle={node.title} description={description} />
}
export default StanfordCourseMetadata
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
import {NodeStanfordEventSeries, StanfordBasicSiteSetting} from "@lib/gql/__generated__/drupal.d"
import {getConfigPageField} from "@lib/gql/gql-queries"
import {NodeStanfordEventSeries} from "@lib/gql/__generated__/drupal.d"
import {getFirstText} from "@lib/utils/text-tools"
import NodePageMetadata from "@components/nodes/pages/node-page-metadata"

type Props = {
node: NodeStanfordEventSeries
}
const StanfordEventSeriesMetadata = async ({node}: Props) => {
const siteName =
(await getConfigPageField<StanfordBasicSiteSetting, StanfordBasicSiteSetting["suSiteName"]>(
"StanfordBasicSiteSetting",
"suSiteName"
)) || "Stanford University"

const pageTitle = `${node.title} | ${siteName}`
const StanfordEventSeriesMetadata = ({node}: Props) => {
const description = node.suEventSeriesSubheadline || getFirstText(node.suEventSeriesComponents)

return (
<>
<title>{pageTitle}</title>
<meta name="description" content={description} />
<meta property="og:title" content={pageTitle} />
<meta property="og:description" content={description} />

<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={pageTitle} />
<meta name="twitter:description" content={description} />
</>
)
return <NodePageMetadata pageTitle={node.title} description={description} />
}
export default StanfordEventSeriesMetadata
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
import {NodeStanfordEvent, StanfordBasicSiteSetting} from "@lib/gql/__generated__/drupal.d"
import {getConfigPageField} from "@lib/gql/gql-queries"
import {NodeStanfordEvent} from "@lib/gql/__generated__/drupal.d"
import {getCleanDescription} from "@lib/utils/text-tools"
import NodePageMetadata from "@components/nodes/pages/node-page-metadata"

type Props = {
node: NodeStanfordEvent
}
const StanfordEventMetadata = async ({node}: Props) => {
const siteName =
(await getConfigPageField<StanfordBasicSiteSetting, StanfordBasicSiteSetting["suSiteName"]>(
"StanfordBasicSiteSetting",
"suSiteName"
)) || "Stanford University"

const pageTitle = `${node.title} | ${siteName}`
const StanfordEventMetadata = ({node}: Props) => {
const description = node.suEventSubheadline || getCleanDescription(node.body?.processed)

return (
<>
<title>{pageTitle}</title>
<meta name="description" content={description} />
<meta property="og:title" content={pageTitle} />
<meta property="og:description" content={description} />

<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={pageTitle} />
<meta name="twitter:description" content={description} />
</>
)
return <NodePageMetadata pageTitle={node.title} description={description} />
}
export default StanfordEventMetadata
Original file line number Diff line number Diff line change
@@ -1,53 +1,21 @@
import {NodeStanfordNews, StanfordBasicSiteSetting} from "@lib/gql/__generated__/drupal.d"
import {getConfigPageField} from "@lib/gql/gql-queries"
import {NodeStanfordNews} from "@lib/gql/__generated__/drupal.d"
import {getFirstText} from "@lib/utils/text-tools"
import NodePageMetadata from "@components/nodes/pages/node-page-metadata"

type Props = {
node: NodeStanfordNews
}
const StanfordNewsMetadata = async ({node}: Props) => {
const siteName =
(await getConfigPageField<StanfordBasicSiteSetting, StanfordBasicSiteSetting["suSiteName"]>(
"StanfordBasicSiteSetting",
"suSiteName"
)) || "Stanford University"

const pageTitle = `${node.title} | ${siteName}`
const StanfordNewsMetadata = ({node}: Props) => {
const description = node.suNewsDek || getFirstText(node.suNewsComponents)
const image =
node.suNewsFeaturedMedia?.mediaImage ||
(node.suNewsBanner?.__typename === "MediaImage" && node.suNewsBanner.mediaImage)

return (
<>
<title>{pageTitle}</title>
<meta name="description" content={description} />
<meta property="og:title" content={pageTitle} />
<meta property="og:description" content={description} />
<meta property="og:type" content="article" />
<NodePageMetadata pageTitle={node.title} description={description} image={image} ogType="article">
{node.suNewsPublishingDate?.time && (
<meta property="article:published_time" content={new Date(node.suNewsPublishingDate.time).toISOString()} />
)}

{image && (
<>
<meta property="og:image" content={image.url} />
<meta property="og:image:width" content={image.width.toString()} />
<meta property="og:image:height" content={image.height.toString()} />
{image.alt && <meta property="og:image:alt" content={image.alt} />}

<meta name="twitter:image" content={image.url} />
<meta name="twitter:image:width" content={image.width.toString()} />
<meta name="twitter:image:height" content={image.height.toString()} />
{image.alt && <meta name="twitter:image:alt" content={image.alt} />}
</>
)}

<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={pageTitle} />
<meta name="twitter:description" content={description} />
</>
</NodePageMetadata>
)
}
export default StanfordNewsMetadata
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import {NodeStanfordPage, StanfordBasicSiteSetting} from "@lib/gql/__generated__/drupal.d"
import {getConfigPageField} from "@lib/gql/gql-queries"
import {NodeStanfordPage} from "@lib/gql/__generated__/drupal.d"
import {getFirstText} from "@lib/utils/text-tools"
import NodePageMetadata from "@components/nodes/pages/node-page-metadata"

type Props = {
node: NodeStanfordPage
isHome?: true
}
const StanfordPageMetadata = async ({node, isHome}: Props) => {
const siteName =
(await getConfigPageField<StanfordBasicSiteSetting, StanfordBasicSiteSetting["suSiteName"]>(
"StanfordBasicSiteSetting",
"suSiteName"
)) || "Stanford University"

const StanfordPageMetadata = ({node, isHome}: Props) => {
const pageTitleBannerImage =
node.suPageBanner?.__typename === "ParagraphStanfordPageTitleBanner" &&
node.suPageBanner.suTitleBannerImage.mediaImage
Expand All @@ -21,35 +15,7 @@ const StanfordPageMetadata = async ({node, isHome}: Props) => {
const image = node.suPageImage?.mediaImage || pageTitleBannerImage || bannerImage

const description = node.suPageDescription || getFirstText(node.suPageComponents)
const pageTitle = isHome ? siteName : `${node.title} | ${siteName}`

return (
<>
<title>{pageTitle}</title>
<meta name="description" content={description} />
<meta property="og:title" content={pageTitle} />
<meta property="og:description" content={description} />

{image && (
<>
<meta property="og:image" content={image.url} />
<meta property="og:image:width" content={image.width.toString()} />
<meta property="og:image:height" content={image.height.toString()} />
{image.alt && <meta property="og:image:alt" content={image.alt} />}

<meta name="twitter:image" content={image.url} />
<meta name="twitter:image:width" content={image.width.toString()} />
<meta name="twitter:image:height" content={image.height.toString()} />
{image.alt && <meta name="twitter:image:alt" content={image.alt} />}
</>
)}

<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={pageTitle} />
<meta name="twitter:description" content={description} />
</>
)
return <NodePageMetadata pageTitle={isHome ? undefined : node.title} description={description} image={image} />
}

export default StanfordPageMetadata
Loading

0 comments on commit 4bd3cda

Please sign in to comment.