From 31ad8c4def29512c81a968b1de2bb39aa52456e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Thu, 21 Oct 2021 17:22:49 +0200 Subject: [PATCH] fix(ideal-image): fix IdealImage in dev not handling ES import images properly (#5760) --- .../src/theme/IdealImage.js | 11 +++++++++-- .../_docs tests/tests/img-tests.mdx | 19 +++++++++++++++++++ website/_dogfooding/docs-tests-sidebars.js | 10 ++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 website/_dogfooding/_docs tests/tests/img-tests.mdx diff --git a/packages/docusaurus-plugin-ideal-image/src/theme/IdealImage.js b/packages/docusaurus-plugin-ideal-image/src/theme/IdealImage.js index 7679f53bb2..d5d0215f13 100644 --- a/packages/docusaurus-plugin-ideal-image/src/theme/IdealImage.js +++ b/packages/docusaurus-plugin-ideal-image/src/theme/IdealImage.js @@ -12,8 +12,15 @@ function Image(props) { const {alt, className, img} = props; // In dev env just use regular img with original file - if (img.default) { - return {alt}; + if (typeof img === 'string' || typeof img.default === 'string') { + return ( + {alt} + ); } return ( diff --git a/website/_dogfooding/_docs tests/tests/img-tests.mdx b/website/_dogfooding/_docs tests/tests/img-tests.mdx new file mode 100644 index 0000000000..885500b6a3 --- /dev/null +++ b/website/_dogfooding/_docs tests/tests/img-tests.mdx @@ -0,0 +1,19 @@ +# Image tests + +import Image from '@theme/IdealImage'; + +import docusaurusImport from '@site/static/img/docusaurus.png'; + +export const docusaurusRequire = require('@site/static/img/docusaurus.png'); + +## Regular images + + + + + +## Ideal images + + + + diff --git a/website/_dogfooding/docs-tests-sidebars.js b/website/_dogfooding/docs-tests-sidebars.js index 61fdaa1f23..02682bbdd8 100644 --- a/website/_dogfooding/docs-tests-sidebars.js +++ b/website/_dogfooding/docs-tests-sidebars.js @@ -13,6 +13,16 @@ module.exports = { className: 'red', label: 'Index', }, + { + type: 'category', + label: 'Tests', + items: [ + { + type: 'autogenerated', + dirName: 'tests', + }, + ], + }, { type: 'category', label: 'section',