forked from PrivateCoffee/wikimore
fix(routing): handle redirects for nested wiki routes
Updated the route to accept nested paths for wiki titles. Added logic to handle redirects within wiki articles, checking for redirection messages and appropriately redirecting if the "redirect" query parameter is not set to "no". This ensures smoother navigation between articles, even when dealing with paths that include slashes, which helps enhance user experience. Fixes #3.
This commit is contained in:
parent
dbb3ab0e98
commit
6f5863b746
1 changed files with 12 additions and 1 deletions
|
@ -109,7 +109,7 @@ def search():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/<project>/<lang>/wiki/<title>")
|
@app.route("/<project>/<lang>/wiki/<path:title>")
|
||||||
def wiki_article(project, lang, title):
|
def wiki_article(project, lang, title):
|
||||||
language_projects = app.languages.get(lang, {}).get("projects", {})
|
language_projects = app.languages.get(lang, {}).get("projects", {})
|
||||||
base_url = language_projects.get(project)
|
base_url = language_projects.get(project)
|
||||||
|
@ -127,6 +127,17 @@ def wiki_article(project, lang, title):
|
||||||
|
|
||||||
soup = BeautifulSoup(article_html, "html.parser")
|
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):
|
for a in soup.find_all("a", href=True):
|
||||||
href = a["href"]
|
href = a["href"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue