1
1
'use client' ;
2
2
3
3
import { useRouter } from "next/navigation" ;
4
- import Image from "next/image" ;
5
- import { getValidImageSrc } from "@/utils/checkImageProperty" ;
6
4
7
5
interface ContentProps {
8
6
text ?: string ;
@@ -23,16 +21,40 @@ const ArticleDetailContent = ({ text, title, paywallUp, createdAt, authorName, i
23
21
24
22
const parseHtmlContent = ( htmlContent : string ) : string => {
25
23
if ( ! htmlContent ) return "" ;
26
-
24
+
27
25
try {
28
26
const parser = new DOMParser ( ) ;
29
27
const doc = parser . parseFromString ( htmlContent , "text/html" ) ;
30
- return doc . body . innerHTML ;
28
+
29
+ doc . querySelectorAll ( "[class*='max-w-[']" ) . forEach ( ( el ) => {
30
+ const classList = el . getAttribute ( "class" ) || "" ;
31
+ const match = classList . match ( / m a x - w - \[ ( \d + ) p x \] / ) ;
32
+
33
+ if ( match ) {
34
+ const maxWidth = match [ 1 ] ;
35
+ ( el as HTMLElement ) . style . maxWidth = `${ maxWidth } px` ;
36
+ el . setAttribute ( "class" , classList . replace ( match [ 0 ] , "" ) . trim ( ) ) ;
37
+ }
38
+ } ) ;
39
+
40
+ doc . querySelectorAll ( "[class*='left-[']" ) . forEach ( ( el ) => {
41
+ const classList = el . getAttribute ( "class" ) || "" ;
42
+ const match = classList . match ( / l e f t - \[ ( \d + ) p x \] / ) ;
43
+
44
+ if ( match ) {
45
+ const leftValue = parseInt ( match [ 1 ] , 10 ) + 15 ;
46
+ ( el as HTMLElement ) . style . left = `${ leftValue } px` ;
47
+ el . setAttribute ( "class" , classList . replace ( match [ 0 ] , "" ) . trim ( ) ) ;
48
+ }
49
+ } ) ;
50
+
51
+ return doc . body . innerHTML ;
31
52
} catch ( error ) {
32
53
console . error ( "HTML 파싱 중 오류 발생:" , error ) ;
33
- return htmlContent ;
54
+ return htmlContent ;
34
55
}
35
56
} ;
57
+
36
58
37
59
const parsedPaywallContent = paywallUp ? parseHtmlContent ( paywallUp ) : null ;
38
60
const parsedTextContent = text ? parseHtmlContent ( text ) : null ;
@@ -43,11 +65,6 @@ const ArticleDetailContent = ({ text, title, paywallUp, createdAt, authorName, i
43
65
{ new Date ( createdAt ) . toLocaleDateString ( ) } < br />
44
66
BY. { authorName }
45
67
</ p >
46
- { /* <Image
47
- src={getValidImageSrc(imgLink)}
48
- alt={title}
49
- className="w-full max-w-[650px] aspect-square my-16 object-cover mx-auto rounded-lg"
50
- /> */ }
51
68
{ isPremium ? (
52
69
< >
53
70
< article
0 commit comments