Coverage for src/content_generator/schema_builder.py: 100%

1# Schema Builder

2 from dataclasses import dataclass

3 from typing import Any

4

5

6@dataclass

7 class FAQItem:

8 question: str

9 answer: str

10

11

12 class SchemaBuilder:

13 def build_faq_schema(self, items: list[FAQItem]) -> dict[str, Any]:

14 return {

15 "@context": "https://schema.org",

16 "@type": "FAQPage",

17 "mainEntity": [

18 {

19 "@type": "Question",

20 "name": item.question,

21 "acceptedAnswer": {"@type": "Answer", "text": item.answer},

22 }

23 for item in items

24 ],

25 }

26

27 def build_howto_schema(self, title: str, steps: list[str]) -> dict[str, Any]:

28 return {

29 "@context": "https://schema.org",

30 "@type": "HowTo",

31 "name": title,

32 "step": [

33 {"@type": "HowToStep", "text": step, "position": i + 1}

34 for i, step in enumerate(steps)

35 ],

36 }

37

38 def build_article_schema(

39 self, title: str, description: str, author: str, date: str

40 ) -> dict[str, Any]:

41 return {

42 "@context": "https://schema.org",

43 "@type": "Article",

44 "headline": title,

45 "description": description,

46 "author": {"@type": "Person", "name": author},

47 "datePublished": date,

48 }