Commit 097ef6a3 authored by Brendan Wong's avatar Brendan Wong Committed by GitHub

feat: fallback metadata injection (#7070)

* feat: fallback metadata

* fix lint

* Update tsconfig.json

* feedback

* fix: cloudfunctions

* update test
parent 984cf819
/* eslint-disable import/no-unused-modules */
import { MetaTagInjector } from './components/metaTagInjector'
export const onRequest: PagesFunction = async ({ request, next }) => {
const imageUri = new URL(request.url).origin + '/images/1200x630_Rich_Link_Preview_Image.png'
const data = {
title: 'Uniswap Interface',
image: imageUri,
url: request.url,
}
const res = next()
try {
return new HTMLRewriter().on('head', new MetaTagInjector(data)).transform(await res)
} catch (e) {
return res
}
}
This diff is collapsed.
const defaultUrls = ['http://127.0.0.1:3000/', 'http://127.0.0.1:3000/swap', 'http://127.0.0.1:3000/pools']
test.each(defaultUrls)('should inject metadata for valid collections', async (defaultUrl) => {
const body = await fetch(new Request(defaultUrl)).then((res) => res.text())
expect(body).toMatchSnapshot()
expect(body).toContain(`<meta property="og:title" content="Uniswap Interface"/>`)
expect(body).toContain(
`<meta property="og:image" content="http://127.0.0.1:3000/images/1200x630_Rich_Link_Preview_Image.png"/>`
)
expect(body).toContain(`<meta property="og:image:width" content="1200"/>`)
expect(body).toContain(`<meta property="og:image:height" content="630"/>`)
expect(body).toContain(`<meta property="og:type" content="website"/>`)
expect(body).toContain(`<meta property="og:url" content="${defaultUrl}"/>`)
expect(body).toContain(`<meta property="og:image:alt" content="Uniswap Interface"/>`)
expect(body).toContain(`<meta property="twitter:card" content="summary_large_image"/>`)
expect(body).toContain(`<meta property="twitter:title" content="Uniswap Interface"/>`)
expect(body).toContain(
`<meta property="twitter:image" content="http://127.0.0.1:3000/images/1200x630_Rich_Link_Preview_Image.png"/>`
)
expect(body).toContain(`<meta property="twitter:image:alt" content="Uniswap Interface"/>`)
})
...@@ -38,9 +38,7 @@ test.each(collections)('should inject metadata for valid collections', async (co ...@@ -38,9 +38,7 @@ test.each(collections)('should inject metadata for valid collections', async (co
const invalidCollections = [ const invalidCollections = [
'http://127.0.0.1:3000/nfts/collection/0xed5af388653567af2f388e6224dc7c4b3241c545', 'http://127.0.0.1:3000/nfts/collection/0xed5af388653567af2f388e6224dc7c4b3241c545',
'http://127.0.0.1:3000/nfts/collection/0xed5af388653567af2f388e6224dc7c4b3241c545/10',
'http://127.0.0.1:3000/nfts/collection/0xed5af388653567af2f388e6224dc7c4b3241c545//', 'http://127.0.0.1:3000/nfts/collection/0xed5af388653567af2f388e6224dc7c4b3241c545//',
'http://127.0.0.1:3000/nfts/collection',
] ]
test.each(invalidCollections)( test.each(invalidCollections)(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment