From da4db0277a917d23c4d4a98cc0d5edd4cf73de58 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 13 Jun 2023 00:46:18 +0200 Subject: [PATCH] add img a change --- lib/WPChange.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/WPChange.py b/lib/WPChange.py index b12c0c4..8d2b626 100644 --- a/lib/WPChange.py +++ b/lib/WPChange.py @@ -74,6 +74,7 @@ class WPChange: ## Change path img file def _change(self, file): + ext_img = ["png", "svg", "gif", "jpg", "jpeg"] try: with open(file, 'r') as f: content = f.read() @@ -101,6 +102,17 @@ class WPChange: 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)) 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: with open(file, "w") as f: self._logger.info("{0} : File write : {1}".format(self._name, file))