Skip to content

Commit

Permalink
Customer Testimonial OG image (highlight#7445)
Browse files Browse the repository at this point in the history
## Summary

See attached issue.
We want an OG image for customer testimonials, similar to blog posts.

## How did you test this change?

Checking opengraph.xyz


https://www.opengraph.xyz/url/https%3A%2F%2Fhighlight-landing-g0mpgbx8k-highlight-run.vercel.app%2Fcustomers%2Fmotion

<img width="432" alt="image"
src="https://github.com/highlight/highlight/assets/25088104/2eb3ac7a-fa3c-425b-bd53-20f8514b19b3">

## Are there any deployment considerations?

No

## Does this work require review from our design team?

No
  • Loading branch information
Abhishek-More authored Jan 15, 2024
1 parent 48be97a commit af13af3
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 46 deletions.
1 change: 1 addition & 0 deletions highlight.io/components/common/Navbar/ResourceDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const ResourceDropdown = ({ isOpen }: { isOpen?: boolean }) => {
title: 'Customers',
icon: <Icons.HiUsers className={styles.copyOnLight} />,
link: '/customers',
sameTab: true,
},
{
title: 'Changelog',
Expand Down
4 changes: 0 additions & 4 deletions highlight.io/pages/api/docs/github.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import yaml from 'js-yaml'
import path from 'path'
import logger from '../../../highlight.logger'

// ignored files from docs
export const IGNORED_DOCS_PATHS = new Set<string>([
Expand Down Expand Up @@ -87,7 +86,6 @@ export const processDocPath = function (
}

export const getGithubDocsPaths = async (path: string = 'docs-content/') => {
logger.info({ path }, 'getGithubDocsPaths')
const url = `https://api.github.com/repos/highlight/highlight/contents/${path}`
const response = await fetch(url, {
headers: githubHeaders,
Expand Down Expand Up @@ -137,7 +135,6 @@ export const getGithubDoc = async (
meta: DocMeta
content: string
} | null> => {
logger.info({ slug }, 'getGithubDoc')
const response = await fetch(
`https://api.github.com/repos/highlight/highlight/contents/docs-content/${slug}.md`,
{
Expand All @@ -163,7 +160,6 @@ export const getGithubDoc = async (
} else if (!slug.endsWith('/index')) {
return getGithubDoc(`${slug}/index`)
} else {
logger.error(response, 'error fetching from the github api')
return null
}
}
7 changes: 3 additions & 4 deletions highlight.io/pages/api/docs/search/[searchValue].ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { promises as fsp } from 'fs'
import path from 'path'
import type { NextApiRequest, NextApiResponse } from 'next'
import { getDocsPaths, readMarkdown } from '../../../docs/[[...doc]]'
import path from 'path'
import removeMd from 'remove-markdown'
import { withPageRouterHighlight } from '../../../../highlight.config'
import logger from '../../../../highlight.logger'
import { getDocsPaths, readMarkdown } from '../../../docs/[[...doc]]'

export const SEARCH_RESULT_BLURB_LENGTH = 100

Expand All @@ -24,7 +23,7 @@ const handler = withPageRouterHighlight(async function handler(
res: NextApiResponse,
) {
const searchValue = [req.query.searchValue].flat().join('').toLowerCase()
logger.info('running api docs search query', { searchValue })
// logger.info('running api docs search query', { searchValue })
const docPaths = await getDocsPaths(fsp, undefined)
const paths: SearchResult[] = await Promise.all(
docPaths.map(async (doc) => {
Expand Down
54 changes: 28 additions & 26 deletions highlight.io/pages/api/og/blog/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ImageResponse } from '@vercel/og'
import { NextRequest, URLPattern } from 'next/server'
import { backdrop, font, fontLight } from '../util'
import { withEdgeRouterHighlight } from '../../../../highlight.edge.config'
import { backdrop, font, fontLight } from '../util'

export const config = {
runtime: 'edge',
Expand Down Expand Up @@ -54,7 +54,7 @@ const handler = async function (req: NextRequest) {
display: 'flex',
color: 'white',
flexDirection: 'column',
width: 600,
width: 800,
height: '100%',
justifyContent: 'space-between',
paddingTop: 50,
Expand All @@ -67,7 +67,7 @@ const handler = async function (req: NextRequest) {
style={{
position: 'absolute',
top: 0,
left: 550,
left: 750,
}}
width={650}
height={650}
Expand All @@ -88,25 +88,27 @@ const handler = async function (req: NextRequest) {
fill="white"
/>
</svg>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<div tw={'flex flex-col justify-center'}>
<span
style={{
color: '#0D0225',
marginBottom: 20,
backgroundColor: '#ebff5e',
padding: '6px 18px 2px 18px',
borderRadius: 100,
backgroundColor: '#0D0225',
border: '1px solid #ebff5e',
padding: '10px 18px 6px 18px',
marginBottom: 30,
borderRadius: 8,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '200px',
width: '175px',
maxWidth: '175px',
color: '#ebff5e',
}}
>
Highlight Blog
</span>
<span
style={{
fontSize: 50,
fontSize: 45,
marginBottom: 60,
lineHeight: '1.2em',
maxHeight: '4.2em',
Expand All @@ -116,21 +118,21 @@ const handler = async function (req: NextRequest) {
>
{title || slug}
</span>
<div tw={'flex flex-row items-center'}>
<div tw={'flex flex-col'}>
<span style={{ fontSize: 24 }}>
{firstName || ''} {lastName || ''}
</span>
<span
style={{
color: '#DFDFDF',
fontSize: 24,
fontFamily: '"PoppinsLight"',
}}
>
{role || ''}
</span>
</div>
</div>
<div tw={'flex flex-row items-center'}>
<div tw={'flex flex-col'}>
<span style={{ fontSize: 24 }}>
{firstName || ''} {lastName || ''}
</span>
<span
style={{
color: '#DFDFDF',
fontSize: 24,
fontFamily: '"PoppinsLight"',
}}
>
{role || ''}
</span>
</div>
</div>
</div>
Expand Down
155 changes: 155 additions & 0 deletions highlight.io/pages/api/og/customer/[slug].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { ImageResponse } from '@vercel/og'
import { NextRequest, URLPattern } from 'next/server'
import { withEdgeRouterHighlight } from '../../../../highlight.edge.config'
import { backdrop, font, fontLight } from '../util'

export const config = {
runtime: 'edge',
}

//Example query: https://highlight.io/api/og/customer/highlight-launch-week-day-5?title=Day+5%3A+Our+Partners+%26+Supporters&fname=Vadim&lname=Korolik&role=Co-Founder+%26+CTO
//This query is sent from each customer slug to generate the og image
const handler = async function (req: NextRequest) {
const query = req.nextUrl.href
const fontData = await font
const fontLightData = await fontLight
const backdropData = await backdrop
const backDropBase64 = btoa(
new Uint8Array(backdropData).reduce(function (p, c) {
return p + String.fromCharCode(c)
}, ''),
)

const slug = new URLPattern({ pathname: '/api/og/customer/:slug' }).exec(
req.url,
)?.pathname.groups.slug

const url = new URL(query)
const title = url.searchParams.get('title')
const firstName = url.searchParams.get('fname')
const lastName = url.searchParams.get('lname')
const role = url.searchParams.get('role')

return new ImageResponse(
(
<div
style={{
height: '100%',
width: '100%',
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
justifyContent: 'flex-start',
backgroundColor: '#0D0225',
}}
>
<div
style={{
display: 'flex',
color: 'white',
flexDirection: 'column',
width: 800,
height: '100%',
justifyContent: 'space-between',
paddingTop: 50,
paddingLeft: 50,
paddingBottom: 50,
}}
>
<img
alt={'backdrop'}
style={{
position: 'absolute',
top: 0,
left: 750,
}}
width={650}
height={650}
src={`data:image/png;base64,${backDropBase64}`}
></img>
<svg
width="68"
height="68"
viewBox="0 0 68 68"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<circle cx="34" cy="34" r="34" fill="#6C37F4" />
<path
fillRule="evenodd"
clipRule="evenodd"
d="M23.375 19.125C21.0278 19.125 19.125 21.0278 19.125 23.375V44.625C19.125 46.9722 21.0278 48.875 23.375 48.875H36.125L25.5 19.125H23.375ZM31.875 19.125L42.5 48.875H44.625C46.9722 48.875 48.875 46.9722 48.875 44.625V23.375C48.875 21.0278 46.9722 19.125 44.625 19.125H31.875Z"
fill="white"
/>
</svg>
<div tw={'flex flex-col justify-center'}>
<span
style={{
backgroundColor: '#0D0225',
border: '1px solid #ebff5e',
padding: '10px 18px 6px 18px',
marginBottom: 30,
borderRadius: 8,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '200px',
maxWidth: '200px',
color: '#ebff5e',
}}
>
Highlight Customer
</span>
<span
style={{
fontSize: 45,
marginBottom: 60,
lineHeight: '1.2em',
maxHeight: '4.2em',
textOverflow: 'ellipsis',
overflow: 'hidden',
}}
>
{title || slug}
</span>
</div>
<div tw={'flex flex-row items-center'}>
<div tw={'flex flex-col'}>
<span style={{ fontSize: 24 }}>
{firstName || ''} {lastName || ''}
</span>
<span
style={{
color: '#DFDFDF',
fontSize: 24,
fontFamily: '"PoppinsLight"',
}}
>
{role || ''}
</span>
</div>
</div>
</div>
</div>
),
{
width: 1200,
height: 630,
fonts: [
{
name: 'Poppins',
data: fontData,
weight: 600,
style: 'normal',
},
{
name: 'PoppinsLight',
data: fontLightData,
weight: 400,
style: 'normal',
},
],
},
)
}
export default withEdgeRouterHighlight(handler)
9 changes: 6 additions & 3 deletions highlight.io/pages/blog/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
params.set('lname', suggestedPost.author?.lastName || '')
params.set('role', suggestedPost.author?.title || '')

const metaImageURL = `https://${'www.highlight.io'}/api/og/blog/${
suggestedPost.slug
}?${params.toString()}`
const metaImageURL = `https://${
process.env.NEXT_PUBLIC_VERCEL_URL || 'www.highlight.io'
}/api/og/blog/${suggestedPost.slug}?${params.toString()}`

suggestedPost.image.url = metaImageURL
}
Expand Down Expand Up @@ -240,6 +240,9 @@ const PostPage = ({
process.env.NEXT_PUBLIC_VERCEL_URL
}/api/og/blog/${post.slug}?${params.toString()}`

console.log(post)
console.log(metaImageURL)

return (
<>
<Meta
Expand Down
Loading

0 comments on commit af13af3

Please sign in to comment.