From 3d4ae374dc8fcec337bbfd9189f89c61dea897a1 Mon Sep 17 00:00:00 2001 From: Seonu Jang Date: Fri, 15 Mar 2024 00:46:35 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Page=20can=20get=20sitemap=20option?= =?UTF-8?q?s=20(#9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sitemapr/core.py | 7 ++++++- sitemapr/models.py | 3 +++ tests/test_core.py | 7 ++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sitemapr/core.py b/sitemapr/core.py index 63a42a5..8c40a80 100644 --- a/sitemapr/core.py +++ b/sitemapr/core.py @@ -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 diff --git a/sitemapr/models.py b/sitemapr/models.py index 30882d8..9c6f011 100644 --- a/sitemapr/models.py +++ b/sitemapr/models.py @@ -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): diff --git a/tests/test_core.py b/tests/test_core.py index 99097ea..6f95e44 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -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", @@ -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(