Skip to content

Commit

Permalink
⬆️ UPDATE fix slider img url
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwu51 committed Nov 22, 2024
1 parent e95100c commit b9d0088
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion app/components/Slider.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
'use client'
import AwesomeSlider from 'react-awesome-slider';
import 'react-awesome-slider/dist/styles.css';
import React from 'react';

export default AwesomeSlider


export default function Slider({children}) {
const replaceImageDomain = (node) => {
// 如果是 img 元素,替换 src
if (React.isValidElement(node) && node.type === 'img') {
return React.cloneElement(node, {
src: node.props.src.replace('i.imgur.com', 'sunwu51.github.io/notebook')
});
}

// 如果是 React 元素但不是 img,递归处理其子元素
if (React.isValidElement(node) && node.props.children) {
return React.cloneElement(node, {
children: React.Children.map(node.props.children, replaceImageDomain)
});
}

// 如果是其他类型的节点,直接返回
return node;
};
const modifiedChildren = process.env.NODE_ENV === 'production' ? React.Children.map(children, replaceImageDomain): children;
return (
<div className='slider'>
<AwesomeSlider>
{modifiedChildren}
</AwesomeSlider>
</div>
);
}

0 comments on commit b9d0088

Please sign in to comment.