Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add investor slug page
Marc Seitzf3a27fa66802
diff --git a/app/(static)/blog/[slug]/page.tsx b/app/(static)/blog/[slug]/page.tsxindex 56dea66b..ea96546d 100644--- a/app/(static)/blog/[slug]/page.tsx+++ b/app/(static)/blog/[slug]/page.tsx@@ -1,4 +1,4 @@-import { getPosts, getPost } from "@/lib//content/blog";+import { getPosts, getPost } from "@/lib/content/blog";import { ContentBody } from "@/components/mdx/post-body";import { notFound } from "next/navigation";import Link from "next/link";@@ -7,22 +7,28 @@ import { constructMetadata, formatDate } from "@/lib/utils";import { Metadata } from "next";export async function generateStaticParams() {- const posts = await getPosts()- return posts.map((post) => ({ slug: post?.data.slug }))+ const posts = await getPosts();+ return posts.map((post) => ({ slug: post?.data.slug }));}export const generateMetadata = async ({params,}: {params: {- slug: string- }+ slug: string;+ };}): Promise<Metadata> => {- const post = (await getPosts()).find((post) => post?.data.slug === params.slug)- const { title, summary: description, image } = post?.data || {}-- return constructMetadata({ title: `${title} - Papermark`, description, image })-}+ const post = (await getPosts()).find(+ (post) => post?.data.slug === params.slug,+ );+ const { title, summary: description, image } = post?.data || {};++ return constructMetadata({+ title: `${title} - Papermark`,+ description,+ image,+ });+};export default async function BlogPage({params,diff --git a/app/(static)/investors/[slug]/page.tsx b/app/(static)/investors/[slug]/page.tsxnew file mode 100644index 00000000..1763c941--- /dev/null+++ b/app/(static)/investors/[slug]/page.tsx@@ -0,0 +1,17 @@+import { getInvestor } from "@/lib/content/investor";+import { notFound } from "next/navigation";++export default async function InvestorPage({+ params,+}: {+ params: { slug: string };+}) {+ const investor = await getInvestor(params.slug);+ if (!investor) return notFound();++ return (+ <>+ <div>{investor.name}</div>+ </>+ );+}diff --git a/app/(static)/investors/page.tsx b/app/(static)/investors/page.tsxindex 6b11fa92..96ccfc7f 100644--- a/app/(static)/investors/page.tsx+++ b/app/(static)/investors/page.tsx@@ -1,24 +1,7 @@import { Suspense } from "react";import Dashboard from "./ClientPage";import { FallbackInvestors } from "./Fallback";--export const revalidate = 3600; // revalidate the data at most every 24 hours--const getInvestors = async () => {- const response = await fetch(`https://investors.papermark.io/api/investors`, {- method: "GET",- headers: {- "Content-Type": "application/json",- Authorization: `Bearer ${process.env.INVESTORS_API_KEY}`,- },- });- if (!response.ok) {- throw new Error("Network response was not ok " + response.statusText);- }- const data = await response.json();- return data;-};-+import { getInvestors } from "@/lib/content/investor";export default async function HomePage() {const allInvestors = await getInvestors();diff --git a/lib/content/investor.ts b/lib/content/investor.tsnew file mode 100644index 00000000..b89fe7be--- /dev/null+++ b/lib/content/investor.ts@@ -0,0 +1,36 @@+import { cache } from "react";++type Investor = {+ id: number;+ name: string;+ imageUrl: string | null;+ round: string | null;+ location: string | null;+ sector: string | null;+ website: string | null;+ status: string | null;+ slug: string | null;+};++// `cache` is a React 18 feature that allows you to cache a function for the lifetime of a request.+// this means getPosts() will only be called once per page build, even though we may call it multiple times+// when rendering the page.+export const getInvestors = cache(async () => {+ const response = await fetch(`https://investors.papermark.io/api/investors`, {+ method: "GET",+ headers: {+ "Content-Type": "application/json",+ Authorization: `Bearer ${process.env.INVESTORS_API_KEY}`,+ },+ });+ if (!response.ok) {+ throw new Error("Network response was not ok " + response.statusText);+ }+ const data = (await response.json()) as Investor[];+ return data;+});++export const getInvestor = async (slug: string) => {+ const investors = await getInvestors();+ return investors.find((investor) => investor.slug === slug);+};