-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add open graph and twitter meta tags for anvil-cmg (#4797) #4799
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
Open
frano-m
wants to merge
10
commits into
main
Choose a base branch
from
fran/4797-anvil-cmg-og-meta
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
26ae4c7
feat: add open graph and twitter meta tags for anvil-cmg (#4797)
frano-m 3ac0682
feat: add page titles and descriptions to all anvil-cmg pages (#4797)
frano-m fbbd6ae
fix: remove anvil references from shared page descriptions (#4797)
frano-m 4e38beb
refactor: move og image to site config, derive entity descriptions fr…
frano-m f8188e4
fix: use null instead of undefined for serializable page props (#4797)
frano-m 46c0f12
chore: switch og image to 512x512 brand icon, match anvil-portal summ…
frano-m 617ca09
refactor: source page title and description from mdx frontmatter (#4797)
frano-m 8a7179b
feat: source og description from site config and derive entity detail…
frano-m 2079c78
refactor: drop entity detail description override (#4797)
frano-m 86857b9
fix: address copilot review feedback for og meta (#4797)
frano-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,9 @@ _templates | |
| # favicons | ||
| /public/favicons/* | ||
|
|
||
| # og images | ||
| /public/og/* | ||
|
|
||
| /files/**/out/ | ||
|
|
||
| #Python | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import NextHead from "next/head"; | ||
| import { useRouter } from "next/router"; | ||
| import { JSX } from "react"; | ||
| import type { OgMetaProps } from "./types"; | ||
|
|
||
| /** | ||
| * Builds the canonical path from the router's asPath, stripping query and hash. | ||
| * @param asPath - The router's asPath value. | ||
| * @returns clean path. | ||
| */ | ||
| function buildPath(asPath: string): string { | ||
| return asPath.split("?")[0].split("#")[0]; | ||
| } | ||
|
|
||
| /** | ||
| * Builds the OG title from the page title and app title. | ||
| * @param appTitle - The application title. | ||
| * @param pageTitle - The page-specific title. | ||
| * @returns formatted title. | ||
| */ | ||
| function buildTitle(appTitle: string, pageTitle?: string | null): string { | ||
| if (pageTitle && pageTitle !== appTitle) { | ||
| return `${pageTitle} - ${appTitle}`; | ||
| } | ||
| return appTitle; | ||
| } | ||
|
|
||
| /** | ||
| * Renders Open Graph and Twitter meta tags for rich link sharing. | ||
| * @param props - The component props. | ||
| * @param props.appTitle - The application title. | ||
| * @param props.browserURL - The site's base URL. | ||
| * @param props.defaultDescription - Fallback description when no page description is provided. | ||
| * @param props.pageDescription - Page-specific description. | ||
| * @param props.pageTitle - Page-specific title. | ||
| * @returns head element with meta tags. | ||
| */ | ||
| export const OgMeta = ({ | ||
| appTitle, | ||
| browserURL, | ||
| defaultDescription, | ||
| pageDescription, | ||
| pageTitle, | ||
| }: OgMetaProps): JSX.Element => { | ||
| const { asPath } = useRouter(); | ||
| const description = pageDescription || defaultDescription; | ||
| const image = `${browserURL}/og/og-image.png`; | ||
| const path = buildPath(asPath); | ||
| const title = buildTitle(appTitle, pageTitle); | ||
| const url = `${browserURL}${path}`; | ||
| return ( | ||
| <NextHead> | ||
| <meta key="description" content={description} name="description" /> | ||
| <meta | ||
| key="og:description" | ||
| content={description} | ||
| property="og:description" | ||
| /> | ||
| <meta key="og:image" content={image} property="og:image" /> | ||
| <meta key="og:image:height" content="512" property="og:image:height" /> | ||
| <meta key="og:image:width" content="512" property="og:image:width" /> | ||
| <meta key="og:site_name" content={appTitle} property="og:site_name" /> | ||
| <meta key="og:title" content={title} property="og:title" /> | ||
| <meta key="og:type" content="website" property="og:type" /> | ||
| <meta key="og:url" content={url} property="og:url" /> | ||
| <meta key="twitter:card" content="summary" name="twitter:card" /> | ||
| <meta key="twitter:image" content={image} name="twitter:image" /> | ||
| </NextHead> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export interface OgMetaProps { | ||
| appTitle: string; | ||
| browserURL: string; | ||
| defaultDescription: string; | ||
| pageDescription?: string | null; | ||
| pageTitle?: string | null; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| --- | ||
| pageTitle: "APIs" | ||
| --- | ||
|
|
||
| <Breadcrumbs | ||
| breadcrumbs={[ | ||
| { path: "/projects", text: "LungMAP Data Explorer" }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.