Skip to content
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

Improve meta handling (NOT included => default Farcaster Frame) #811

Merged
merged 8 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 5 additions & 42 deletions packages/nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -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
31 changes: 25 additions & 6 deletions packages/nextjs/utils/scaffold-eth/getMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { Metadata } from "next";

const baseUrl = process.env.VERCEL_URL
? `https://${process.env.VERCEL_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,9 +35,19 @@ export const getMetadata = ({
],
},
twitter: {
title: title,
title: {
default: title,
template: titleTemplate,
},
description: description,
images: [imageUrl],
},
other: {
"fc:frame": "vNext",
"fc:frame:image": imageUrl,
"fc:frame:button:1": "Open my 🏗️ Scaffold-ETH 2 dApp",
damianmarti marked this conversation as resolved.
Show resolved Hide resolved
"fc:frame:button:1:action": "link",
"fc:frame:button:1:target": baseUrl,
technophile-04 marked this conversation as resolved.
Show resolved Hide resolved
},
};
};
Loading