Coverage for fastblocks / adapters / sitemap / static.py: 56%

48 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-02 20:00 -0800

1"""FastBlocks Static Sitemap Adapter. 

2 

3Pre-configured URL list sitemap generation for simple sites 

4with known, static URL structures. 

5""" 

6 

7import typing as t 

8from contextlib import suppress 

9from uuid import UUID 

10 

11 

12# Custom implementations for ACB compatibility 

13class AdapterStatus: 

14 """Custom AdapterStatus for Oneiric compatibility.""" 

15 

16 STABLE = "STABLE" 

17 BETA = "BETA" 

18 ALPHA = "ALPHA" 

19 EXPERIMENTAL = "EXPERIMENTAL" 

20 

21 

22def debug(msg: str) -> None: 

23 """Custom debug function for Oneiric compatibility.""" 

24 print(f"[DEBUG] {msg}") 

25 

26 

27from oneiric.core.resolution import Resolver 

28 

29# Oneiric resolver for dependency injection 

30depends = Resolver() 

31 

32 

33def import_adapter(adapter_name: str) -> None: 

34 """Custom implementation for Oneiric compatibility.""" 

35 return None 

36 

37 

38from ._base import SitemapBase, SitemapBaseSettings 

39from .core import BaseSitemap, SitemapApp 

40 

41 

42class StaticSitemapSettings(SitemapBaseSettings): 

43 pass 

44 

45 

46class StaticSitemap(BaseSitemap[str], SitemapBase): 

47 sitemap: SitemapApp | None = None 

48 

49 def items(self) -> list[str]: 

50 strategy_options = self.config.strategy_options 

51 static_urls = t.cast(list[str], strategy_options.get("static_urls", [])) 

52 debug(f"StaticSitemap: Using {len(static_urls)} static URLs") 

53 return static_urls 

54 

55 def location(self, item: str) -> str: 

56 return item 

57 

58 def changefreq(self, item: str) -> str: 

59 return t.cast(str, self.config.change_freq) 

60 

61 def priority(self, item: str) -> float: 

62 if item == "/": 

63 return 1.0 

64 segments = len([s for s in item.split("/") if s]) 

65 if segments == 1: 

66 return 0.8 

67 if segments == 2: 

68 return 0.6 

69 return 0.4 

70 

71 async def init(self) -> None: 

72 if not self.config.domain: 

73 msg = "domain must be set in sitemap settings" 

74 raise ValueError(msg) 

75 self.sitemap = SitemapApp( 

76 self, 

77 domain=self.config.domain, 

78 cache_ttl=self.config.cache_ttl, 

79 ) 

80 debug(f"StaticSitemap: Initialized with domain={self.config.domain}") 

81 

82 

83Sitemap = StaticSitemap 

84 

85MODULE_ID = UUID("01937d86-af80-7192-e453-789012345601") 

86MODULE_STATUS = AdapterStatus.STABLE 

87 

88with suppress(Exception): 

89 depends.set(Sitemap)