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: opengraph for base network #323

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 9 additions & 17 deletions ogi/components/OgImage/gallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ defineOptions({
const props = defineProps<{
title: string
image: string
usd: string
price: string
symbol: string
usd?: string
price?: string
symbol?: string
network: string
}>()

Expand All @@ -21,25 +21,20 @@ const cover: CSSProperties = {
}

const parseUsd = computed(() =>
parseFloat(props.usd) ? `$${parseFloat(props.usd)}` : '--',
props.usd && parseFloat(props.usd) ? `$${parseFloat(props.usd)}` : '--',
)

const parsePrice = computed(() =>
parseFloat(props.price) ? `${parseFloat(props.price)} ${props.symbol}` : '--',
props.price && parseFloat(props.price) ? `${parseFloat(props.price)} ${props.symbol}` : '--',
)
</script>

<template>
<img :src="image" :alt="title" :style="cover" class="h-full w-full" />

<div
class="flex flex-col justify-end h-full w-full bg-slate-900/85 text-white p-20 text-2xl font-bold absolute inset-0"
>
<img
:src="image"
:alt="title"
class="w-30 rounded-md border border-white"
/>
class="flex flex-col justify-end h-full w-full bg-slate-900/85 text-white p-20 text-2xl font-bold absolute inset-0">
<img :src="image" :alt="title" class="w-30 rounded-md border border-white" />
<h1 class="mb-6 font-bold">{{ title }}</h1>
<div class="flex flex-row">
<div>
Expand All @@ -59,9 +54,6 @@ const parsePrice = computed(() =>
</div>
</div>

<img
src="https://raw.githubusercontent.com/kodadot/kodadot-presskit/main/pre-v4/png/KodalightV4.png"
alt="logo"
class="absolute top-20 right-20 w-40"
/>
<img src="https://raw.githubusercontent.com/kodadot/kodadot-presskit/main/pre-v4/png/KodalightV4.png" alt="logo"
class="absolute top-20 right-20 w-40" />
</template>
1 change: 1 addition & 0 deletions ogi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@polkadot/util": "^12.6.2",
"remark-parse": "^11.0.0",
"remark-stringify": "^11.0.0",
"thirdweb": "^5.42.0",
"unified": "^11.0.4",
"vfile-matter": "^5.0.0"
}
Expand Down
60 changes: 60 additions & 0 deletions ogi/pages/base/gallery/[id].vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<div>
<p>address: {{ address }}</p>
<p>token: {{ token }}</p>
{{ item }}
<div>
<p>image:</p>
<img :src="image" :alt="item.metadata.name" />
</div>
</div>
</template>

<script lang="ts" setup>
import { createThirdwebClient, getContract } from 'thirdweb'
import { base } from 'thirdweb/chains';
import { getNFT } from 'thirdweb/extensions/erc721'

const router = useRouter()
const id = router.currentRoute.value.params.id.toString().split('-')
const address = id[0]
const token = id[1] as unknown as bigint

const client = createThirdwebClient({
clientId: 'd0455344acaa6fb760281466980f3ec6'
})
const contract = getContract({
client,
chain: base,
address: address,
})
const item = await getNFT({
contract,
tokenId: token
})

const imageUri = item.metadata.image || 'https://koda.art/k_card.png'
Copy link
Member

Choose a reason for hiding this comment

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

you would probably need to used sanitizer :) , just in case

const image = useState(() => '')
// ensure to callOnce to avoid missmatch content between ssr/csr
await callOnce(async () => image.value = await parseImage(imageUri, false))

defineOgImage({
component: 'gallery',
props: {
title: item.metadata.name,
image,
network: 'base'
}
})

useSeoMeta({
title: seoTitle(item.metadata.name),
description: item.metadata.description,
ogTitle: seoTitle(item.metadata.name),
ogDescription: item.metadata.description,
ogType: 'website',
twitterCard: 'summary_large_image',
twitterTitle: seoTitle(item.metadata.name),
twitterImageAlt: item.metadata.name,
})
</script>
2 changes: 1 addition & 1 deletion ogi/utils/seo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const seoTitle = (title: string) => {
export const seoTitle = (title='') => {
return `${title} | Generative Art Marketplace`
}
Loading
Loading