-
Notifications
You must be signed in to change notification settings - Fork 1
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
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Page usage example: https://masterbots.ai/technology/ff0838e1-efd9-4046-843b-d413cbfa70ff
There was a problem hiding this comment.
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 insteadmasterbots.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