Coverage for fastblocks/adapters/sitemap/asgi.py: 0%
32 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-09 00:47 -0700
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-09 00:47 -0700
1"""FastBlocks ASGI Sitemap Adapter (Legacy).
3This adapter now uses FastBlocks native sitemap implementation
4instead of the external asgi-sitemaps dependency.
6For new projects, consider using the native adapter directly.
7"""
9import typing as t
10from contextlib import suppress
11from uuid import UUID
13from acb.adapters import AdapterStatus
14from acb.depends import depends
16from ._base import SitemapBase, SitemapBaseSettings
17from .core import BaseSitemap as NativeSitemap
18from .core import SitemapApp
21class SitemapSettings(SitemapBaseSettings):
22 pass
25class AsgiSitemap(NativeSitemap[str], SitemapBase): # type: ignore[override,name-defined]
26 sitemap: SitemapApp | None = None
28 def items(self) -> t.Any:
29 try:
30 routes_adapter = depends.get("routes")
31 if hasattr(routes_adapter, "routes"):
32 return [r.path for r in routes_adapter.routes]
33 return []
34 except Exception:
35 return []
37 def location(self, item: str) -> str:
38 return item
40 def changefreq(self, item: str) -> str:
41 return t.cast(str, self.config.change_freq)
43 async def init(self) -> None:
44 if not self.config.app.domain:
45 msg = "`domain` must be set in AppSettings"
46 raise ValueError(msg)
47 self.sitemap = SitemapApp(
48 self,
49 domain=self.config.app.domain,
50 cache_ttl=getattr(self.config, "cache_ttl", 3600),
51 )
54MODULE_ID = UUID("01937d86-eff0-7410-5786-a01234567890")
55MODULE_STATUS = AdapterStatus.STABLE
57with suppress(Exception):
58 depends.set(AsgiSitemap)