Skip to content

Commit

Permalink
Merge pull request #939 from hirosystems/develop
Browse files Browse the repository at this point in the history
chore/updates
  • Loading branch information
ryanwaits authored Jan 22, 2025
2 parents 99b28e1 + 536c127 commit 6303f74
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 37 deletions.
42 changes: 6 additions & 36 deletions app/(docs)/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RollButton } from "fumadocs-ui/components/roll-button";
import { DocsPage, DocsBody } from "fumadocs-ui/page";
import { notFound } from "next/navigation";
import { utils, type Page } from "@/utils/source";
import { createMetadata } from "@/utils/metadata";
import { createMetadata, getRouteMetadata } from "@/utils/metadata";

interface Param {
slug: string[];
Expand Down Expand Up @@ -71,45 +71,15 @@ function Category({ page }: { page: Page }): JSX.Element {
);
}

const metadata: Metadata = {
metadataBase: new URL(
`https://${process.env.NEXT_PUBLIC_VERCEL_URL}` || "https://docs.hiro.so"
),
title: "Hiro Docs",
description:
"All the developer docs, guides and resources you need to build on Bitcoin layers.",
openGraph: {
title: "Hiro Docs",
description:
"All the developer docs, guides and resources you need to build on Bitcoin layers.",
url: "https://docs.hiro.so",
siteName: "Hiro Docs",
images: [
{
url: "/og.jpg",
width: 800,
height: 600,
},
],
locale: "en_US",
type: "website",
},
twitter: {
card: "summary_large_image",
title: "Hiro Docs",
description:
"All the developer docs, guides and resources you need to build on Bitcoin layers.",
creator: "@hirosystems",
images: ["/og.jpg"], // Must be an absolute URL
},
};

export async function generateMetadata(props: {
params: Promise<{ slug?: string[] }>;
}) {
}): Promise<Metadata> {
const params = await props.params;
const page = utils.getPage(params.slug);
if (!page) notFound();

return metadata;
const path = `/${params.slug?.join("/") || ""}`;
const routeMetadata = getRouteMetadata(path);

return createMetadata(routeMetadata);
}
Binary file added public/images/hiro-hacks-season-one.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 71 additions & 1 deletion utils/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,82 @@
import type { Metadata } from "next/types";

export function createMetadata(override: Metadata): Metadata {
const defaultMetadata: Metadata = {
title: "Hiro Docs",
description:
"All the developer docs, guides and resources you need to build on Bitcoin layers.",
openGraph: {
title: "Hiro Docs",
description:
"All the developer docs, guides and resources you need to build on Bitcoin layers.",
url: "https://docs.hiro.so",
siteName: "Hiro Docs",
images: [
{
url: "/og.jpg",
width: 800,
height: 600,
},
],
locale: "en_US",
type: "website",
},
twitter: {
card: "summary_large_image",
title: "Hiro Docs",
description:
"All the developer docs, guides and resources you need to build on Bitcoin layers.",
creator: "@hirosystems",
images: ["/og.jpg"],
},
};

const hiroHacksMetadata: Partial<Metadata> = {
title: "Hiro Hacks - Season 1",
description:
"Join Hiro Hacks Season 1 and build on Bitcoin layers with our monthly themed challenges.",
openGraph: {
title: "Hiro Hacks - Season 1",
description:
"Join Hiro Hacks Season 1 and build on Bitcoin layers with our monthly themed challenges.",
images: [
{
url: "/images/hiro-hacks-season-one.png",
width: 800,
height: 600,
},
],
},
twitter: {
title: "Hiro Hacks - Season 1",
description:
"Join Hiro Hacks Season 1 and build on Bitcoin layers with our monthly themed challenges.",
images: ["/images/hiro-hacks-season-one.png"],
},
};

export function createMetadata(override: Partial<Metadata>): Metadata {
return {
...defaultMetadata,
...override,
openGraph: {
...defaultMetadata.openGraph,
...override.openGraph,
},
twitter: {
...defaultMetadata.twitter,
...override.twitter,
},
};
}

export const baseUrl =
process.env.NODE_ENV === "development"
? new URL("http://localhost:3000")
: new URL(`https://${process.env.NEXT_PUBLIC_VERCEL_URL!}`);

export function getRouteMetadata(path: string): Partial<Metadata> {
if (path.startsWith("/stacks/hacks")) {
return hiroHacksMetadata;
}
return {};
}

0 comments on commit 6303f74

Please sign in to comment.