Coverage for src / content_generator / schema_builder.py: 100%
11 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-13 20:29 +0800
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-13 20:29 +0800
1# Schema Builder
2from dataclasses import dataclass
3from typing import Any
6@dataclass
7class FAQItem:
8 question: str
9 answer: str
12class 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 }
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 }
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 }