Skip to content

Commit

Permalink
added og:image
Browse files Browse the repository at this point in the history
  • Loading branch information
velascoandres committed Mar 9, 2024
1 parent 61b66dc commit 18a02fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Binary file added public/preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions src/app/view-whiteboard/[id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import { db } from '@/server/db'
export async function generateMetadata({ params }: {params: {id: string}}, parent: ResolvingMetadata) {
const id = Number(params.id)

const whiteboard = await findPublicWhiteboardById(db, { id })
const whiteboard = await findPublicWhiteboardById(db, { id, omitContent: true })


if (!whiteboard){
redirect('/not-found')
}


const previousImages = (await parent).openGraph?.images ?? []
const previousDescription = (await parent).openGraph?.description ?? ''

return {
Expand All @@ -28,7 +27,11 @@ export async function generateMetadata({ params }: {params: {id: string}}, paren
title: whiteboard.name,
description: whiteboard.description ?? previousDescription,
url: 'https://drawy-studio.vercel.app/',
images: [...previousImages],
images: [{
url: 'https://drawy-studio.vercel.app/preview.jpg',
width: 1200,
height: 630,
}],
siteName: 'Drawy studio',
}
} as Metadata
Expand Down
15 changes: 12 additions & 3 deletions src/server/api/whiteboard/usecases/find-public-whiteboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ import { type SearchByIdDto } from '@/dtos/shared-dtos'
import type * as schema from '@/server/db/schema'
import { NotFound } from '@/server/exceptions/not-found'

type Options = z.infer<typeof SearchByIdDto>

type Options = z.infer<typeof SearchByIdDto> & {omitContent?: boolean}

const findPublicWhiteboardById = async (db: PostgresJsDatabase<typeof schema>, options: Options) => {
const { id } = options
const { id, omitContent } = options

const currentWhiteboard = await db.query.whiteboards.findFirst({
where: (whiteboards, { eq, and }) => and(eq(whiteboards.id, id), eq(whiteboards.isPublic, true))
where: (whiteboards, { eq, and }) => and(eq(whiteboards.id, id), eq(whiteboards.isPublic, true)),
columns: {
id: true,
name: true,
description: true,
content: omitContent ? false : true,
createdAt: true,
updatedAt: true,
}
})

if (!currentWhiteboard){
Expand Down

0 comments on commit 18a02fb

Please sign in to comment.