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

feat: Using Next.js Image component in markdown files #6454

Merged
merged 7 commits into from
Mar 12, 2024

Conversation

canerakdas
Copy link
Member

Description

With this PR, we are starting to use the next/image Image component instead of the HTML img tag in markdown files.

Validation

The img tags added from markdown pages should work correctly.

You can check whether the image uses next/image or not via the extra attributes it adds(decoding,data-nimg,style)

image

Ex: /en/about

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run npx turbo format to ensure the code follows the style guide.
  • I have run npx turbo test to check if all tests are passing.
  • I have run npx turbo build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

@canerakdas canerakdas requested a review from a team as a code owner March 5, 2024 22:57
Copy link

vercel bot commented Mar 5, 2024

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

Name Status Preview Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview Mar 12, 2024 8:04am

Copy link
Contributor

github-actions bot commented Mar 5, 2024

Lighthouse Results

URL Performance Accessibility Best Practices SEO Report
/en 🟢 96 🟢 90 🟢 100 🟢 91 🔗
/en/about 🟢 100 🟢 91 🟢 96 🟢 91 🔗
/en/about/previous-releases 🟢 99 🟢 90 🟢 100 🟢 92 🔗
/en/download 🟢 100 🟠 89 🟢 100 🟢 91 🔗
/en/blog 🟢 100 🟢 90 🟢 96 🟢 92 🔗

Copy link
Contributor

github-actions bot commented Mar 5, 2024

Unit Test Coverage Report

Lines Statements Branches Functions
Coverage: 84%
80.03% (449/561) 79.55% (144/181) 71.17% (79/111)

Unit Test Report

Tests Skipped Failures Errors Time
90 0 💤 0 ❌ 0 🔥 4.414s ⏱️

@canerakdas canerakdas marked this pull request as draft March 6, 2024 10:38
@canerakdas
Copy link
Member Author

It breaks markdown formatted images, I will add a wrapper component that will support the markup formatted images as well;

Example usage on here;
https://nodejs-fciqu3xpl-openjs.vercel.app/en/about/previous-releases

@ovflowd
Copy link
Member

ovflowd commented Mar 6, 2024

It breaks markdown formatted images, I will add a wrapper component that will support the markup formatted images as well;

Example usage on here; nodejs-fciqu3xpl-openjs.vercel.app/en/about/previous-releases

Like we have with our Link component? You can do it like, use Next Image component if width/height provided otherwise use HTML img component. Or IDK

@canerakdas
Copy link
Member Author

Like we have with our Link component?

Yes, I have updated the PR 🎉

Can I get a re-review for this PR? cc @nodejs/nodejs-website

@canerakdas canerakdas marked this pull request as ready for review March 6, 2024 13:28
@canerakdas canerakdas added the github_actions:pull-request Trigger Pull Request Checks label Mar 6, 2024
@github-actions github-actions bot removed the github_actions:pull-request Trigger Pull Request Checks label Mar 6, 2024
pages/en/about/index.mdx Outdated Show resolved Hide resolved
@ovflowd ovflowd enabled auto-merge March 12, 2024 10:17
@ovflowd ovflowd disabled auto-merge March 12, 2024 10:17
@ovflowd ovflowd added the github_actions:pull-request Trigger Pull Request Checks label Mar 12, 2024
@ovflowd ovflowd enabled auto-merge March 12, 2024 10:17
@github-actions github-actions bot removed the github_actions:pull-request Trigger Pull Request Checks label Mar 12, 2024
@ovflowd ovflowd added this pull request to the merge queue Mar 12, 2024
Merged via the queue into nodejs:main with commit af0f82e Mar 12, 2024
15 checks passed
// We disable image optimisation during static export builds
unoptimized: ENABLE_STATIC_EXPORT,
// We allow SVGs to be used as images
dangerouslyAllowSVG: true,
Copy link
Member

Choose a reason for hiding this comment

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

@canerakdas @ovflowd Why is dangerouslyAllowSVG enabled?

Was something not working when it was disabled?

Copy link
Member Author

Choose a reason for hiding this comment

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

@styfle For example, we were getting error when we were not able to load the following image on the https://nodejs.org/en/about/previous-releases page

The image we are trying to load;
https://raw.githubusercontent.com/nodejs/Release/main/schedule.svg?sanitize=true

The requested resource "https://raw.githubusercontent.com/nodejs/Release/main/schedule.svg?sanitize=true" has type "image/svg+xml" but dangerouslyAllowSVG is disabled

Copy link
Member

Choose a reason for hiding this comment

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

@canerakdas Seem like you could add unoptimized=true prop for that image instead of opening the risk for all images with this config.

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I know, since this image is generated from Markdown using MDX, I can't directly add unoptimized. prop Instead, I updated the MDXImage component to serve images with the .svg extension as unoptimized

Here is the PR; #7244

Thank you for the feedback!

@canerakdas canerakdas mentioned this pull request Nov 19, 2024
5 tasks
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.

7 participants