Coverage for fastblocks/adapters/sitemap/asgi.py: 0%
32 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-21 04:50 -0700
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-21 04:50 -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"""
9from contextlib import suppress
10from uuid import UUID
12from acb.adapters import AdapterStatus
13from acb.depends import depends
15from ._base import SitemapBase, SitemapBaseSettings
16from .core import BaseSitemap as NativeSitemap
17from .core import SitemapApp
20class SitemapSettings(SitemapBaseSettings):
21 pass
24class Sitemap(NativeSitemap[str], SitemapBase):
25 sitemap: SitemapApp | None = None
27 @depends.inject
28 def items(self) -> list[str]:
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 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(Sitemap)