Skip to content

Commit 33a11e4

Browse files
Fix StringVar handling in convert_url_path_to_github_path function
- Add detection for Reflex StringVar objects using hasattr check - Use rx.vars.sequence.string_replace_operation for StringVar manipulation - Maintain backwards compatibility with regular Python strings - Fixes TypeError: StringVar.strip() takes 1 positional argument but 2 were given Co-Authored-By: [email protected] <[email protected]>
1 parent d8c26c0 commit 33a11e4

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

pcweb/templates/docpage/docpage.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,27 @@ def link_pill(text: str, href: str) -> rx.Component:
274274
)
275275

276276

277-
def convert_url_path_to_github_path(url_path: str) -> str:
277+
def convert_url_path_to_github_path(url_path) -> str:
278278
"""Convert a URL path to the corresponding GitHub filesystem path.
279279
280280
Args:
281-
url_path: URL path like "/docs/getting-started/introduction/"
281+
url_path: URL path like "/docs/getting-started/introduction/" (can be str or rx.Var[str])
282282
283283
Returns:
284284
GitHub filesystem path like "docs/getting_started/introduction.md"
285285
"""
286-
path = url_path.strip("/")
287-
path = path.replace("-", "_")
288-
if not path.endswith(".md"):
289-
path += ".md"
290-
return path
286+
if hasattr(url_path, '_js_expr'): # This is a Reflex Var
287+
from reflex.vars.sequence import string_replace_operation
288+
289+
path_no_slashes = string_replace_operation(url_path, r"^/+|/+$", "")
290+
path_with_underscores = string_replace_operation(path_no_slashes, "-", "_")
291+
return f"{path_with_underscores}.md"
292+
else:
293+
path = url_path.strip("/")
294+
path = path.replace("-", "_")
295+
if not path.endswith(".md"):
296+
path += ".md"
297+
return path
291298

292299

293300
@rx.memo

0 commit comments

Comments
 (0)