Module: JekyllAeo::Schema::FaqPage

Defined in:
lib/jekyll-aeo/schema/faq_page.rb

Class Method Summary collapse

Class Method Details

.build(page, _site_config, _aeo_config = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jekyll-aeo/schema/faq_page.rb', line 6

def self.build(page, _site_config, _aeo_config = {})
  faq = page["faq"]
  return nil unless faq.is_a?(Array) && faq.any?

  entities = faq.filter_map do |item|
    next unless item.is_a?(Hash) && item["q"] && item["a"]

    {
      "@type" => "Question",
      "name" => item["q"],
      "acceptedAnswer" => {
        "@type" => "Answer",
        "text" => item["a"]
      }
    }
  end

  return nil if entities.empty?

  {
    "@context" => "https://schema.org",
    "@type" => "FAQPage",
    "mainEntity" => entities
  }
end