Skip to content

Commit 032802d

Browse files
Fix 'Edit this page' link to preserve original file paths for GitHub URLs
- Add get_github_path() function to preserve underscores in file paths - Update docpage_footer() to use original file path for GitHub links - Maintain existing get_path() transformation for web URLs - Fixes issue where underscore-to-hyphen transformation caused 404s on GitHub Co-Authored-By: [email protected] <[email protected]>
1 parent 8ad9cd8 commit 032802d

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

pcweb/route.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,20 @@ def get_path(component_fn: Callable):
5353
module.__name__.replace(".", "/").replace("_", "-").split("pcweb/pages")[1]
5454
+ "/"
5555
)
56+
57+
58+
def get_github_path(component_fn: Callable):
59+
"""Get the original file path for GitHub links based on the file location.
60+
61+
This preserves underscores in filenames, unlike get_path() which converts them to hyphens for URLs.
62+
63+
Args:
64+
component_fn: The component function for the page.
65+
"""
66+
module = inspect.getmodule(component_fn)
67+
68+
# Create a path based on the module name, preserving underscores for GitHub links.
69+
return (
70+
module.__name__.replace(".", "/").split("pcweb/pages")[1]
71+
+ "/"
72+
)

pcweb/templates/docpage/docpage.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from pcweb.components.button import button
1313
from pcweb.components.icons.icons import get_icon
14-
from pcweb.route import Route, get_path
14+
from pcweb.route import Route, get_path, get_github_path
1515
from pcweb.styles.colors import c_color
1616

1717
from .blocks import *
@@ -275,7 +275,7 @@ def link_pill(text: str, href: str) -> rx.Component:
275275

276276

277277
@rx.memo
278-
def docpage_footer(path: str):
278+
def docpage_footer(path: str, github_path: str):
279279
from pcweb.constants import FORUM_URL, ROADMAP_URL
280280
from pcweb.pages.blog import blogs
281281
from pcweb.pages.docs import ai_builder, getting_started, hosting
@@ -303,7 +303,7 @@ def docpage_footer(path: str):
303303
),
304304
link_pill(
305305
"Edit this page",
306-
f"https://github.com/reflex-dev/reflex-web/tree/main{path}.md",
306+
f"https://github.com/reflex-dev/reflex-web/tree/main/docs{github_path}.md",
307307
),
308308
class_name="lg:flex hidden flex-row items-center gap-2 w-auto",
309309
),
@@ -524,6 +524,7 @@ def docpage(contents: Callable[[], Route]) -> Route:
524524
"""
525525

526526
path = get_path(contents) if set_path is None else set_path
527+
github_path = get_github_path(contents) if set_path is None else set_path
527528

528529
title = contents.__name__.replace("_", " ").title() if t is None else t
529530

@@ -648,7 +649,7 @@ def wrapper(*args, **kwargs) -> rx.Component:
648649
*links,
649650
class_name="flex flex-row gap-2 mt-8 lg:mt-10 mb-6 lg:mb-12",
650651
),
651-
docpage_footer(path=path.rstrip("/")),
652+
docpage_footer(path=path.rstrip("/"), github_path=github_path.rstrip("/")),
652653
class_name="lg:mt-0 mt-6 px-4 xl:px-20 h-screen bg-slate-1",
653654
),
654655
class_name="w-full bg-slate-1 h-full mx-auto max-w-2xl "

0 commit comments

Comments
 (0)