Skip to content

Commit

Permalink
notes og image
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeFulton committed Aug 25, 2024
1 parent 376f8de commit 73cde04
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 11 deletions.
Binary file added pages/api/og-generator/Inter-Bold.ttf
Binary file not shown.
Binary file added pages/api/og-generator/Inter-VariableFont.ttf
Binary file not shown.
Binary file added pages/api/og-generator/InterDisplay-Bold.ttf
Binary file not shown.
Binary file added pages/api/og-generator/InterDisplay-Regular.ttf
Binary file not shown.
File renamed without changes.
241 changes: 241 additions & 0 deletions pages/api/og-generator/og-note.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
import { NotePencil } from "@/components/icons";
import { ImageResponse } from "@vercel/og";

const interBold = fetch(
new URL("./InterDisplay-Bold.ttf", import.meta.url)
).then(res => res.arrayBuffer());
const interRegular = fetch(
new URL("./InterDisplay-Regular.ttf", import.meta.url)
).then(res => res.arrayBuffer());

export const config = {
runtime: "edge",
};

const OgImageHandler = async req => {
const { searchParams } = new URL(req.url);
const title = searchParams.get("title") || "New note";
const avatar =
searchParams.get("avatar") ||
"https://s3-us-west-1.amazonaws.com/tinify-bucket/%2Fprototypr%2Ftemp%2F1595435549331-1595435549330.png";
const author = searchParams.get("author") || "";
const date = searchParams.get("date") || "";

const boldFont = await interBold;
const regularFont = await interRegular;

return new ImageResponse(
(
<div
style={{
display: "flex",
flexDirection: "column",
position: "relative",
height: "100%",
width: "100%",
alignItems: "center",
justifyContent: "center",
letterSpacing: "-.02em",
fontWeight: 700,
background: "#ededf5",

backgroundImage: 'radial-gradient(circle at 25px 25px, #C8C8E4 5%, transparent 0%)',
backgroundSize: '50px 50px',
}}
>
<img
style={{
position: "absolute",
top: "12px",
left: "12px",
width: "74px",
}}
src={`https://prototypr-media.sfo2.digitaloceanspaces.com/strapi/a8771a61fb3e1990bd2b87fa29054d74.png`}
/>
<div
style={{
width: "758px",
height: "486px",
display: "flex",
alignItems: "center",
justifyContent: "center",
position: "relative",
backgroundColor: "#f9fafb",
borderRadius: "2px",
boxShadow:
"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",
}}
>
{/* paper stack */}
<div
style={{
position: "absolute",
inset: 0,
backgroundColor: "#f9fafb",
transform: "translateX(-4px) translateY(2px) rotate(-3.5deg)",
zIndex: -10,
boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1)",
border: "1px solid #f9fafb",
borderLeft: "1px solid #e5e7eb",
width: "100%",
height: "100%",
}}
/>
<div
style={{
position: "absolute",
inset: 0,
backgroundColor: "#f7f7f7",
transform: "translateX(-2px) translateY(2px) rotate(2deg)",
zIndex: -20,
boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1)",
borderLeft: "1px solid #e5e7eb",
borderTop: "1px solid #e5e7eb",
width: "100%",
height: "100%",
}}
/>
<div
style={{
position: "absolute",
inset: 0,
transform: "translateX(-2px) rotate(4.5deg)",
zIndex: -50,
boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1)",
borderLeft: "1px solid #e5e7eb",
backgroundColor: "#f7f7f7",
width: "100%",
height: "100%",
}}
/>

{/* Main content */}
<div
style={{
position: "relative",
width: "100%",
height: "100%",
background: "white",
padding: "24px",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
zIndex: 10,
transform: "rotate(-1deg)",
transition: "all 0.5s ease-in-out",
border: "1px solid rgba(229, 231, 235, 0.5)",
boxShadow:
"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",
}}
>
<div
style={{
display: "flex",
gap: 4,
flexDirection: "row",
fontSize: 14,
fontWeight: 400,
fontFamily: "InterRegular",
justifyContent: "center",
marginBottom: 8,
}}
>
<NotePencil size={16} color="#6b7280" />
<div
style={{
color: "#6b7280",
display: "flex",
alignItems: "center",
}}
>
Prototypr Notes
</div>
</div>
<h1
style={{
display: "flex",
flexWrap: "wrap",
justifyContent: "center",
margin: "0 42px",
fontSize: 48,
fontWeight: 900,
width: "auto",
maxWidth: 550,
textAlign: "center",
fontFamily: "InterBold",
marginBottom: 44,
}}
>
<b>{title}</b>
</h1>

<div
style={{
display: "flex",
gap: 12,
flexDirection: "row",
alignItems: "center",
}}
>
{avatar && (
<img
style={{
width: 64,
height: 64,
borderRadius: 100,
objectFit: "cover",
}}
src={avatar}
/>
)}
{author && (
<div
style={{
display: "flex",
gap: 4,
flexDirection: "column",
fontSize: 20,
fontWeight: 400,
fontFamily: "InterRegular",
justifyContent: "center",
}}
>
<div>{author}</div>
<div
style={{
fontSize: 18,
fontWeight: 400,
fontFamily: "InterRegular",
color: "#6b7280",
}}
>
{date}
</div>
</div>
)}
</div>
</div>
</div>
</div>
),
{
width: 1200,
height: 630,
fonts: [
{
name: "InterBold",
data: boldFont,
style: "bold",
},
{
name: "InterRegular",
data: regularFont,
style: "normal",
},
],
}
);
};

