Skip to content

Commit d8c26c0

Browse files
Fix 'Edit this page' button GitHub links
- Add convert_url_path_to_github_path() utility function to convert URL paths to filesystem paths - Convert dashes to underscores (getting-started -> getting_started) - Change tree/main/ to blob/main/ for direct file links - Ensure .md extension is properly added Fixes incorrect GitHub links that were generating 404s due to path mismatch between URL format (dashes) and filesystem format (underscores). Co-Authored-By: [email protected] <[email protected]>
1 parent b7168d3 commit d8c26c0

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

pcweb/templates/docpage/docpage.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,22 @@ def link_pill(text: str, href: str) -> rx.Component:
274274
)
275275

276276

277+
def convert_url_path_to_github_path(url_path: str) -> str:
278+
"""Convert a URL path to the corresponding GitHub filesystem path.
279+
280+
Args:
281+
url_path: URL path like "/docs/getting-started/introduction/"
282+
283+
Returns:
284+
GitHub filesystem path like "docs/getting_started/introduction.md"
285+
"""
286+
path = url_path.strip("/")
287+
path = path.replace("-", "_")
288+
if not path.endswith(".md"):
289+
path += ".md"
290+
return path
291+
292+
277293
@rx.memo
278294
def docpage_footer(path: str):
279295
from pcweb.constants import FORUM_URL, ROADMAP_URL
@@ -303,7 +319,7 @@ def docpage_footer(path: str):
303319
),
304320
link_pill(
305321
"Edit this page",
306-
f"https://github.com/reflex-dev/reflex-web/tree/main{path}.md",
322+
f"https://github.com/reflex-dev/reflex-web/blob/main/{convert_url_path_to_github_path(path)}",
307323
),
308324
class_name="desktop-only flex-row items-center gap-2 w-auto",
309325
),

0 commit comments

Comments
 (0)