Skip to content

Commit

Permalink
Improve meta handling (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
carletex committed May 7, 2024
1 parent 0f9d9db commit 3ff50f2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 48 deletions.
47 changes: 5 additions & 42 deletions packages/nextjs/app/layout.tsx
@@ -1,50 +1,13 @@
import "@rainbow-me/rainbowkit/styles.css";
import { Metadata } from "next";
import { ScaffoldEthAppWithProviders } from "~~/components/ScaffoldEthAppWithProviders";
import { ThemeProvider } from "~~/components/ThemeProvider";
import "~~/styles/globals.css";
import { getMetadata } from "~~/utils/scaffold-eth/getMetadata";

const baseUrl = process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: `http://localhost:${process.env.PORT || 3000}`;
const imageUrl = `${baseUrl}/thumbnail.jpg`;

const title = "Scaffold-ETH 2 App";
const titleTemplate = "%s | Scaffold-ETH 2";
const description = "Built with 🏗 Scaffold-ETH 2";

export const metadata: Metadata = {
metadataBase: new URL(baseUrl),
title: {
default: title,
template: titleTemplate,
},
description,
openGraph: {
title: {
default: title,
template: titleTemplate,
},
description,
images: [
{
url: imageUrl,
},
],
},
twitter: {
card: "summary_large_image",
images: [imageUrl],
title: {
default: title,
template: titleTemplate,
},
description,
},
icons: {
icon: [{ url: "/favicon.png", sizes: "32x32", type: "image/png" }],
},
};
export const metadata = getMetadata({
title: "Scaffold-ETH 2 App",
description: "Built with 🏗 Scaffold-ETH 2",
});

const ScaffoldEthApp = ({ children }: { children: React.ReactNode }) => {
return (
Expand Down
24 changes: 18 additions & 6 deletions packages/nextjs/utils/scaffold-eth/getMetadata.ts
@@ -1,5 +1,10 @@
import type { Metadata } from "next";

const baseUrl = process.env.VERCEL_PROJECT_PRODUCTION_URL
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
: `http://localhost:${process.env.PORT || 3000}`;
const titleTemplate = "%s | Scaffold-ETH 2";

export const getMetadata = ({
title,
description,
Expand All @@ -9,15 +14,19 @@ export const getMetadata = ({
description: string;
imageRelativePath?: string;
}): Metadata => {
const baseUrl = process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: `http://localhost:${process.env.PORT || 3000}`;
const imageUrl = `${baseUrl}${imageRelativePath}`;

return {
title: title,
title: {
default: title,
template: titleTemplate,
},
description: description,
openGraph: {
title: title,
title: {
default: title,
template: titleTemplate,
},
description: description,
images: [
{
Expand All @@ -26,7 +35,10 @@ export const getMetadata = ({
],
},
twitter: {
title: title,
title: {
default: title,
template: titleTemplate,
},
description: description,
images: [imageUrl],
},
Expand Down

0 comments on commit 3ff50f2

Please sign in to comment.