diff --git a/src/wikimore/app.py b/src/wikimore/app.py index 960d4aa..c02a292 100644 --- a/src/wikimore/app.py +++ b/src/wikimore/app.py @@ -109,7 +109,7 @@ def search(): ) -@app.route("///wiki/") +@app.route("/<project>/<lang>/wiki/<path:title>") def wiki_article(project, lang, title): language_projects = app.languages.get(lang, {}).get("projects", {}) base_url = language_projects.get(project) @@ -127,6 +127,17 @@ def wiki_article(project, lang, title): soup = BeautifulSoup(article_html, "html.parser") + redirect_message = soup.find("div", class_="redirectMsg") + + if redirect_message and not (request.args.get("redirect") == "no"): + redirect_dest = redirect_message.find("a")["title"] + logger.debug(f"Redirecting to {redirect_dest}") + destination = url_for( + "wiki_article", project=project, lang=lang, title=redirect_dest + ) + logger.debug(f"Redirect URL: {destination}") + return redirect(destination) + for a in soup.find_all("a", href=True): href = a["href"]