Module: JekyllAeo::Schema::HowTo

Defined in:
lib/jekyll-aeo/schema/how_to.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
# File 'lib/jekyll-aeo/schema/how_to.rb', line 6

def self.build(page, _site_config, _aeo_config = {})
  howto = page["howto"]
  return nil unless howto.is_a?(Hash)

  steps = howto["steps"]
  return nil unless steps.is_a?(Array) && steps.any?

  step_entities = steps.each_with_index.filter_map { |step, i| build_step(step, i) }
  return nil if step_entities.empty?

  schema = { "@context" => "https://schema.org", "@type" => "HowTo", "step" => step_entities }
  add_optional_fields(schema, howto, page)
  schema
end