-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
docs: update og generation code with local assets #64888
Merged
Merged
Conversation
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
I tried loading a file in `public` folder(say `./public/og.png`). The Node.js local assets example code did work locally with `next start` but failed with error message `Error: ENOENT: no such file or directory` when deployed to vercel. Then I found out the trick here is the relative path here. On my local machine the CWD is the root folder so the relative path works, And it seems the CWD is somewhat different on vercel runtime. Also it's worthy to note where the local assets should be placed, so that devs could be less confused.
KagamiChan
requested review from
timneutkens,
ijjk,
shuding,
styfle,
huozhi,
ztanner and
a team
as code owners
April 22, 2024 18:58
KagamiChan
requested review from
jh3y and
timeyoutakeit
and removed request for
a team
April 22, 2024 18:58
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
styfle
reviewed
Apr 22, 2024
docs/02-app/02-api-reference/02-file-conventions/01-metadata/opengraph-image.mdx
Outdated
Show resolved
Hide resolved
styfle
reviewed
Apr 22, 2024
docs/02-app/02-api-reference/02-file-conventions/01-metadata/opengraph-image.mdx
Outdated
Show resolved
Hide resolved
styfle
approved these changes
Apr 22, 2024
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.
Thanks!
ijjk
reviewed
Apr 22, 2024
docs/02-app/02-api-reference/02-file-conventions/01-metadata/opengraph-image.mdx
Outdated
Show resolved
Hide resolved
styfle
approved these changes
Apr 23, 2024
ijjk
approved these changes
Apr 23, 2024
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This PR fixes OpenGraph generation code with local assets in Node.js runtime. Also adds some notes on file location.
The updated code is validated with my project on vercel.
Why?
I tried loading a file in
public
folder(say./public/og.png
). The Node.js local assets example code did work locally withnext start
but failed with error messageError: ENOENT: no such file or directory
when deployed to vercel.Then I found out the trick here is the relative path. On my local machine the CWD is the root folder so the relative path works, And it seems the CWD is somewhat different on vercel runtime. Then I tried using
process.cwd()
to get the CWD and construct a absolute path, this has been validated with my project on vercel.Also it's worthy to note where the local assets should be placed, so that devs could be less confused.