Skip to content

Commit f775e24

Browse files
Fix double slash issues in library page URL generation (#1485)
- Fix URL construction in library.py to handle empty prefix correctly - Fix get_component_link function to avoid double slashes when prefix is empty - Fix category overview links to handle empty prefix properly - Fix library preview page URL generation This resolves 404 errors on library component links caused by URLs like /docs/library//data-display Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Alek <[email protected]>
1 parent d7551a0 commit f775e24

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

pcweb/components/docpage/sidebar/sidebar_items/component_lib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def get_component_link(category, clist, prefix="") -> str:
77
component_name = rx.utils.format.to_kebab_case(clist[0])
88
# construct the component link. The component name points to the name of the md file.
9-
return f"/docs/library/{prefix.strip('/')}/{category.lower().replace(' ', '-')}/{component_name.lower()}"
9+
return f"/docs/library/{prefix.strip('/') + '/' if prefix.strip('/') else ''}{category.lower().replace(' ', '-')}/{component_name.lower()}"
1010

1111

1212
def get_category_children(category, category_list, prefix=""):
@@ -22,7 +22,7 @@ def get_category_children(category, category_list, prefix=""):
2222
category_item_children.append(
2323
SideBarItem(
2424
names="Overview",
25-
link=f"/docs/library/{prefix}{category.lower().replace(' ', '-')}/",
25+
link=f"/docs/library/{prefix if prefix else ''}{category.lower().replace(' ', '-')}/",
2626
)
2727
)
2828
for c in category_list:

pcweb/pages/docs/library.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def generate_gallery(
2222
class_name="font-large text-slate-12",
2323
),
2424
get_icon("new_tab", class_name="text-slate-11 [&>svg]:size-4"),
25-
href=f"/docs/library/{prefix.strip('/')}/{category.lower()}",
25+
href=f"/docs/library/{prefix.strip('/') + '/' if prefix.strip('/') else ''}{category.lower()}",
2626
underline="none",
2727
class_name="px-4 py-2 bg-slate-1 hover:bg-slate-3 transition-bg flex flex-row justify-between items-center !text-slate-12",
2828
),

pcweb/pages/library_previews.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def page() -> rx.Component:
7272
component_card(
7373
name=component[0],
7474
link=get_component_link(
75-
component_category, component, prefix.strip("/") + "/"
75+
component_category, component, prefix.strip("/") + "/" if prefix.strip("/") else ""
7676
),
7777
section=component_category,
7878
)

0 commit comments

Comments
 (0)