-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get og conf images + calculate metadata dynamically (#1352)
- Loading branch information
Showing
6 changed files
with
106 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { imageMeta } from 'image-meta' | ||
|
||
const upcomingConferences: Array<{ | ||
name: string | ||
dates: string | ||
link: string | ||
location: string | ||
}> = [ | ||
{ | ||
name: 'Vue.js Nation', | ||
dates: '24-25 January', | ||
link: 'https://vuejsnation.com/', | ||
location: '🌍', | ||
}, | ||
{ | ||
name: 'Vue.js Amsterdam', | ||
dates: '28-29 February', | ||
link: 'https://vuejs.amsterdam/', | ||
location: '🇳🇱', | ||
}, | ||
{ | ||
name: 'CityJS London', | ||
dates: '3-5 April', | ||
link: 'https://london.cityjsconf.org/', | ||
location: '🇬🇧', | ||
}, | ||
{ | ||
name: 'Vue.js Live', | ||
dates: '25-26 April', | ||
link: 'https://vuejslive.com/', | ||
location: '🌍', | ||
}, | ||
{ | ||
name: 'Vueconf US', | ||
dates: '15-17 May', | ||
link: 'https://vueconf.us/', | ||
location: '🇺🇸', | ||
}, | ||
{ | ||
name: 'Middlesborough FE', | ||
dates: '17 July', | ||
link: 'https://middlesbroughfe.co.uk/', | ||
location: '🇬🇧', | ||
}, | ||
] | ||
|
||
export default defineEventHandler(async () => { | ||
if (!import.meta.dev && !import.meta.prerender) return [] | ||
|
||
return Promise.all( | ||
upcomingConferences.map(async conference => { | ||
const html = await $fetch<string>(conference.link) | ||
const ogImage = html.match( | ||
/<meta[^>]*property="og:image"[^>]*content="([^"]+)"|<meta[^>]*content="([^"]+)"[^>]*property="og:image"/ | ||
)?.[1] | ||
|
||
if (!ogImage) { | ||
return { | ||
...conference, | ||
image: { | ||
url: null, | ||
width: null, | ||
height: null, | ||
} | ||
} | ||
} | ||
|
||
// if (import.meta.dev) { | ||
// return { | ||
// ...conference, | ||
// image: { | ||
// url: ogImage, | ||
// width: 1200, | ||
// height: 630, | ||
// }, | ||
// } | ||
// } | ||
|
||
const res = await $fetch(ogImage!, { responseType: 'arrayBuffer' }) as ArrayBuffer | ||
const data = Buffer.from(res) | ||
const metadata = imageMeta(data) | ||
|
||
return { | ||
...conference, | ||
image: { | ||
url: ogImage, | ||
width: metadata.width, | ||
height: metadata.height, | ||
}, | ||
} | ||
}) | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e9d8b4e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
roe.dev – ./
danielroe.com
roe.dev
danielroe.me
www.nuxt.ninja
nuxt.ninja
www.danielcroe.com
www.danielroe.me
www.danielroe.com
iocalho.st
danielcroe.com
roedev-danielroe.vercel.app
roedev-git-main-danielroe.vercel.app