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

feat: SEO tokens page #136

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/pretty-tables-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stackspulse": patch
---

Add SEO to new tokens page.
70 changes: 70 additions & 0 deletions apps/web/src/app/tokens/[token]/opengraph-image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { env } from "@/env";
import { stacksTokensApi } from "@/lib/stacks";
import { notFound } from "next/navigation";
import { ImageResponse } from "next/og";

export const runtime = "edge";

export const alt = "About Protocol";
export const size = {
width: 1012,
height: 506,
};

export const contentType = "image/png";

interface PageProps {
params: { token: string };
}

export default async function Image({ params }: PageProps) {
const tokenInfo = await stacksTokensApi
.getFtMetadata(params.token)
.catch((error) => {
if (error.status === 404) {
return null;
}
throw error;
});
if (!tokenInfo) {
notFound();
}

return new ImageResponse(
<div
style={{
fontSize: 60,
width: "100%",
height: "100%",
display: "flex",
padding: "60px",
alignItems: "center",
justifyContent: "flex-start",
background: `url("${env.NEXT_PUBLIC_BASE_URL}/og/protocol-background.png")`,
backgroundSize: "cover",
backgroundPosition: "center center",
backgroundRepeat: "no-repeat",
color: "white",
}}
>
<div tw="flex items-center">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
tw="mr-4"
src={tokenInfo.image_thumbnail_uri || tokenInfo.image_uri}
alt={alt}
height={100}
width={100}
style={{
borderRadius: "50%",
border: "2px solid white",
}}
/>
{tokenInfo.symbol}
</div>
</div>,
{
...size,
},
);
}
25 changes: 25 additions & 0 deletions apps/web/src/app/tokens/[token]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TokenStats } from "@/components/Token/TokenStats";
import { TokenTransactionsVolume } from "@/components/Token/TokenTransactionsVolume";
import { stacksTokensApi } from "@/lib/stacks";
import { Container } from "@radix-ui/themes";
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { Suspense } from "react";

Expand All @@ -13,6 +14,30 @@ interface PageProps {
params: { token: string };
}

export async function generateMetadata({
params,
}: PageProps): Promise<Metadata> {
const tokenInfo = await stacksTokensApi
.getFtMetadata(params.token)
.catch((error) => {
if (error.status === 404) {
return null;
}
throw error;
});
if (!tokenInfo) {
notFound();
}

return {
title: `stackspulse - ${tokenInfo.name}`,
description: `Get the latest ${tokenInfo.name} on-chain stats. Explore holders, transaction volume, and more..`,
alternates: {
canonical: `/tokens/${params.token}`,
},
};
}

export default async function ProtocolPage({ params }: PageProps) {
const tokenInfo = await stacksTokensApi
.getFtMetadata(params.token)
Expand Down