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

Opengraph image generation #135

Merged
merged 43 commits into from
Dec 18, 2024
Merged

Opengraph image generation #135

merged 43 commits into from
Dec 18, 2024

Conversation

Shane98c
Copy link
Member

@Shane98c Shane98c commented Dec 10, 2024

This sets up dynamic social card generation via next/og for both the overall website and individual preprint pages.

Browse to /opengraph-image for the main site version, and /preprint/[id]/opengraph-image/1 for the preprint specific version.

I ran into some odd errors when trying to use our formatter utils, so ended up replicating them in the files. Also created a couple reused components, which I placed in the components/og-image folder.

I think these are ready visually, with one potential wording change for the main card still to come. One other potential visual issue is that a lot of platforms add rounded corners to social card images, so our bezeled border loses a bit of its flair in those cases.

Currently these are set up to cache fonts indefinitely, and to refetch preprint count/title and regenerate the image after a week. I could imagine shortening this. Performance wise, it looks like raw image creation/fetch takes a bit over a second, with subsequent serves far faster than that, fwiw.

Copy link

vercel bot commented Dec 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cdrxiv-org ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 18, 2024 4:15pm

@Shane98c
Copy link
Member Author

ok I think this is ready to go!

We still have a few tradeoffs with the edge runtime - there aren't great ways to revalidate cache, so we're preventing any caching on our janeway request which leads to a duplicate call during metadata generation (used in alt text). I think this is probably ok.

Tested that a redeploy busts the cache, and it also looks like our cache-control in the ImageResponse header is working to cause regeneration after a day, so things shouldn't get too stale!

Copy link
Member

@katamartin katamartin left a comment

Choose a reason for hiding this comment

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

Left one small suggestion, otherwise lgtm!

Comment on lines 74 to 83
const fullAuthorString = authors
.map((author) =>
`${author?.first_name || ''} ${author?.last_name || ''}`.trim(),
)
.join(', ')
if (fullAuthorString.length < 35) {
return fullAuthorString
}
const firstAuthor = authors[0]
return firstAuthor?.last_name ? `${firstAuthor.last_name} et al.` : ''
Copy link
Member

Choose a reason for hiding this comment

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

nit: we could still pull in authorsList here to reduce duplication / enforce some consistency between social card formatting and in-app formatting

Suggested change
const fullAuthorString = authors
.map((author) =>
`${author?.first_name || ''} ${author?.last_name || ''}`.trim(),
)
.join(', ')
if (fullAuthorString.length < 35) {
return fullAuthorString
}
const firstAuthor = authors[0]
return firstAuthor?.last_name ? `${firstAuthor.last_name} et al.` : ''
const fullAuthorString = authorsList(preprint.authors)
if (fullAuthorString.length < 35) {
return fullAuthorString
}
return authorsList(preprint.authors, { abbreviate: true })

marginTop: '-5px',
}}
>
Preprints Available
Copy link
Member

Choose a reason for hiding this comment

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

Should we follow Tyler's nudge to use a more general term?

Suggested change
Preprints Available
Titles Hosted

or

Suggested change
Preprints Available
Submissions Contributed

@Shane98c Shane98c merged commit 043edd9 into staging Dec 18, 2024
6 checks passed
@Shane98c Shane98c deleted the Shane98c/social-cards branch December 18, 2024 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants