Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions docs/app/reflex_docs/templates/docpage/docpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,24 @@ def handle_submit(self, form_data: dict):
pass


def footer_link(text: str, href: str):
return rx.link(
text,
class_name="font-small text-secondary-9 hover:!text-secondary-11 transition-color",
href=href,
underline="none",
def footer_link(text: str, href: str, *, root_site: bool = False) -> rx.Component:
"""Create a footer link, optionally bypassing the docs router basename.

Args:
text: The visible link label.
href: The link destination.
root_site: Whether the destination is outside the docs router basename.

Returns:
The styled footer link.
"""
class_name = (
"font-small text-secondary-9 hover:!text-secondary-11 "
"transition-color no-underline"
)
if root_site:
return rx.el.elements.a(text, href=href, class_name=class_name)
return rx.link(text, href=href, class_name=class_name, underline="none")


def footer_link_flex(heading: str, links):
Expand Down Expand Up @@ -360,7 +371,7 @@ def docpage_footer(path: rx.Var[str]) -> rx.Component:
"Links",
Comment thread
carlosabadia marked this conversation as resolved.
[
footer_link("Home", "/"),
footer_link("Blog", "/blog"),
footer_link("Blog", "/blog/", root_site=True),
footer_link("Changelog", "/changelog/"),
],
),
Expand All @@ -376,7 +387,7 @@ def docpage_footer(path: rx.Var[str]) -> rx.Component:
footer_link_flex(
"Resources",
[
footer_link("FAQ", "/faq/"),
footer_link("FAQ", "/faq/", root_site=True),
footer_link("Roadmap", ROADMAP_URL),
footer_link("Forum", FORUM_URL),
],
Expand Down
25 changes: 25 additions & 0 deletions docs/app/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections import Counter

import pytest
import reflex as rx


@pytest.fixture
Expand Down Expand Up @@ -62,3 +63,27 @@ def test_docs_route_descriptions_fit_search_snippet_length(routes_fixture):
}

assert overlong == {}


@pytest.mark.parametrize(
("label", "href"),
[("Blog", "/blog/"), ("FAQ", "/faq/")],
)
def test_docpage_footer_uses_root_site_anchors(label: str, href: str):
"""Root-site footer links should not inherit the /docs router basename."""
from reflex_docs.templates.docpage.docpage import docpage_footer

rendered = docpage_footer.__wrapped__(rx.Var.create("/test")).render()

def find_link(node: dict) -> dict | None:
if any(child.get("contents") == f'"{label}"' for child in node["children"]):
return node
for child in node["children"]:
if "children" in child and (link := find_link(child)) is not None:
return link
return None

link = find_link(rendered)
assert link is not None
assert link["name"] == '"a"'
assert f'href:"{href}"' in link["props"]
Loading