Skip to content

Open-source status page, incident response and uptime monitoring

2.7 KB
Raw Blame
import type { Metadata } from "next";
import Image from "next/image";
import { notFound } from "next/navigation";

import { CustomMDX } from "../../../../content/mdx";
import { sections } from "../../../../content/sections";
import { getUseCasePages } from "../../../../content/utils";
import { JsonLd } from "../../../../lib/metadata/json-ld";
import { getPageMetadata } from "../../../../lib/metadata/shared-metadata";
import {
  createJsonLDGraph,
  getJsonLDBlogPosting,
  getJsonLDFAQPage,
  getJsonLDHowTo,
  getJsonLDOrganization,
  getJsonLDSectionBreadcrumb,
  getJsonLDWebPage,
} from "../../../../lib/metadata/structured-data";
import { ContentMetadata } from "../../content-metadata";
import { ContentPagination } from "../../content-pagination";

export const dynamicParams = false;

export async function generateStaticParams() {
  const posts = getUseCasePages();

  return posts.map((post) => ({
    slug: post.slug,
  }));
}

export async function generateMetadata({
  params,
}: {
  params: Promise<{ slug: string }>;
}): Promise<Metadata | undefined> {
  const { slug } = await params;
  const post = getUseCasePages().find((post) => post.slug === slug);
  if (!post) {
    return;
  }

  const metadata = getPageMetadata(post, "use-case");

  return metadata;
}

export default async function UseCase({
  params,
}: {
  params: Promise<{ slug: string }>;
}) {
  const { slug } = await params;
  const posts = getUseCasePages().sort(
    (a, b) =>
      b.metadata.publishedAt.getTime() - a.metadata.publishedAt.getTime(),
  );
  const postIndex = posts.findIndex((post) => post.slug === slug);
  const post = posts[postIndex];
  const previousPost = posts[postIndex - 1];
  const nextPost = posts[postIndex + 1];

  if (!post) {
    notFound();
  }

  const jsonLDGraph = createJsonLDGraph([
    getJsonLDOrganization(),
    getJsonLDWebPage(post),
    getJsonLDBlogPosting(post, "use-case"),
    getJsonLDSectionBreadcrumb(sections["use-case"], {
      label: post.metadata.title,
      path: post.href,
    }),
    getJsonLDHowTo(post),
    getJsonLDFAQPage(post),
  ]);

  return (
    <section className="prose dark:prose-invert max-w-none">
      <JsonLd graph={jsonLDGraph} />
      <h1>{post.metadata.hero ?? post.metadata.title}</h1>
      <ContentMetadata data={post} />
      {post.metadata.image ? (
        <div className="border-border relative aspect-video w-full overflow-hidden border">
          <Image
            src={post.metadata.image}
            alt={post.metadata.title}
            fill
            className="object-contain"
          />
        </div>
      ) : null}
      <CustomMDX source={post.content} />
      <ContentPagination prev={previousPost} next={nextPost} />
    </section>
  );
}