From 82de4ac15e6a942c3b004efad24a3dc8a4ab7edf Mon Sep 17 00:00:00 2001
From: eug-vs <eugene@eug-vs.xyz>
Date: Fri, 30 Sep 2022 20:47:08 +0300
Subject: feat: add custom Image component

---
 src/Image.tsx | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 src/Image.tsx

(limited to 'src/Image.tsx')

diff --git a/src/Image.tsx b/src/Image.tsx
new file mode 100644
index 0000000..770c383
--- /dev/null
+++ b/src/Image.tsx
@@ -0,0 +1,21 @@
+import ImageBase from 'next/future/image';
+import { FC } from 'react';
+
+type Props = Record<'src' | 'alt', string>;
+
+const IMAGE_CDN = 'http://localhost:8000';
+
+const localizeSrc = (src: string) => {
+  if (process.env.NODE_ENV === 'production' || src.startsWith('http')) return src;
+  return IMAGE_CDN + src;
+}
+
+const Image: FC<Props> = ({ src, ...props }) => {
+  const source = localizeSrc(src);
+
+  return (
+    <ImageBase src={source} {...props} />
+  )
+}
+
+export default Image;
-- 
cgit v1.2.3

