From 7228911e6859b7cf96b11dc81d3e8df3843c3995 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 13 Jun 2023 00:38:34 +0200 Subject: [PATCH] add js and css --- lib/WPChange.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/WPChange.py b/lib/WPChange.py index c08b5f0..b12c0c4 100644 --- a/lib/WPChange.py +++ b/lib/WPChange.py @@ -83,8 +83,24 @@ class WPChange: src = i.get("src") o = urlparse(src) if len(o.netloc) > 0: - self._logger.info("{0} : Change source {1} /dists/img/{2}/{3}".format(self._name, src, o.netloc, o.path)) - content = content.replace(src, "/dists/img/{0}/{1}".format(o.netloc, o.path)) + self._logger.info("{0} : Change source image {1} /img/{2}/{3}".format(self._name, src, o.netloc, o.path)) + content = content.replace(src, "/img/{0}/{1}".format(o.netloc, o.path)) + script = soup.find_all("script", {"type": "text/javascript"}) + for i in script: + src = i.get("src") + if src is not None: + o = urlparse(src) + if len(o.netloc) > 0: + self._logger.info("{0} : Change source js {1} /dists/js/{2}/{3}".format(self._name, src, o.netloc, o.path)) + content = content.replace(src, "/dists/js/{0}/{1}".format(o.netloc, o.path)) + link = soup.find_all("link", {"rel": "stylesheet"}) + for i in link: + href = i.get("href") + if href is not None: + o = urlparse(href) + 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)) try: with open(file, "w") as f: self._logger.info("{0} : File write : {1}".format(self._name, file))