Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(masterbots.ai): dynamic og image design and metadata #221

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/masterbots.ai/app/b/[id]/[threadId]/page.tsx
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@AndlerRL AndlerRL May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am looking now that this change is from the b folder, so we have also this: https://masterbots.ai/b/technology/ff0838e1-efd9-4046-843b-d413cbfa70ff . I think we should be using instead masterbots.ai/b/[id]/[thread_id] for sharing and site map in general, since it makes more sense when navigating the bot threads, mainly because the focus is the perspective of blogs created by the Ai.

Let me know what you think, @gaboesquivel .

cc - @merivercap @TopETH

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { BrowseThread } from '@/components/browse-thread'
import { ChatPageProps } from '@/app/chat/[chatbot]/[threadId]/page'
import { getThread } from '@/app/actions'

export { generateMbMetadata as generateMetadata } from '@/lib/metadata'

export default async function ChatPage({ params }: ChatPageProps) {
const thread = await getThread({
threadId: params.threadId,
})
return <BrowseThread thread={thread} />
}
121 changes: 25 additions & 96 deletions apps/masterbots.ai/app/og/route.tsx
Original file line number Diff line number Diff line change
@@ -1,119 +1,48 @@
/* eslint-disable @next/next/no-img-element */

import { ImageResponse } from '@vercel/og'
import { NextRequest } from 'next/server'
import { GeistMono } from 'geist/font/mono' // Import the GeistMono font
import '@/app/globals.css'
import { getThread } from '../actions'

import { getThread } from '@/app/actions'
import OgImage from '@/components/og-image'
export const runtime = 'edge'

export async function GET(req: NextRequest) {
try {
const { searchParams } = req.nextUrl
const threadId = searchParams.get('threadId')
const thread = await getThread({ threadId })

// You may need to convert GeistMono or fetch it as ArrayBuffer if needed
// const font = GeistMono; // Assuming GeistMono can be directly used, modify as needed
const threadId = searchParams.get('threadId');
const thread = await getThread({ threadId },)
const question = thread.firstMessage.content
const answer = thread.firstAnswer.content
const username = thread.account?.username
const user_avatar = thread.account?.avatar || ''

let theme = 'dark'
if (typeof window !== 'undefined') {
theme = localStorage.getItem('theme') || 'dark'
}
const isLightTheme = theme === 'light'
return new ImageResponse(
(
<div
style={{
height: '100%',
width: '100%',
display: 'flex',
alignItems: 'flex-start',
justifyContent: 'flex-start',
backgroundColor: '#17171b',
padding: '40px'
// fontFamily: GeistMono.className
}}
>
<div
style={{
display: 'flex',
height: '100%',
alignItems: 'center',
width: '100%'
}}
>
<div
style={{
flex: '1',
display: 'flex',
flexDirection: 'column',
marginRight: '20px'
}}
>
<p
style={{
fontWeight: 'bold',
marginBottom: '0px',
fontSize: 32,
color: 'white'
}}
>
{thread.chatbot.name}
</p>
<h1 style={{ fontSize: '68px', color: 'white' }}>
{thread.firstMessage.content}
</h1>
<p
style={{ color: '#ef4444', fontSize: '18px', marginTop: '0px' }}
>
{thread.chatbot.categories[0].name}
</p>
</div>
{thread.chatbot.avatar ? (
<div style={{ display: 'flex', position: 'relative' }}>
<svg
height="600"
style={{
position: 'absolute',
top: '-300px',
left: '-100px',
opacity: '0.2'
}}
version="1.1"
viewBox="0 0 900 600"
width="900"
>
<g transform="translate(444.3593826782917 273.8643784322123)">
<path
d="M186.1 -166.4C230.8 -141.4 249.4 -70.7 237.7 -11.7C226 47.4 184.1 94.8 139.4 139.9C94.8 185.1 47.4 228 -2.2 230.3C-51.9 232.5 -103.7 194 -149.2 148.9C-194.7 103.7 -233.9 51.9 -229.5 4.4C-225.1 -43.1 -177.3 -86.3 -131.8 -111.3C-86.3 -136.3 -43.1 -143.1 13.8 -156.9C70.7 -170.7 141.4 -191.4 186.1 -166.4"
fill="#ef4444"
/>
</g>
</svg>

<img
alt=""
src={thread.chatbot.avatar}
style={{
objectFit: 'cover',
margin: 'auto',
border: '8px solid #ef4444',
width: '300px',
height: '300px',
borderRadius: '50%'
}}
/>
</div>
) : null}
</div>
</div>
<OgImage
thread={thread}
question={question}
answer={answer}
username={username}
user_avatar={user_avatar}
isLightTheme={isLightTheme}
/>
),
{
width: 1200,
height: 627
}
)
} catch (e) {
} catch (e: any) {
console.log(`${e.message}`)
return new Response(`Failed to generate the image`, {
status: 500
})
}
}
function useTheme() {
throw new Error('Function not implemented.')
}
Loading
Loading