fix add menu with album

This commit is contained in:
Valentin CZERYBA 2023-08-24 22:43:15 +02:00
parent d9c20cedcb
commit 1fc9c48d2c

View File

@ -85,11 +85,15 @@ class WPMenu:
def _getIdfromTitlePost(self, content): def _getIdfromTitlePost(self, content):
idMenu = {"id":0, "type":"", "link":""} idMenu = {"id":0, "type":"", "link":""}
soup = BeautifulSoup(content, self._parser) soup = BeautifulSoup(content, self._parser)
articletitle = soup.find("h2", class_="articletitle").get_text() articletitle = soup.find_all("h2", class_="articletitle")
if len(articletitle) > 0:
articletitle = articletitle[0].get_text()
search = "posts" search = "posts"
post_type = "post"
if len(articletitle) == 0: if len(articletitle) == 0:
articletitle = soup.find("div", class_="albumbody").find("h2").get_text() articletitle = soup.find("div", class_="albumbody").find("h2").get_text()
search = "pages" search = "pages"
post_type = "page"
exist = False exist = False
for index in range(1,10): for index in range(1,10):
@ -109,7 +113,7 @@ class WPMenu:
self._logger.debug("{0} : comparaison debug {1} {2}".format(self._name, articletitle, title_rendered)) self._logger.debug("{0} : comparaison debug {1} {2}".format(self._name, articletitle, title_rendered))
if articletitle == title_rendered: if articletitle == title_rendered:
self._logger.debug("{0} : get {2} id : {1}".format(self._name, i, search)) self._logger.debug("{0} : get {2} id : {1}".format(self._name, i, search))
idMenu = {"id":i["id"], "type":"post", "link": i["link"]} idMenu = {"id":i["id"], "type":post_type, "link": i["link"]}
exist = True exist = True
else: else:
self._logger.debug("{0} : {2} {1}".format(self._name, result, len(result))) self._logger.debug("{0} : {2} {1}".format(self._name, result, len(result)))
@ -159,13 +163,18 @@ class WPMenu:
idMenu = {"id":0, "type":"", "link":""} idMenu = {"id":0, "type":"", "link":""}
if href != "#": if href != "#":
title = href[::-1] title = href[::-1]
second_title = title.split("/")[2]
second_title = second_title[::-1]
link = title.split("/")[0] link = title.split("/")[0]
link = link[::-1] link = link[::-1]
title = title.split("/")[1] title = title.split("/")[1]
title = title[::-1] title = title[::-1]
self._logger.info("{0} link {1} title {2}".format(self._name, link, title)) self._logger.info("{0} link {1} title {2}".format(self._name, link, title))
if link == "index.html": if link == "index.html":
idMenu = self._getId(title) if second_title == "archives" or second_title == "albums":
idMenu = self._getIdFromPost(href)
else:
idMenu = self._getId(title)
else: else:
idMenu = self._getIdFromPost(href) idMenu = self._getIdFromPost(href)