Skip to content

Commit f009734

Browse files
committed
fix potential issues related to sitemap generation
1 parent 6a20335 commit f009734

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

reflex/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def add_page(
693693
image: str = constants.DefaultPage.IMAGE,
694694
on_load: EventType[()] | None = None,
695695
meta: list[dict[str, str]] = constants.DefaultPage.META_LIST,
696-
sitemap_priority: float = None,
696+
sitemap_priority: float = constants.DefaultPage.SITEMAP_PRIORITY,
697697
sitemap_changefreq: str = constants.DefaultPage.SITEMAP_CHANGEFREQ,
698698
):
699699
"""Add a page to the app.

reflex/constants/route.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class DefaultPage(SimpleNamespace):
6363
META_LIST = []
6464
# The default changefrequency for sitemap generation.
6565
SITEMAP_CHANGEFREQ = "weekly"
66+
# The default priority for sitemap generation.
67+
SITEMAP_PRIORITY = 10.0
6668

6769

6870
# 404 variables

reflex/sitemap.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,19 @@ def generate_links_for_sitemap(app_instance) -> List[dict[str, str]]:
8989
if not route.startswith("/"):
9090
route = f"/{route}"
9191

92-
# extract sitemap properties from the app's property
92+
sitemap_changefreq = constants.DefaultPage.SITEMAP_CHANGEFREQ # default value
93+
sitemap_priority = constants.DefaultPage.SITEMAP_PRIORITY # default value
94+
95+
# extract sitemap properties from the app's property, route exist in the compiled pages.
9396
if route in app_instance.site_map_properties:
9497
sitemap_priority = app_instance.site_map_properties[route]["priority"]
9598
sitemap_changefreq = app_instance.site_map_properties[route]["changefreq"]
9699

97-
else:
98-
# calculate priority as it is none
100+
if (
101+
sitemap_priority == constants.DefaultPage.SITEMAP_PRIORITY
102+
): # indicates that user didn't set priority
99103
depth = route.count("/")
100104
sitemap_priority = max(0.5, 1.0 - (depth * 0.1))
101-
sitemap_changefreq = "weekly"
102105

103106
deploy_url = get_config().deploy_url # pick domain url from the config file.
104107

tests/units/test_app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def test_add_duplicate_page_route_error(app, first_page, second_page, route):
353353

354354

355355
def test_add_page_with_sitemap_properties(app):
356+
"""Test if the sitemap properties of the app instance is set properly or not."""
356357
# check with given values.
357358
app.add_page(
358359
page1, route="/page1", sitemap_priority=0.9, sitemap_changefreq="daily"
@@ -361,7 +362,8 @@ def test_add_page_with_sitemap_properties(app):
361362

362363
# check default values added.
363364
app.add_page(page2, route="/page2")
364-
assert app.sitemap_properties["page2"] == {"priority": None, "changefreq": "weekly"}
365+
print(app.sitemap_properties)
366+
assert app.sitemap_properties["page2"] == {"priority": 10.0, "changefreq": "weekly"}
365367

366368

367369
def test_initialize_with_admin_dashboard(test_model):

0 commit comments

Comments
 (0)