Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

add custom metatag

Marc Seitz0a31e129e8f8
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsx
index fa14fbab..4d2ba4fb 100644
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@ -18,7 +18,7 @@ import { mutate } from "swr";
import { Button } from "@/components/ui/button";
import { toast } from "sonner";
import { Label } from "@/components/ui/label";
-import { cn } from "@/lib/utils";
+import { cn, convertDataUrlToFile, uploadImage } from "@/lib/utils";
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
import Link from "next/link";
import DomainSection from "./domain-section";
@@ -26,6 +26,9 @@ import AllowDownloadSection from "./allow-download-section";
import { useTeam } from "@/context/team-context";
import AllowNotificationSection from "./allow-notification-section";
import FeedbackSection from "./feedback-section";
+import OGSection from "./og-section";
+import { ScrollArea } from "@/components/ui/scroll-area";
+import { upload } from "@vercel/blob/client";
export const DEFAULT_LINK_PROPS = {
id: null,
@@ -38,6 +41,10 @@ export const DEFAULT_LINK_PROPS = {
allowDownload: false,
enableNotification: true,
enableFeedback: true,
+ enableCustomMetatag: false,
+ metaTitle: null,
+ metaDescription: null,
+ metaImage: null,
};
export type DEFAULT_LINK_TYPE = {
@@ -51,6 +58,10 @@ export type DEFAULT_LINK_TYPE = {
allowDownload: boolean;
enableNotification: boolean;
enableFeedback: boolean;
+ enableCustomMetatag: boolean; // metatags
+ metaTitle: string | null; // metatags
+ metaDescription: string | null; // metatags
+ metaImage: string | null; // metatags
};
export default function LinkSheet({
@@ -80,6 +91,19 @@ export default function LinkSheet({
setIsLoading(true);
+ // Upload the image if it's a data URL
+ let blobUrl: string | null =
+ data.metaImage && data.metaImage.startsWith("data:")
+ ? null
+ : data.metaImage;
+ if (data.metaImage && data.metaImage.startsWith("data:")) {
+ // Convert the data URL to a blob
+ const blob = convertDataUrlToFile({ dataUrl: data.metaImage });
+ // Upload the blob to vercel storage
+ blobUrl = await uploadImage(blob);
+ setData({ ...data, metaImage: blobUrl });
+ }
+
let endpoint = "/api/links";
let method = "POST";
@@ -96,6 +120,7 @@ export default function LinkSheet({
},
body: JSON.stringify({
...data,
+ metaImage: blobUrl,
documentId: documentId,
}),
});
@@ -154,53 +179,57 @@ export default function LinkSheet({
done.
</SheetDescription>
</SheetHeader>
+
<form className="flex flex-col grow" onSubmit={handleSubmit}>
- <div className="h-0 flex-1">
- <div className="flex flex-1 flex-col justify-between">
- <div className="divide-y divide-gray-200">
- <div className="space-y-6 pb-5 pt-6">
- <div className="space-y-2">
- <Label htmlFor="link-name">Link Name</Label>
- <div className="mt-2">
- <input
- type="text"
- name="link-name"
- id="link-name"
- placeholder="Recipient's Organization"
- value={data.name || ""}
- className="flex w-full rounded-md border-0 py-1.5 text-foreground bg-background shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6"
- onChange={(e) =>
- setData({ ...data, name: e.target.value })
- }
- />
+ <ScrollArea className="flex-grow">
+ <div className="h-0 flex-1">
+ <div className="flex flex-1 flex-col justify-between">
+ <div className="divide-y divide-gray-200">
+ <div className="space-y-6 pb-5 pt-6">
+ <div className="space-y-2">
+ <Label htmlFor="link-name">Link Name</Label>
+ <div className="mt-2">
+ <input
+ type="text"
+ name="link-name"
+ id="link-name"
+ placeholder="Recipient's Organization"
+ value={data.name || ""}
+ className="flex w-full rounded-md border-0 py-1.5 text-foreground bg-background shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6"
+ onChange={(e) =>
+ setData({ ...data, name: e.target.value })
+ }
+ />
+ </div>
</div>
- </div>
- <div className="space-y-2">
- <DomainSection {...{ data, setData, domains }} />
- </div>
+ <div className="space-y-2">
+ <DomainSection {...{ data, setData, domains }} />
+ </div>
- <div className="flex items-center relative">
- <Separator className="bg-muted-foreground absolute" />
- <div className="relative mx-auto">
- <span className="px-2 bg-background text-muted-foreground text-sm">
- Optional
- </span>
+ <div className="flex items-center relative">
+ <Separator className="bg-muted-foreground absolute" />
+ <div className="relative mx-auto">
+ <span className="px-2 bg-background text-muted-foreground text-sm">
+ Optional
+ </span>
+ </div>
</div>
- </div>
- <div>
- <EmailProtectionSection {...{ data, setData }} />
- <AllowDownloadSection {...{ data, setData }} />
- <PasswordSection {...{ data, setData }} />
- <ExpirationSection {...{ data, setData }} />
- <AllowNotificationSection {...{ data, setData }} />
- <FeedbackSection {...{ data, setData }} />
+ <div>
+ <EmailProtectionSection {...{ data, setData }} />
+ <AllowDownloadSection {...{ data, setData }} />
+ <PasswordSection {...{ data, setData }} />
+ <ExpirationSection {...{ data, setData }} />
+ <OGSection {...{ data, setData }} />
+ <AllowNotificationSection {...{ data, setData }} />
+ <FeedbackSection {...{ data, setData }} />
+ </div>
</div>
</div>
</div>
</div>
- </div>
+ </ScrollArea>
<SheetFooter>
<div className="flex items-center">
diff --git a/components/links/link-sheet/og-section.tsx b/components/links/link-sheet/og-section.tsx
new file mode 100644
index 00000000..8933d47a
--- /dev/null
+++ b/components/links/link-sheet/og-section.tsx
@@ -0,0 +1,258 @@
+import {
+ Dispatch,
+ SetStateAction,
+ useState,
+ useEffect,
+ useCallback,
+} from "react";
+import { Switch } from "@/components/ui/switch";
+import { cn } from "@/lib/utils";
+import { DEFAULT_LINK_TYPE } from ".";
+import { motion } from "framer-motion";
+import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
+import LoadingSpinner from "@/components/ui/loading-spinner";
+import { ArrowUpTrayIcon } from "@heroicons/react/20/solid";
+import { Input } from "@/components/ui/input";
+import { Textarea } from "@/components/ui/textarea";
+
+export default function OGSection({
+ data,
+ setData,
+}: {
+ data: DEFAULT_LINK_TYPE;
+ setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;
+}) {
+ const { enableCustomMetatag, metaTitle, metaDescription, metaImage } = data;
+ const [enabled, setEnabled] = useState<boolean>(false);
+
+ const [fileError, setFileError] = useState<string | null>(null);
+ const [dragActive, setDragActive] = useState(false);
+
+ const onChangePicture = useCallback(
+ (e: any) => {
+ setFileError(null);
+ const file = e.target.files[0];
+ if (file) {
+ if (file.size / 1024 / 1024 > 5) {
+ setFileError("File size too big (max 5MB)");
+ } else if (file.type !== "image/png" && file.type !== "image/jpeg") {
+ setFileError("File type not supported (.png or .jpg only)");
+ } else {
+ const reader = new FileReader();
+ reader.onload = (e) => {
+ setData((prev) => ({
+ ...prev,
+ metaImage: e.target?.result as string,
+ }));
+ };
+ reader.readAsDataURL(file);
+ }
+ }
+ },
+ [setData],
+ );
+
+ useEffect(() => {
+ setEnabled(enableCustomMetatag);
+ }, [enableCustomMetatag]);
+
+ const handleCustomMetatag = async () => {
+ const updatedCustomMetatag = !enabled;
+
+ setData({ ...data, enableCustomMetatag: updatedCustomMetatag });
+ setEnabled(updatedCustomMetatag);
+ };
+
+ return (
+ <div className="pb-5">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center justify-between space-x-2">
+ <h2
+ className={cn(
+ "text-sm font-medium leading-6",
+ enabled ? "text-foreground" : "text-muted-foreground",
+ )}
+ >
+ Custom social media cards
+ </h2>
+ </div>
+ <Switch checked={enabled} onCheckedChange={handleCustomMetatag} />
+ </div>
+
+ {enabled && (
+ <motion.div
+ className="relative mt-4 rounded-md shadow-sm space-y-3"
+ {...FADE_IN_ANIMATION_SETTINGS}
+ >
+ <div>
+ <div className="flex items-center justify-between">
+ <p className="block text-sm font-medium text-foreground">Image</p>
+ {fileError ? (
+ <p className="text-sm text-red-500">{fileError}</p>
+ ) : null}
+ </div>
+ <label
+ htmlFor="image"
+ className="group relative mt-1 flex h-[14rem] cursor-pointer flex-col items-center justify-center rounded-md border border-gray-300 bg-white shadow-sm transition-all hover:bg-gray-50"
+ >
+ {false && (
+ <div className="absolute z-[5] flex h-full w-full items-center justify-center rounded-md bg-white">
+ <LoadingSpinner />
+ </div>
+ )}
+ <div
+ className="absolute z-[5] h-full w-full rounded-md"
+ onDragOver={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setDragActive(true);
+ }}
+ onDragEnter={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setDragActive(true);
+ }}
+ onDragLeave={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setDragActive(false);
+ }}
+ onDrop={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setDragActive(false);
+ setFileError(null);
+ const file = e.dataTransfer.files && e.dataTransfer.files[0];
+ if (file) {
+ if (file.size / 1024 / 1024 > 5) {
+ setFileError("File size too big (max 5MB)");
+ } else if (
+ file.type !== "image/png" &&
+ file.type !== "image/jpeg"
+ ) {
+ setFileError(
+ "File type not supported (.png or .jpg only)",
+ );
+ } else {
+ const reader = new FileReader();
+ reader.onload = (e) => {
+ setData((prev) => ({
+ ...prev,
+ metaImage: e.target?.result as string,
+ }));
+ };
+ reader.readAsDataURL(file);
+ }
+ }
+ }}
+ />
+ <div
+ className={`${
+ dragActive
+ ? "cursor-copy border-2 border-black bg-gray-50 opacity-100"
+ : ""
+ } absolute z-[3] flex h-full w-full flex-col items-center justify-center rounded-md bg-white transition-all ${
+ metaImage
+ ? "opacity-0 group-hover:opacity-100"
+ : "group-hover:bg-gray-50"
+ }`}
+ >
+ <ArrowUpTrayIcon
+ className={`${
+ dragActive ? "scale-110" : "scale-100"
+ } h-7 w-7 text-gray-500 transition-all duration-75 group-hover:scale-110 group-active:scale-95`}
+ />
+ <p className="mt-2 text-center text-sm text-gray-500">
+ Drag and drop or click to upload.
+ </p>
+ <p className="mt-2 text-center text-sm text-gray-500">
+ Recommended: 1200 x 630 pixels (max 5MB)
+ </p>
+ <span className="sr-only">OG image upload</span>
+ </div>
+ {metaImage && (
+ <img
+ src={metaImage}
+ alt="Preview"
+ className="h-full w-full rounded-md object-cover"
+ />
+ )}
+ </label>
+ <div className="mt-1 flex rounded-md shadow-sm">
+ <input
+ id="image"
+ name="image"
+ type="file"
+ accept="image/*"
+ className="sr-only"
+ onChange={onChangePicture}
+ />
+ </div>
+ </div>
+
+ <div>
+ <div className="flex items-center justify-between">
+ <p className="block text-sm font-medium text-foreground">Title</p>
+ <p className="text-sm text-muted-foreground">
+ {metaTitle?.length || 0}/120
+ </p>
+ </div>
+ <div className="relative mt-1 flex rounded-md shadow-sm">
+ {false && (
+ <div className="absolute flex h-full w-full items-center justify-center rounded-md border border-gray-300 bg-white">
+ <LoadingSpinner />
+ </div>
+ )}
+ <Input
+ name="title"
+ id="title"
+ maxLength={120}
+ className="flex w-full rounded-md border-0 py-1.5 text-foreground bg-background shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6"
+ placeholder={`Papermark - open-source document sharing infrastructure.`}
+ value={metaTitle || ""}
+ onChange={(e) => {
+ setData({ ...data, metaTitle: e.target.value });
+ }}
+ aria-invalid="true"
+ />
+ </div>
+ </div>
+
+ <div>
+ <div className="flex items-center justify-between">
+ <p className="block text-sm font-medium text-foreground">
+ Description
+ </p>
+ <p className="text-sm text-muted-foreground">
+ {metaDescription?.length || 0}/240
+ </p>
+ </div>
+ <div className="relative mt-1 flex rounded-md shadow-sm">
+ {false && (
+ <div className="absolute flex h-full w-full items-center justify-center rounded-md border border-gray-300 bg-white">
+ <LoadingSpinner />
+ </div>
+ )}
+ <Textarea
+ name="description"
+ id="description"
+ rows={3}
+ maxLength={240}
+ className="flex w-full rounded-md border-0 py-1.5 text-foreground bg-background shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6"
+ placeholder={`Papermark is an open-source document sharing infrastructure for modern teams.`}
+ value={metaDescription || ""}
+ onChange={(e) => {
+ setData({
+ ...data,
+ metaDescription: e.target.value,
+ });
+ }}
+ aria-invalid="true"
+ />
+ </div>
+ </div>
+ </motion.div>
+ )}
+ </div>
+ );
+}
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index 74291bef..622a0a03 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -69,6 +69,12 @@ export default function LinksTable() {
? link.enableNotification
: false,
enableFeedback: link.enableFeedback ? link.enableFeedback : false,
+ enableCustomMetatag: link.enableCustomMetatag
+ ? link.enableCustomMetatag
+ : false,
+ metaTitle: link.metaTitle,
+ metaDescription: link.metaDescription,
+ metaImage: link.metaImage,
});
//wait for dropdown to close before opening the link sheet
setTimeout(() => {
diff --git a/components/ui/textarea.tsx b/components/ui/textarea.tsx
new file mode 100644
index 00000000..9f9a6dc5
--- /dev/null
+++ b/components/ui/textarea.tsx
@@ -0,0 +1,24 @@
+import * as React from "react"
+
+import { cn } from "@/lib/utils"
+
+export interface TextareaProps
+ extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
+
+const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
+ ({ className, ...props }, ref) => {
+ return (
+ <textarea
+ className={cn(
+ "flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
+ className
+ )}
+ ref={ref}
+ {...props}
+ />
+ )
+ }
+)
+Textarea.displayName = "Textarea"
+
+export { Textarea }
diff --git a/components/view/custom-metatag.tsx b/components/view/custom-metatag.tsx
new file mode 100644
index 00000000..11feaaf0
--- /dev/null
+++ b/components/view/custom-metatag.tsx
@@ -0,0 +1,26 @@
+import Head from "next/head";
+
+const CustomMetatag = ({
+ title,
+ description,
+ imageUrl,
+}: {
+ title: string;
+ description: string;
+ imageUrl: string;
+}) => {
+ return (
+ <Head>
+ <title>{title}</title>
+ <meta name="description" content={description} />
+ <meta property="og:title" content={title} />
+ <meta property="og:description" content={description} />
+ <meta property="og:image" content={imageUrl} />
+ <meta name="twitter:title" content={title} />
+ <meta name="twitter:description" content={description} />
+ <meta name="twitter:image" content={imageUrl} />
+ </Head>
+ );
+};
+
+export default CustomMetatag;
diff --git a/lib/utils.ts b/lib/utils.ts
index 0f79ed38..96338416 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -6,6 +6,7 @@ import { toast } from "sonner";
import { customAlphabet } from "nanoid";
import { ThreadMessage } from "openai/resources/beta/threads/messages/messages";
import { Message } from "ai";
+import { upload } from "@vercel/blob/client";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
@@ -303,3 +304,82 @@ export const convertThreadMessagesToMessages = (
};
});
};
+
+export function constructMetadata({
+ title = "Papermark | The Open Source DocSend Alternative",
+ description = "Papermark is an open-source document sharing alternative to DocSend with built-in engagement analytics and 100% white-labeling.",
+ image = "https://www.papermark.io/_static/meta-image.png",
+ favicon = "/favicon.ico",
+ noIndex = false,
+}: {
+ title?: string;
+ description?: string;
+ image?: string;
+ favicon?: string;
+ noIndex?: boolean;
+} = {}) {
+ return {
+ title,
+ description,
+ openGraph: {
+ title,
+ description,
+ images: [
+ {
+ url: image,
+ },
+ ],
+ },
+ twitter: {
+ card: "summary_large_image",
+ title,
+ description,
+ images: [image],
+ creator: "@papermarkio",
+ },
+ favicon,
+ ...(noIndex && {
+ robots: {
+ index: false,
+ follow: false,
+ },
+ }),
+ };
+}
+
+export const convertDataUrlToFile = ({
+ dataUrl,
+ filename = "logo.png",
+}: {
+ dataUrl: string;
+ filename?: string;
+}) => {
+ let arr = dataUrl.split(","),
+ match = arr[0].match(/:(.*?);/),
+ mime = match ? match[1] : "",
+ bstr = atob(arr[1]),
+ n = bstr.length,
+ u8arr = new Uint8Array(n);
+
+ while (n--) {
+ u8arr[n] = bstr.charCodeAt(n);
+ }
+
+ filename =
+ mime == "image/png"
+ ? "logo.png"
+ : mime == "image/jpeg"
+ ? "logo.jpg"
+ : filename;
+
+ return new File([u8arr], filename, { type: mime });
+};
+
+export const uploadImage = async (file: File) => {
+ const newBlob = await upload(file.name, file, {
+ access: "public",
+ handleUploadUrl: "/api/file/logo-upload",
+ });
+
+ return newBlob.url;
+};
diff --git a/pages/_document.tsx b/pages/_document.tsx
index bf9e456b..a0945840 100644
--- a/pages/_document.tsx
+++ b/pages/_document.tsx
@@ -23,8 +23,8 @@ export default function Document() {
/>
<meta property="og:url" content="https://www.papermark.io" />
<meta name="twitter:card" content="summary_large_image" />
- <meta name="twitter:site" content="@mfts0" />
- <meta name="twitter:creator" content="@mfts0" />
+ <meta name="twitter:site" content="@papermarkio" />
+ <meta name="twitter:creator" content="@papermarkio" />
<meta name="twitter:title" content="Papermark" />
<meta
name="twitter:description"
diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.ts
index 5f0d626d..fe3ca648 100644
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@ -27,6 +27,10 @@ export default async function handle(
enableFeedback: true,
password: true,
isArchived: true,
+ enableCustomMetatag: true,
+ metaTitle: true,
+ metaDescription: true,
+ metaImage: true,
document: {
select: {
id: true,
@@ -153,6 +157,10 @@ export default async function handle(
slug: slug || null,
enableNotification: linkData.enableNotification,
enableFeedback: linkData.enableFeedback,
+ enableCustomMetatag: linkData.enableCustomMetatag,
+ metaTitle: linkData.metaTitle || null,
+ metaDescription: linkData.metaDescription || null,
+ metaImage: linkData.metaImage || null,
},
include: {
views: {
diff --git a/pages/api/links/domains/[...domainSlug].ts b/pages/api/links/domains/[...domainSlug].ts
index c11e0b44..c2a49319 100644
--- a/pages/api/links/domains/[...domainSlug].ts
+++ b/pages/api/links/domains/[...domainSlug].ts
@@ -28,10 +28,14 @@ export default async function handle(
allowDownload: true,
password: true,
isArchived: true,
+ enableCustomMetatag: true,
+ metaTitle: true,
+ metaDescription: true,
+ metaImage: true,
document: {
select: {
id: true,
- team: { select: { plan: true } },
+ team: { select: { id: true, plan: true } },
versions: {
where: { isPrimary: true },
select: {
@@ -67,7 +71,21 @@ export default async function handle(
});
}
- res.status(200).json(link);
+ let brand = await prisma.brand.findFirst({
+ where: {
+ teamId: link.document.team.id,
+ },
+ select: {
+ logo: true,
+ brandColor: true,
+ },
+ });
+
+ if (!brand) {
+ brand = null;
+ }
+
+ res.status(200).json({ link, brand });
} catch (error) {
return res.status(500).json({
message: "Internal Server Error",
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index 3999d9aa..c0b912fb 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -100,6 +100,10 @@ export default async function handler(
slug: slug || null,
enableNotification: linkData.enableNotification,
enableFeedback: linkData.enableFeedback,
+ enableCustomMetatag: linkData.enableCustomMetatag,
+ metaTitle: linkData.metaTitle || null,
+ metaDescription: linkData.metaDescription || null,
+ metaImage: linkData.metaImage || null,
},
});
diff --git a/pages/view/[linkId]/index.tsx b/pages/view/[linkId]/index.tsx
index b2f3b1cd..f2ff76e5 100644
--- a/pages/view/[linkId]/index.tsx
+++ b/pages/view/[linkId]/index.tsx
@@ -10,6 +10,8 @@ import { parsePageId } from "notion-utils";
import { GetStaticPropsContext } from "next";
import { useRouter } from "next/router";
import { Brand } from "@prisma/client";
+import CustomMetatag from "@/components/view/custom-metatag";
+import Head from "next/head";
export const getStaticProps = async (context: GetStaticPropsContext) => {
const { linkId } = context.params as { linkId: string };
@@ -119,27 +121,47 @@ export default function ViewPage({
);
}
+ const { enableCustomMetatag, metaTitle, metaDescription, metaImage } = link;
+
if (emailProtected || linkPassword) {
return (
+ <>
+ {enableCustomMetatag ? (
+ <CustomMetatag
+ title={metaTitle!}
+ description={metaDescription!}
+ imageUrl={metaImage!}
+ />
+ ) : null}
+ <DocumentView
+ link={link}
+ userEmail={userEmail}
+ userId={userId}
+ isProtected={true}
+ notionData={notionData}
+ brand={brand}
+ />
+ </>
+ );
+ }
+
+ return (
+ <>
+ {enableCustomMetatag ? (
+ <CustomMetatag
+ title={metaTitle!}
+ description={metaDescription!}
+ imageUrl={metaImage!}
+ />
+ ) : null}
<DocumentView
link={link}
userEmail={userEmail}
userId={userId}
- isProtected={true}
+ isProtected={false}
notionData={notionData}
brand={brand}
/>
- );
- }
-
- return (
- <DocumentView
- link={link}
- userEmail={userEmail}
- userId={userId}
- isProtected={false}
- notionData={notionData}
- brand={brand}
- />
+ </>
);
}
diff --git a/pages/view/domains/[domain]/[slug]/index.tsx b/pages/view/domains/[domain]/[slug]/index.tsx
index ebc598c0..2d1a20a1 100644
--- a/pages/view/domains/[domain]/[slug]/index.tsx
+++ b/pages/view/domains/[domain]/[slug]/index.tsx
@@ -11,6 +11,8 @@ import prisma from "@/lib/prisma";
import { ExtendedRecordMap } from "notion-types";
import notion from "@/lib/notion";
import { parsePageId } from "notion-utils";
+import { Brand } from "@prisma/client";
+import CustomMetatag from "@/components/view/custom-metatag";
export const getStaticProps = async (context: GetStaticPropsContext) => {
const { domain, slug } = context.params as { domain: string; slug: string };
@@ -24,7 +26,10 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
if (!res.ok) {
return { notFound: true };
}
- const link = (await res.json()) as LinkWithDocument;
+ const { link, brand } = (await res.json()) as {
+ link: LinkWithDocument;
+ brand: Brand | null;
+ };
let pageId = null;
let recordMap = null;
@@ -59,6 +64,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
rootNotionPageId: pageId,
recordMap,
},
+ brand, // pass the brand to client
},
revalidate: 10,
};
@@ -74,12 +80,14 @@ export async function getStaticPaths() {
export default function ViewPage({
link,
notionData,
+ brand,
}: {
link: LinkWithDocument;
notionData: {
rootNotionPageId: string | null;
recordMap: ExtendedRecordMap | null;
};
+ brand?: Brand;
}) {
const router = useRouter();
const { data: session, status } = useSession();
@@ -114,25 +122,47 @@ export default function ViewPage({
);
}
+ const { enableCustomMetatag, metaTitle, metaDescription, metaImage } = link;
+
if (emailProtected || linkPassword) {
return (
+ <>
+ {enableCustomMetatag ? (
+ <CustomMetatag
+ title={metaTitle!}
+ description={metaDescription!}
+ imageUrl={metaImage!}
+ />
+ ) : null}
+ <DocumentView
+ link={link}
+ userEmail={userEmail}
+ userId={userId}
+ isProtected={true}
+ notionData={notionData}
+ brand={brand}
+ />
+ </>
+ );
+ }
+
+ return (
+ <>
+ {enableCustomMetatag ? (
+ <CustomMetatag
+ title={metaTitle!}
+ description={metaDescription!}
+ imageUrl={metaImage!}
+ />
+ ) : null}
<DocumentView
link={link}
userEmail={userEmail}
userId={userId}
- isProtected={true}
+ isProtected={false}
notionData={notionData}
+ brand={brand}
/>
- );
- }
-
- return (
- <DocumentView
- link={link}
- userEmail={userEmail}
- userId={userId}
- isProtected={false}
- notionData={notionData}
- />
+ </>
);
}
diff --git a/prisma/migrations/20240117020456_add_branding/migration.sql b/prisma/migrations/20240117020456_add_branding/migration.sql
new file mode 100644
index 00000000..380267c6
--- /dev/null
+++ b/prisma/migrations/20240117020456_add_branding/migration.sql
@@ -0,0 +1,24 @@
+-- AlterTable
+ALTER TABLE "Link" ADD COLUMN "enableCustomMetatag" BOOLEAN DEFAULT false,
+ADD COLUMN "metaDescription" TEXT,
+ADD COLUMN "metaImage" TEXT,
+ADD COLUMN "metaTitle" TEXT;
+
+-- CreateTable
+CREATE TABLE "Brand" (
+ "id" TEXT NOT NULL,
+ "logo" TEXT,
+ "brandColor" TEXT,
+ "accentColor" TEXT,
+ "teamId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "Brand_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateIndex
+CREATE UNIQUE INDEX "Brand_teamId_key" ON "Brand"("teamId");
+
+-- AddForeignKey
+ALTER TABLE "Brand" ADD CONSTRAINT "Brand_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 5a082c7a..642efc5a 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -189,6 +189,12 @@ model Link {
enableNotification Boolean? @default(true) // Optional give user a option to pause/resume the notifications
enableFeedback Boolean? @default(true) // Optional give user a option to enable the feedback toolbar
+ // custom metatags
+ metaTitle String? // This will be the meta title of the link
+ metaDescription String? // This will be the meta description of the link
+ metaImage String? // This will be the meta image of the link
+ enableCustomMetatag Boolean? @default(false) // Optional give user a option to enable the custom metatag
+
@@unique([domainSlug, slug])
@@index([documentId])
}