bookmarks: account for relative urls more robustly (#4022)
Fixes up url's that don't have `/` in front or `http` ### Change Type <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `feature` — New feature - [x] `improvement` — Product improvement - [ ] `api` — API change - [ ] `bugfix` — Bug fix - [ ] `other` — Changes that don't affect SDK users, e.g. internal or .com changes ### Release Notes - Bookmark extractor: account for relative urls more robustly
This commit is contained in:
parent
f19ed94422
commit
41c3b1e3df
5 changed files with 14 additions and 14 deletions
|
@ -46,12 +46,12 @@ export const metadata: Metadata = {
|
|||
},
|
||||
icons: [
|
||||
{ rel: 'shortcut icon', url: '/favicon.svg' },
|
||||
{ rel: 'icon', url: 'favicon-32x32.svg', sizes: '32x32' },
|
||||
{ rel: 'icon', url: 'favicon-16x16.svg', sizes: '16x16' },
|
||||
{ rel: 'apple-touch-icon', url: 'apple-touch-icon.png' },
|
||||
{ rel: 'apple-touch-icon', url: 'apple-touch-icon-152x152.svg', sizes: '152x152' },
|
||||
{ rel: 'apple-touch-icon', url: 'apple-touch-icon-180x180.svg', sizes: '180x180' },
|
||||
{ rel: 'apple-touch-icon', url: 'apple-touch-icon-167x167.svg', sizes: '167x167' },
|
||||
{ rel: 'icon', url: '/favicon-32x32.svg', sizes: '32x32' },
|
||||
{ rel: 'icon', url: '/favicon-16x16.svg', sizes: '16x16' },
|
||||
{ rel: 'apple-touch-icon', url: '/apple-touch-icon.png' },
|
||||
{ rel: 'apple-touch-icon', url: '/apple-touch-icon-152x152.svg', sizes: '152x152' },
|
||||
{ rel: 'apple-touch-icon', url: '/apple-touch-icon-180x180.svg', sizes: '180x180' },
|
||||
{ rel: 'apple-touch-icon', url: '/apple-touch-icon-167x167.svg', sizes: '167x167' },
|
||||
],
|
||||
}
|
||||
|
||||
|
|
|
@ -31,10 +31,10 @@ export async function unfurl(url: string) {
|
|||
$('link[rel="icon"]').attr('href') ??
|
||||
undefined
|
||||
|
||||
if (image?.startsWith('/')) {
|
||||
if (image && !image?.startsWith('http')) {
|
||||
image = new URL(image, url).href
|
||||
}
|
||||
if (favicon?.startsWith('/')) {
|
||||
if (favicon && !favicon?.startsWith('http')) {
|
||||
favicon = new URL(favicon, url).href
|
||||
}
|
||||
|
||||
|
|
|
@ -58,10 +58,10 @@ export async function createAssetFromUrl({ url }: { type: 'url'; url: string }):
|
|||
description:
|
||||
doc.head.querySelector('meta[property="og:description"]')?.getAttribute('content') ?? '',
|
||||
}
|
||||
if (meta.image.startsWith('/')) {
|
||||
if (!meta.image.startsWith('http')) {
|
||||
meta.image = new URL(meta.image, url).href
|
||||
}
|
||||
if (meta.favicon.startsWith('/')) {
|
||||
if (!meta.favicon.startsWith('http')) {
|
||||
meta.favicon = new URL(meta.favicon, url).href
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
@ -43,10 +43,10 @@ export async function onCreateAssetFromUrl({
|
|||
description:
|
||||
doc.head.querySelector('meta[property="og:description"]')?.getAttribute('content') ?? '',
|
||||
}
|
||||
if (meta.image.startsWith('/')) {
|
||||
if (!meta.image.startsWith('http')) {
|
||||
meta.image = new URL(meta.image, url).href
|
||||
}
|
||||
if (meta.favicon.startsWith('/')) {
|
||||
if (!meta.favicon.startsWith('http')) {
|
||||
meta.favicon = new URL(meta.favicon, url).href
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
@ -148,10 +148,10 @@ export function registerDefaultExternalContentHandlers(
|
|||
description:
|
||||
doc.head.querySelector('meta[property="og:description"]')?.getAttribute('content') ?? '',
|
||||
}
|
||||
if (meta.image.startsWith('/')) {
|
||||
if (!meta.image.startsWith('http')) {
|
||||
meta.image = new URL(meta.image, url).href
|
||||
}
|
||||
if (meta.favicon.startsWith('/')) {
|
||||
if (!meta.favicon.startsWith('http')) {
|
||||
meta.favicon = new URL(meta.favicon, url).href
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in a new issue