@@ -47,33 +47,21 @@ def __init__(self, img_meta_data: Dict[str, Union[int, str]]):
47
47
self .url : str = img_meta_data ['url' ]
48
48
self .name : str = self ._get_image_name ()
49
49
self ._markdown_str = ""
50
- self .image_relative_path : str = f"./{ _IMAGE_DIR_NAME } /{ self .name } "
50
+ self ._image_relative_path : str = f"./{ _IMAGE_DIR_NAME } /{ self .name } "
51
51
52
52
def _get_image_name (self ) -> str :
53
53
return self .url .split ('/' )[- 1 ]
54
-
55
- # def _get_markdown_str(self, img_details: Dict[str, Union[int, str]]) -> str:
56
- # if 'content' in img_details:
57
- # if _MARKDOWN_STR_CHECK in img_details['content']:
58
- # print(img_details['content'][_MARKDOWN_STR_CHECK])
59
- # return self._get_md_url_str(img_details['content'][_MARKDOWN_STR_CHECK])
60
- # return ""
54
+
55
+ @property
56
+ def image_relative_path (self ):
57
+ return self ._image_relative_path
61
58
62
59
@property
63
60
def markdown_str (self ):
64
61
return self ._markdown_str
65
62
66
63
def set_markdown_content (self , img_details : Dict [str , Union [int , str ]]):
67
64
self ._markdown_str = self ._get_md_url_str (img_details )
68
- # @markdown_str.setter
69
- # def markdown_str(self, img_details: Dict[str, Union[int, str]]) -> str:
70
- # self._markdown_str = self._get_md_url_str(img_details)
71
-
72
-
73
- def get_replace_str (self ) -> str :
74
- """return str for regex replace in page md content"""
75
- # return f"[]"
76
- return self .image_relative_path
77
65
78
66
@staticmethod
79
67
def _get_md_url_str (img_data : Dict [str , Union [int , str ]]) -> str :
@@ -185,30 +173,17 @@ def gzip_archive(self):
185
173
def _update_image_links (self , page_data : bytes , image_nodes : List [ImageNode ]) -> bytes :
186
174
"""regex replace links to local created directories"""
187
175
for img_node in image_nodes :
188
- img_meta_url = f"{ self .api_urls [" images" ]} /{ img_node .id } "
176
+ img_meta_url = f"{ self .api_urls [' images' ]} /{ img_node .id } "
189
177
img_details = common_util .http_get_request (img_meta_url ,
190
178
self ._headers , self .verify_ssl )
191
179
192
180
img_node .set_markdown_content (img_details .json ())
193
181
if not img_node .markdown_str :
194
182
continue
195
-
196
- # re_pattern_bytes = self._get_regex_expr(img_node.markdown_str)
197
-
198
- # re_pattern_bytes = self._get_regex_expr(img_node.url)
199
-
200
183
# 1 - what to replace, 2 - replace with, 3 is the data to replace
201
- # re.sub(b'pfsense', b'lol', x.content)
202
- print (img_node .markdown_str )
203
- print (img_node .get_replace_str ())
204
- page_data = re .sub (img_node .markdown_str .encode (), img_node .get_replace_str ().encode (), page_data )
205
- # print(page_data)
184
+ page_data = re .sub (img_node .markdown_str .encode (), img_node .image_relative_path ().encode (), page_data )
206
185
return page_data
207
186
208
- # string to bytes
209
- # >>> k = 'lol'
210
- # >>> k.encode()
211
-
212
187
@property
213
188
def file_extension_map (self ) -> Dict [str , str ]:
214
189
"""file extension metadata"""
@@ -225,10 +200,9 @@ def verify_ssl(self) -> bool:
225
200
return self .asset_config .verify_ssl
226
201
227
202
# @staticmethod
228
- # def _get_regex_expr(image_str : str) -> bytes:
203
+ # def _get_regex_expr(url : str) -> bytes:
229
204
# # regex_str = fr"\[\!\[^$|.*\]\({url}\)\]"
230
- # # print(regex_str)
231
- # return re.compile(image_str.encode())
205
+ # return re.compile(regex_str.encode())
232
206
233
207
@staticmethod
234
208
def _create_image_map (json_data : List [Dict [str , Union [str ,int ]]]) -> Dict [int , List [ImageNode ]]:
0 commit comments