Skip to content

Commit

Permalink
Fix double navigation, and other edge-cases for charm docs - WD-6672 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukewh authored Oct 9, 2023
1 parent e702d22 commit 05c3c73
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions webapp/store/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,16 @@ def get_package(entity_name, channel_request=None, fields=FIELDS):


@store.route('/<regex("' + DETAILS_VIEW_REGEX + '"):entity_name>')
@store.route('/<regex("' + DETAILS_VIEW_REGEX + '"):entity_name>/docs')
@store_maintenance
@redirect_uppercase_to_lowercase
def details_overview(entity_name):
channel_request = request.args.get("channel", default=None, type=str)
if request.base_url.endswith("/docs"):
url = f"/{entity_name}"
if channel_request:
url = f"{url}?channel={channel_request}"
return redirect(url)

extra_fields = [
"result.bugs-url",
Expand Down Expand Up @@ -212,9 +218,7 @@ def details_overview(entity_name):
navigation["nav_items"][0]["children"][1]["navlink_text"]
== "Overview"
):
navigation["nav_items"][0]["children"][1][
"navlink_text"
] = "Docs - Overview"
del navigation["nav_items"][0]["children"][1]
else:
# If there is no navigation but we've got here, there are docs
# So add a top level "Docs item". Example: /easyrsa
Expand All @@ -223,16 +227,6 @@ def details_overview(entity_name):
"level": 0,
"children": [
overview,
{
"level": 1,
"path": "",
"navlink_href": f"/{entity_name}/docs",
"navlink_fragment": "",
"navlink_text": "Docs",
"is_active": True,
"has_active_child": False,
"children": [],
},
],
}
]
Expand All @@ -249,7 +243,6 @@ def details_overview(entity_name):
return render_template("details/overview.html", **context)


@store.route('/<regex("' + DETAILS_VIEW_REGEX + '"):entity_name>/docs')
@store.route(
'/<regex("' + DETAILS_VIEW_REGEX + '"):entity_name>/docs/<path:path>'
)
Expand Down Expand Up @@ -281,6 +274,7 @@ def details_docs(entity_name, path=None):
docs.parse()

if path:
topic_id = None
try:
topic_id = docs.resolve_path(path)[0]
except PathNotFoundError:
Expand All @@ -305,16 +299,16 @@ def details_docs(entity_name, path=None):
"has_active_child": False,
"children": [],
}

if len(navigation["nav_items"]) > 0:
navigation["nav_items"][0]["children"].insert(0, overview)
# If the first item in docs nav is "overview", prefix with "Docs - "
# If the first item in docs nav is "overview",
# prefix with "Docs - "
if (
navigation["nav_items"][0]["children"][1]["navlink_text"]
== "Overview"
):
navigation["nav_items"][0]["children"][1][
"navlink_text"
] = "Docs - Overview"
del navigation["nav_items"][0]["children"][1]
else:
# If there is no navigation but we've got here, there are docs
# So add a top level "Docs item". Example: /easyrsa
Expand All @@ -323,16 +317,6 @@ def details_docs(entity_name, path=None):
"level": 0,
"children": [
overview,
{
"level": 1,
"path": "",
"navlink_href": f"/{entity_name}/docs",
"navlink_fragment": "",
"navlink_text": "Docs",
"is_active": True,
"has_active_child": False,
"children": [],
},
],
}
]
Expand Down

0 comments on commit 05c3c73

Please sign in to comment.