Skip to content

Commit

Permalink
wip: bring back to server rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
qqpann committed Jan 11, 2025
1 parent 0d0876c commit 1d65776
Showing 1 changed file with 57 additions and 57 deletions.
114 changes: 57 additions & 57 deletions www/app/[locale]/blog/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,70 @@ import { notFound } from "next/navigation";
import { BlogPageDetail } from "~/components/blog/detail";
import { nc } from "~/src/notcms/schema";

// ISR: https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration
// // ISR: https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration

// Next.js will invalidate the cache when a
// request comes in, at most once every 60 seconds.
export const revalidate = 60;
// // Next.js will invalidate the cache when a
// // request comes in, at most once every 60 seconds.
// export const revalidate = 60;

// We'll prerender only the params from `generateStaticParams` at build time.
// If a request comes in for a path that hasn't been generated,
// Next.js will server-render the page on-demand.
export const dynamicParams = true; // or false, to 404 on unknown paths
// // We'll prerender only the params from `generateStaticParams` at build time.
// // If a request comes in for a path that hasn't been generated,
// // Next.js will server-render the page on-demand.
// export const dynamicParams = true; // or false, to 404 on unknown paths

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

export async function generateStaticParams() {
const [pages, error] = await nc.query.blog.list();

if (error || !pages) {
console.error("Failed to fetch blog list:", error);
return [];
}

// 静的に生成するパスのリスト
return pages
.filter((p) => p.properties.published)
.map((page: any) => ({
id: page.id,
}));
}

// SEOメタタグ用の動的Metadata
export async function generateMetadata({
params,
}: PageProps): Promise<Metadata> {
const { id } = params;
const [page, error] = await nc.query.blog.get(id);

if (error || !page) {
return {
title: "Page Not Found",
};
}

const thumbnailUrl =
page.properties.thumbnails?.[0] ?? "/opengraph-image.jpg";

return {
title: page.title ?? "Blog Page",
description: page.properties.description ?? "Blog post",
openGraph: {
title: page.title ?? "Blog Page",
description: page.properties.description ?? "Blog post",
images: [{ url: thumbnailUrl }],
type: "article",
},
twitter: {
card: "summary_large_image",
title: page.title ?? "Blog Page",
description: page.properties.description ?? "Blog post",
images: [thumbnailUrl],
},
};
}
// export async function generateStaticParams() {
// const [pages, error] = await nc.query.blog.list();

// if (error || !pages) {
// console.error("Failed to fetch blog list:", error);
// return [];
// }

// // 静的に生成するパスのリスト
// return pages
// .filter((p) => p.properties.published)
// .map((page: any) => ({
// id: page.id,
// }));
// }

// // SEOメタタグ用の動的Metadata
// export async function generateMetadata({
// params,
// }: PageProps): Promise<Metadata> {
// const { id } = params;
// const [page, error] = await nc.query.blog.get(id);

// if (error || !page) {
// return {
// title: "Page Not Found",
// };
// }

// const thumbnailUrl =
// page.properties.thumbnails?.[0] ?? "/opengraph-image.jpg";

// return {
// title: page.title ?? "Blog Page",
// description: page.properties.description ?? "Blog post",
// openGraph: {
// title: page.title ?? "Blog Page",
// description: page.properties.description ?? "Blog post",
// images: [{ url: thumbnailUrl }],
// type: "article",
// },
// twitter: {
// card: "summary_large_image",
// title: page.title ?? "Blog Page",
// description: page.properties.description ?? "Blog post",
// images: [thumbnailUrl],
// },
// };
// }

export default async function Page({ params }: PageProps) {
const { id } = params;
Expand Down

0 comments on commit 1d65776

Please sign in to comment.