export default OgImageHandler;
2 changes: 1 addition & 1 deletion pages/jobs/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function Post({

const image = `${
process.env.NEXT_PUBLIC_HOME_URL
}/api/og?title=${encodeURIComponent(title)}&companyName=${encodeURIComponent(
}/api/og-generator/og-job?title=${encodeURIComponent(title)}&companyName=${encodeURIComponent(
companyName
)}&companyLogo=${companyLogo}&salary=${encodeURIComponent(salaryText)}`;
return (
Expand Down
4 changes: 2 additions & 2 deletions pages/n/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export default function EditPostPage() {
url: "https://prototypr.io/note",
}}
>
<div className="h-screen overflow-hidden bg-gray-100">
<div className="h-screen overflow-auto bg-gray-100">
<div className="w-[758px] group z-10 flex items-center justify-center bg-gray-50 mx-auto mt-20 relative rounded-sm rounded-b-none shadow-lg h-[calc(100vh-114px)]">
<div className="group relative w-full h-full overflow-hidden bg-white group-hover:border-gray-100 shadow-lg p-6 transform -rotate-1 hover:rotate-0 transition-all duration-500 ease-in-out border border-opacity-0 border-gray-400 group-hover:border-opacity-100">
<div className="absolute inset-0 z-0 overflow-hidden">
<div className="relative bg-white flex flex-col justify-start h-full z-10">
<div className="z-10">
<Tiptypr
{...typrNotesProps({
user,
Expand Down
4 changes: 2 additions & 2 deletions pages/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export default function Write() {
<div className="h-screen overflow-hidden bg-gray-100">
<div className="w-[758px] group z-10 flex items-center justify-center bg-gray-50 mx-auto mt-20 relative rounded-sm rounded-b-none shadow-lg h-[calc(100vh-114px)]">
<div className="group relative w-full h-full overflow-hidden bg-white group-hover:border-gray-100 shadow-lg p-6 transform -rotate-1 hover:rotate-0 transition-all duration-500 ease-in-out border border-opacity-0 border-gray-400 group-hover:border-opacity-100">
<div className="absolute inset-0 z-0 overflow-hidden">
<div className="relative bg-white flex flex-col justify-start h-full z-10">
<div className="absolute inset-0 z-0 overflow-auto">
<div className="z-10">
<Typr
{...typrNotesProps({
user,
Expand Down
20 changes: 14 additions & 6 deletions pages/note/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ import Link from "next/link";
import Image from "next/image";
import gumletLoader from "@/components/new-index/gumletLoader";
import { TOTAL_STATIC_POSTS } from "@/lib/constants";
import PostHeader from "@/components/post-header";
// import PostHeader from "@/components/post-header";
import SocialShare from "@/components/SocialShare";
import PostGroupRow from "@/components/v4/layout/PostGroupRow";
import { addTwitterScript } from "@/lib/addTwitterScript";
import { createB64WithFallback } from "@/lib/utils/blurHashToDataURL";
import getSponsors from "@/lib/utils/getSponsors";

import AdCard from "@/components/v4/card/AdCard";
import { NoteReceipt, PenLineSimple } from "@/components/icons";
import AuthorSidebar from "@/components/AuthorSidebar";
import LikeButton from "@/components/LikeButton";
// import AdCard from "@/components/v4/card/AdCard";
// import { NoteReceipt, PenLineSimple } from "@/components/icons";
// import AuthorSidebar from "@/components/AuthorSidebar";
// import LikeButton from "@/components/LikeButton";
import isoToReadableDate from "@/lib/utils/isoToReadableDate";
import { Note } from "@phosphor-icons/react";
import { PenLineSimple } from "@/components/icons";

// import ToolBackgroundCard from "@/components/v4/card/ToolBackgroundCard";
const StickyFooterCTA = dynamic(() => import("@/components/StickyFooterCTA"), {
Expand Down Expand Up @@ -133,6 +134,13 @@ export default function Post({
}
}, [post.attributes?.content]);

const ogImage = `${
process.env.NEXT_PUBLIC_HOME_URL
}/api/og-generator/og-note?title=${encodeURIComponent(title)}&author=${encodeURIComponent(
authorName
)}&date=${encodeURIComponent(date)}&avatar=${encodeURIComponent(avatar)}`;


return (
<Layout
maxWidth={"max-w-[1350px] search-wide"}
Expand All @@ -141,7 +149,7 @@ export default function Post({
seo={{
title: `${title}`,
description: `${description}`,
image: `${image}`,
image: `${ogImage}`,
canonical: `${canonical}`,
url: `${url}`,
monetization: `${paymentPointer}`,
Expand Down
Binary file added public/fonts/Inter-VariableFont.ttf
Binary file not shown.

0 comments on commit 73cde04

Please sign in to comment.