Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add help center articles
Marc Seitz07c31217a7c1
diff --git a/app/(static)/help/[slug]/page.tsx b/app/(static)/help/[slug]/page.tsxnew file mode 100644index 00000000..5b79efbb--- /dev/null+++ b/app/(static)/help/[slug]/page.tsx@@ -0,0 +1,114 @@+import { getHelpPosts, getHelpPost } from "@/lib/content/help";+import { ContentBody } from "@/components/mdx/post-body";+import { notFound } from "next/navigation";+import Link from "next/link";+import BlurImage from "@/components/blur-image";+import { constructMetadata, formatDate } from "@/lib/utils";+import { Metadata } from "next";++export async function generateStaticParams() {+ const posts = await getHelpPosts();+ return posts.map((post) => ({ slug: post?.data.slug }));+}++export const generateMetadata = async ({+ params,+}: {+ params: {+ slug: string;+ };+}): Promise<Metadata> => {+ const post = (await getHelpPosts()).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,+}: {+ params: { slug: string };+}) {+ const post = await getHelpPost(params.slug);+ if (!post) return notFound();++ return (+ <>+ <div className="max-w-7xl w-full mx-auto px-4 md:px-8 mb-10">+ <div className="flex max-w-screen-sm flex-col space-y-4 pt-16">+ <div className="flex items-center space-x-4">+ <time dateTime={post.data.publishedAt} className="text-sm">+ {formatDate(post.data.publishedAt)}+ </time>+ </div>+ <h1 className="text-4xl md:text-6xl text-balance">+ {post.data.title}+ </h1>+ <p className="text-xl text-gray-600">{post.data.summary}</p>++ <div className="items-center space-x-4 flex flex-col self-start sm:hidden">+ <Link+ href={`https://twitter.com/mfts0`}+ className="group flex items-center space-x-3"+ target="_blank"+ rel="noopener noreferrer"+ >+ <BlurImage+ src={`https://pbs.twimg.com/profile_images/1176854646343852032/iYnUXJ-m_400x400.jpg`}+ alt={`Marc Seitz`}+ width={40}+ height={40}+ className="rounded-full transition-all group-hover:brightness-90"+ />+ <div className="flex flex-col">+ <p className="font-semibold text-gray-700">Marc Seitz</p>+ <p className="text-sm text-gray-500">@mfts0</p>+ </div>+ </Link>+ </div>+ </div>+ </div>++ <div className="relative">+ <div className="grid grid-cols-4 gap-10 py-10 max-w-7xl w-full mx-auto px-4 md:px-8">+ <div className="relative col-span-4 mb-10 flex flex-col space-y-8 bg-white md:col-span-3 sm:border-r sm:border-orange-500/50">+ <div className="prose prose-h2:mb-2 first:prose-h2:mt-0 prose-h2:mt-10 prose-headings:font-medium sm:max-w-screen-md sm:pr-2 md:pr-0">+ <ContentBody>{post.body}</ContentBody>+ </div>+ </div>++ <div className="sticky top-14 col-span-1 hidden flex-col divide-y divide-gray-200 self-start sm:flex">+ <div className="flex flex-col space-y-4">+ <p className="text-sm text-gray-500">Written by</p>+ {/* <Author username={data.author} /> */}+ <Link+ href={`https://twitter.com/mfts0`}+ className="group flex items-center space-x-3"+ target="_blank"+ rel="noopener noreferrer"+ >+ <BlurImage+ src={`https://pbs.twimg.com/profile_images/1176854646343852032/iYnUXJ-m_400x400.jpg`}+ alt={`Marc Seitz`}+ width={40}+ height={40}+ className="rounded-full transition-all group-hover:brightness-90"+ />+ <div className="flex flex-col">+ <p className="font-semibold text-gray-700">Marc Seitz</p>+ <p className="text-sm text-gray-500">@mfts0</p>+ </div>+ </Link>+ </div>+ </div>+ </div>+ </div>+ </>+ );+}diff --git a/lib/content/help.ts b/lib/content/help.tsnew file mode 100644index 00000000..664e9538--- /dev/null+++ b/lib/content/help.ts@@ -0,0 +1,56 @@+import matter from "gray-matter";+import { cache } from "react";++type Post = {+ data: {+ title: string;+ summary: string;+ publishedAt: string;+ author: string;+ image: string;+ slug: string;+ published: boolean;+ };+ body: string;+};++const GITHUB_CONTENT_TOKEN = process.env.GITHUB_CONTENT_TOKEN;+const GITHUB_CONTENT_REPO = process.env.GITHUB_CONTENT_REPO;++export const getHelpPosts = cache(async () => {+ const apiUrl = `https://api.github.com/repos/${GITHUB_CONTENT_REPO}/contents/content/help`;+ const headers = {+ Authorization: `Bearer ${GITHUB_CONTENT_TOKEN}`,+ Accept: "application/vnd.github+json",+ "X-GitHub-Api-Version": "2022-11-28",+ };++ const response = await fetch(apiUrl, { headers });+ const data = await response.json();++ const posts = await Promise.all(+ data+ .filter((file: any) => file.name.endsWith(".mdx"))+ .map(async (file: any) => {+ const contentResponse = await fetch(file.url, { headers });+ const fileDetails = await contentResponse.json();+ const content = fileDetails.content; // Getting the base64 encoded content+ const decodedContent = Buffer.from(content, "base64").toString("utf8"); // Decoding the base64 content+ const { data, content: fileContent } = matter(decodedContent);++ if (data.published === false) {+ return null;+ }++ return { data, body: fileContent } as Post;+ }),+ );++ const filteredPosts = posts.filter((post: Post) => post !== null) as Post[];+ return filteredPosts;+});++export async function getHelpPost(slug: string) {+ const posts = await getHelpPosts();+ return posts.find((post) => post?.data.slug === slug);+}diff --git a/lib/content/index.ts b/lib/content/index.tsindex 9d68c6cc..1fc29a00 100644--- a/lib/content/index.ts+++ b/lib/content/index.ts@@ -1,3 +1,4 @@export { getAlternatives } from "./alternative";export { getPostsRemote as getPosts } from "./blog";export { getPages } from "./page";+export { getHelpPosts } from "./help";