feat: add redirect handling for /index.php route

Added a new route to handle redirects from /<project>/<lang>/w/index.php. The redirect fetches the main page from the Wiki API and redirects to it. This improves user navigation by dynamically redirecting to the main page of the relevant project and language.
This commit is contained in:
Kumi 2024-08-19 17:06:48 +02:00
parent a4272eaf8e
commit 4dfbd002f6
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -293,6 +293,20 @@ logger.debug(
)
@app.route("/<project>/<lang>/w/index.php")
def index_php_redirect(project, lang):
# TODO: Handle query string
url = f"{app.languages[lang]['projects'][project]}/w/api.php?action=query&format=json&meta=siteinfo&siprop=general"
with urllib.request.urlopen(url) as response:
data = json.loads(response.read().decode())
main_page = data["query"]["general"]["mainpage"]
return redirect(
url_for("wiki_article", project=project, lang=lang, title=main_page)
)
def main():
port = int(os.environ.get("PORT", 8109))
host = os.environ.get("HOST", "0.0.0.0")