22import logging
33import typing as t
44from copy import deepcopy
5- from pathlib import Path
5+ from pathlibfs import Path
66
77from bs4 import BeautifulSoup
88
9+ from hubspot_tech_writing .util .common import url_to_path
10+
911logger = logging .getLogger (__name__ )
1012
1113
@@ -32,7 +34,7 @@ def __init__(self, html: str, source_path: t.Union[str, Path], uploader: t.Optio
3234
3335 def __str__ (self ):
3436 return (
35- f"HTMLImageTranslator:\n in: { self .images_in } \n local: { self .images_local } \n remote: { self .images_remote } "
37+ f"HTMLImageTranslator:\n source path: { self . source_path } \ n in: { self .images_in } \n local: { self .images_local } \n remote: { self .images_remote } "
3638 )
3739
3840 def discover (self ):
@@ -60,8 +62,9 @@ def resolve(self) -> "HTMLImageTranslator":
6062 Process discovered image elements, computing effective paths.
6163 """
6264 if self .source_path is None :
65+ logger .warning ("No resolving without source path" )
6366 return self
64- parent_path = Path ( self .source_path )
67+ parent_path = self .source_path
6568 if parent_path .is_file ():
6669 parent_path = parent_path .parent
6770 self .images_local = []
@@ -74,7 +77,7 @@ def resolve(self) -> "HTMLImageTranslator":
7477
7578 # Relative paths are relative to the original document.
7679 else :
77- image_new .src = str ( Path ( parent_path ) / image .src )
80+ image_new .src = parent_path / image .src
7881 self .images_local .append (image_new )
7982 return self
8083
@@ -86,7 +89,7 @@ def upload(self) -> "HTMLImageTranslator":
8689 logger .warning ("No upload without uploader" )
8790 return self
8891 for image_local in self .images_local :
89- hs_file = self .uploader (source = image_local .src , name = Path ( image_local .src ) .name )
92+ hs_file = self .uploader (source = image_local .src , name = image_local .src .name )
9093 image_url = hs_file .url
9194 image_remote : HTMLImage = deepcopy (image_local )
9295 image_remote .src = image_url
0 commit comments