add img a change

This commit is contained in:
Valentin CZERYBA 2023-06-13 00:46:18 +02:00
parent 7228911e68
commit da4db0277a

View File

@ -74,6 +74,7 @@ class WPChange:
## Change path img file ## Change path img file
def _change(self, file): def _change(self, file):
ext_img = ["png", "svg", "gif", "jpg", "jpeg"]
try: try:
with open(file, 'r') as f: with open(file, 'r') as f:
content = f.read() content = f.read()
@ -101,6 +102,17 @@ class WPChange:
if len(o.netloc) > 0: if len(o.netloc) > 0:
self._logger.info("{0} : Change source css {1} /dists/css/{2}/{3}".format(self._name, href, o.netloc, o.path)) self._logger.info("{0} : Change source css {1} /dists/css/{2}/{3}".format(self._name, href, o.netloc, o.path))
content = content.replace(href, "/dists/css/{0}/{1}".format(o.netloc, o.path)) content = content.replace(href, "/dists/css/{0}/{1}".format(o.netloc, o.path))
a = soup.find_all("a", {"target": "_blank"})
for i in a:
href = i.get("href")
if href is not None:
o = urlparse(href)
if len(o.netloc) > 0:
ext = o.path.split(".")[len(o.path.split("."))-1]
if ext in ext_img:
self._logger.info("{0} : Change a img {1} /img/{2}/{3}".format(self._name, href, o.netloc, o.path))
content = content.replace(href, "/img/{0}/{1}".format(o.netloc, o.path))
try: try:
with open(file, "w") as f: with open(file, "w") as f:
self._logger.info("{0} : File write : {1}".format(self._name, file)) self._logger.info("{0} : File write : {1}".format(self._name, file))