Skip to content

Commit

Permalink
✨ Page can get sitemap options (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjquant authored Mar 14, 2024
1 parent 2f80eca commit 3d4ae37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion sitemapr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ def _iter_page(self, page: Page) -> Iterator[SiteMapUrl]:
if query_string
else f"{self._base_url}{path}"
)
yield SiteMapUrl(loc=loc)
yield SiteMapUrl(
loc=loc,
lastmod=page.lastmod,
changefreq=page.changefreq,
priority=page.priority,
)

def _get_param_combinations(
self, params: list[Param] | None
Expand Down
3 changes: 3 additions & 0 deletions sitemapr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Page(BaseModel):
path: str
query_params: list[Param] = []
path_params: list[Param] = []
lastmod: str | None = None
changefreq: ChangeFreq | None = None
priority: float | None = None


class SiteMapUrl(BaseModel):
Expand Down
7 changes: 4 additions & 3 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_iter_url_works():
Page(
path="/blog/{id}",
path_params=[Param(name="id", values=["1", "2", "3"])],
changefreq="daily",
),
Page(
path="/blog/{id}/comments",
Expand Down Expand Up @@ -117,19 +118,19 @@ def test_iter_url_works():
SiteMapUrl(
loc="https://example.com/blog/1",
lastmod=None,
changefreq=None,
changefreq="daily",
priority=None,
),
SiteMapUrl(
loc="https://example.com/blog/2",
lastmod=None,
changefreq=None,
changefreq="daily",
priority=None,
),
SiteMapUrl(
loc="https://example.com/blog/3",
lastmod=None,
changefreq=None,
changefreq="daily",
priority=None,
),
SiteMapUrl(
Expand Down

0 comments on commit 3d4ae37

Please sign in to comment.