This is an automated email from the ASF dual-hosted git repository.

liugddx pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/seatunnel-website.git


The following commit(s) were added to refs/heads/main by this push:
     new e2c6bd44b61 [Fix] Fix can not import icons (#335)
e2c6bd44b61 is described below

commit e2c6bd44b6159a0660082b4d8b77041b99d80040
Author: Jia Fan <[email protected]>
AuthorDate: Sat Sep 21 21:00:56 2024 +0800

    [Fix] Fix can not import icons (#335)
---
 src/theme/DocCard/index.js | 45 ++++++++++++++-------------------------------
 1 file changed, 14 insertions(+), 31 deletions(-)

diff --git a/src/theme/DocCard/index.js b/src/theme/DocCard/index.js
index 982ff35f63f..5c5f0a8541f 100644
--- a/src/theme/DocCard/index.js
+++ b/src/theme/DocCard/index.js
@@ -8,6 +8,17 @@ import {
 import isInternalUrl from '@docusaurus/isInternalUrl';
 import {translate} from '@docusaurus/Translate';
 import styles from './styles.module.css';
+
+function importAllIcons(r) {
+    let images = {};
+    r.keys().forEach((item, index) => {
+        images[item.replace('./', '').replace(/\.[^/.]+$/, '').toLowerCase()] 
= r(item);
+    });
+    return images;
+}
+
+const images = importAllIcons(require.context('../../../docs/images/icons', 
false, /\.(png|jpe?g|svg)$/));
+
 function CardContainer({href, children}) {
   return (
     <Link
@@ -59,38 +70,10 @@ function CardCategory({item}) {
   );
 }
 function CardLink({ item }) {
-    const isUrl = (str) => {
-        try {
-            new URL(str);
-            return true;
-        } catch {
-            return false;
-        }
-    };
-
-    const isLocalImage = (str) => {
-        return str && str.startsWith('img:');
-    };
-
-    const isSvg = (str) => {
-        return str && (str.endsWith('.svg') || str.includes('.svg?'));
-    };
-
     const getIconElement = () => {
-        const myEmoji = item?.customProps?.link;
-
-        if (isLocalImage(myEmoji)) {
-            const localImagePath = myEmoji.replace('img:', '');
-            return <img src={localImagePath} alt={item.label} style={{ width: 
'17px', height: '17px' }} />;
-        } else if (isSvg(myEmoji)) {
-            return <img
-                src={myEmoji}
-                alt={item.label}
-                style={{width: '18px', height: '18px'}}
-                className="svg-icon"
-            />
-        } else if (isUrl(myEmoji)) {
-            return <img src={myEmoji} alt={item.label} style={{ width: '24px', 
height: '24px' }} />;
+        if (images[item.label.toLowerCase()]) {
+            return <img src={images[item.label.toLowerCase()].default} 
alt={item.label}
+                        style={{width: '24px', height: '24px'}}/>;
         } else {
             return isInternalUrl(item.href) ? '📄️' : '🔗';
         }

Reply via email to