define content for navigation

This commit is contained in:
Valentin CZERYBA 2023-07-20 00:04:11 +02:00
parent c6894648d1
commit 1f8ea70b40

View File

@ -171,6 +171,9 @@ class WPMenu:
exist = False
if exist is False:
for i in ["categories", "tags"]:
typeId = "category"
if i == "tags":
typeId = "tag"
for index in range(1,10):
try:
params = {"search":title, "per_page":"100", "page":index}
@ -183,7 +186,8 @@ class WPMenu:
self._logger.info("{0} info : {1} {2} {3}".format(self._name, j["name"], j["slug"], title))
if j["name"] == title or j["slug"] == title:
self._logger.info("{0} : comparaison ok : {1} {2}".format(self._name, j["id"], i))
idMenu = {"id": j["id"], "type": i, "link": j["link"]}
idMenu = {"id": j["id"], "type": typeId, "link": j["link"]}
exist = True
else:
break
@ -254,8 +258,18 @@ class WPMenu:
if idMenu["id"] != 0:
menu[i] = {"id":idMenu["id"], "type": idMenu["type"], "title":menu[i]["title"], "link":idMenu["link"], "children": menu[i]["children"]}
navigation = ''
for i in menu:
self._logger.info("{0} Menu parent {1} with id {2} and type {3} and link {4}".format(self._name, i["title"], i["id"], i["type"], i["link"]))
if len(i["children"]) > 0:
navigation = navigation + "<!-- wp:navigation-submenu {\"label\":\"label-string\" ,\"type\":\"kind-string\",\"id\":id-string,\"url\":\"url-string\",\"kind\":\"kind-string-type\"} --> \n\n".replace("label-string", i["title"]).replace("id-string", str(i["id"])).replace("url-string", i["link"]).replace("kind-string", i["type"])
else:
navigation = navigation + "<!-- wp:navigation-link {\"label\":\"label-string\",\"type\":\"kind-string\",\"id\":id-string,\"url\":\"url-string\",\"kind\":\"kind-string-type\"} /--> \n".replace("label-string", i["title"]).replace("id-string", str(i["id"])).replace("url-string", i["link"]).replace("kind-string", i["type"])
for j in i["children"]:
navigation = navigation + "<!-- wp:navigation-link {\"label\":\"label-string\",\"type\":\"kind-string\",\"id\":id-string,\"url\":\"url-string\",\"kind\":\"kind-string-type\"} /--> \n".replace("label-string", j["title"]).replace("id-string", str(j["id"])).replace("url-string", j["link"]).replace("kind-string", j["type"])
self._logger.info("{0} Menu children {1} with id {2} and type {3} and link {4}".format(self._name, j["title"], j["id"], j["type"], j["link"]))
if len(i["children"]) > 0:
navigation = navigation + "<!-- /wp:navigation-submenu --> \n"
self._logger.info("{0} : {1}".format(self._name, navigation))