Skip to content

Commit cd3895f

Browse files
Merge pull request #57 from ShipFriend0516/feature/image-description
[Feature] 이미지 대체텍스트 렌더링 기능 추가
2 parents 482cd6e + 09d4360 commit cd3895f

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

app/entities/common/Overlay/Image/ImageZoomOverlayContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const ImageZoomOverlayContainer = ({
1414
if (!selectedImage) return null;
1515

1616
return (
17-
<div className={'zoomBox p-4 bg-white'}>
17+
<div className={'w-full zoomBox p-4 bg-white rounded-md shadow-lg'}>
1818
<button
1919
onClick={() => {
2020
setSelectedImage(null);
@@ -29,7 +29,7 @@ const ImageZoomOverlayContainer = ({
2929
alt={'확대된 이미지'}
3030
width={800}
3131
height={600}
32-
className={'rounded-none !important max-w-full max-h-[80vh]'}
32+
className={'rounded-none !important w-full h-auto mx-auto'}
3333
/>
3434
</div>
3535
);

app/entities/common/Overlay/Overlay.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ interface OverlayProps {
44
overlayOpen: boolean;
55
setOverlayOpen: (open: boolean) => void;
66
children: ReactNode;
7+
maxWidth?: 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | '7xl' | number;
78
}
89
const Overlay = ({
910
overlayOpen = false,
1011
setOverlayOpen,
1112
children,
13+
maxWidth = '2xl',
1214
}: OverlayProps) => {
1315
const overlayRef = useRef<HTMLDivElement>(null);
1416
useEffect(() => {
@@ -24,13 +26,17 @@ const Overlay = ({
2426
};
2527
}, []);
2628

29+
const isMaxWidthTypeNumber = typeof maxWidth === 'number';
30+
2731
return (
2832
overlayOpen && (
2933
<div
3034
ref={overlayRef}
3135
className="fixed flex justify-center items-center w-screen h-screen top-0 left-0 inset-0 bg-black bg-opacity-50 z-50"
3236
>
33-
<div className="animate-popUp container bg-opacity-90 text-overlay rounded-lg mx-auto max-w-2xl">
37+
<div
38+
className={`animate-popUp container bg-opacity-90 text-overlay rounded-lg mx-auto ${isMaxWidthTypeNumber ? `max-w-[${maxWidth}px]` : `max-w-${maxWidth}`}`}
39+
>
3440
{children}
3541
</div>
3642
</div>

app/entities/post/detail/PostBody.tsx

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,42 @@ const PostBody = ({ content, tags, loading }: Props) => {
4242
}
4343
};
4444

45+
const addDescriptionUnderImage = (
46+
node: any,
47+
index?: number,
48+
parent?: Element
49+
) => {
50+
if (node.type === 'element' && node.tagName === 'img') {
51+
const altText = node.properties.alt;
52+
if (altText) {
53+
const descriptionNode = {
54+
type: 'element',
55+
tagName: 'span',
56+
properties: {
57+
className: 'image-description',
58+
},
59+
children: [
60+
{
61+
type: 'text',
62+
value: altText,
63+
},
64+
],
65+
};
66+
67+
if (
68+
index !== undefined &&
69+
parent &&
70+
parent.children &&
71+
Array.isArray(parent.children)
72+
) {
73+
parent.children.splice(index + 1, 0, descriptionNode);
74+
}
75+
}
76+
}
77+
78+
return null;
79+
};
80+
4581
const renderOpenGraph = (node: any, index?: number, parent?: Element) => {
4682
if (node.type === 'element' && node.tagName === 'p' && node.children) {
4783
const aTag = node.children.find(
@@ -226,7 +262,11 @@ const PostBody = ({ content, tags, loading }: Props) => {
226262
</div>
227263
) : (
228264
<>
229-
<Overlay overlayOpen={openImageBox} setOverlayOpen={setOpenImageBox}>
265+
<Overlay
266+
overlayOpen={openImageBox}
267+
setOverlayOpen={setOpenImageBox}
268+
maxWidth={'5xl'}
269+
>
230270
<ImageZoomOverlayContainer
231271
selectedImage={selectedImage}
232272
setSelectedImage={setSelectedImage}
@@ -253,6 +293,11 @@ const PostBody = ({ content, tags, loading }: Props) => {
253293
parent as Element | undefined
254294
);
255295
addImageClickHandler(node);
296+
addDescriptionUnderImage(
297+
node,
298+
index,
299+
parent as Element | undefined
300+
);
256301
}}
257302
/>
258303
</>

app/globals.css

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,21 @@ article.post .post-body p:has(img) {
8282
}
8383

8484
article.post .post-body img {
85-
max-width: 100%;
85+
max-width: 90%;
8686
height: auto;
8787
margin: 1em 0;
8888
border-radius: 1em;
8989
box-shadow: 0 0 4px rgba(0, 0, 0, 0.05);
9090
}
9191

92+
article.post .post-body div > div img {
93+
max-width: 50%;
94+
}
95+
96+
article.post .post-body div > div.zoomBox img {
97+
max-width: 100%;
98+
}
99+
92100
article.post .post-body .zoomBox img {
93101
border-radius: 0;
94102
}
@@ -175,6 +183,15 @@ article.post .post-body pre {
175183
box-shadow: 0 0 4px rgba(0, 0, 0, 0.05);
176184
}
177185

186+
article.post .image-description {
187+
text-align: center;
188+
font-size: 0.75em;
189+
color: var(--text-weak);
190+
margin-top: -0.5em;
191+
margin-bottom: 1em;
192+
display: block;
193+
}
194+
178195
.shadow-top {
179196
box-shadow:
180197
0 -4px 6px -1px rgba(0, 0, 0, 0.1),

0 commit comments

Comments
 (0)