@@ -21,7 +21,6 @@ export const formatNotionImageUrl = (
21
21
if ( ! url || typeof url !== 'string' || ! url . startsWith ( 'https://' ) ) {
22
22
return url ?? '' ;
23
23
}
24
-
25
24
try {
26
25
// 이미 notion.so 형식인 경우 그대로 반환
27
26
if ( url . includes ( 'notion.so/image/' ) ) {
@@ -45,7 +44,8 @@ export const formatNotionImageUrl = (
45
44
46
45
// 블록 ID가 있는 경우 추가
47
46
if ( blockId ) {
48
- params . push ( `table=block&id=${ blockId } ` ) ;
47
+ const formattedBlockId = formatNotionId ( blockId ) ;
48
+ params . push ( `table=block&id=${ formattedBlockId } ` ) ;
49
49
}
50
50
51
51
// 추가 파라미터가 있는 경우 URL에 추가
@@ -64,6 +64,29 @@ export const formatNotionImageUrl = (
64
64
}
65
65
} ;
66
66
67
+ /**
68
+ * Notion ID 문자열에 하이픈을 추가하는 함수
69
+ *
70
+ * 예시 입력: 1239c6bf2b178076a838d17ca1c89783
71
+ * 예시 출력: 1239c6bf-2b17-8076-a838-d17ca1c89783
72
+ *
73
+ * @param id - 하이픈 없는 Notion ID 문자열
74
+ * @returns 하이픈이 추가된 UUID 형식의 문자열
75
+ */
76
+ const formatNotionId = ( id : string ) : string => {
77
+ if ( ! id || typeof id !== 'string' || id . length !== 32 ) {
78
+ return id ; // 유효하지 않은 ID인 경우 원래 ID 반환
79
+ }
80
+
81
+ try {
82
+ // 8-4-4-4-12 형식으로 하이픈 추가 (UUID 형식)
83
+ return `${ id . slice ( 0 , 8 ) } -${ id . slice ( 8 , 12 ) } -${ id . slice ( 12 , 16 ) } -${ id . slice ( 16 , 20 ) } -${ id . slice ( 20 ) } ` ;
84
+ } catch ( error ) {
85
+ console . error ( 'Notion ID 포맷팅 중 오류 발생:' , error ) ;
86
+ return id ; // 오류 발생 시 원래 ID 반환
87
+ }
88
+ } ;
89
+
67
90
/**
68
91
* 노션 블록에서 이미지 URL을 추출하고 포맷팅하는 함수
69
92
* ! 현재 미사용 (25.4.7)
0 commit comments